new release management

This commit is contained in:
2026-01-27 20:01:25 +01:00
parent 27960741a3
commit ea78a83d78
11 changed files with 176 additions and 371 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ func (c *DownloadController) serve(w http.ResponseWriter, r *http.Request, relea
return
}
absContentsDir, err := filepath.Abs(os.Getenv("GAMES_DIR"))
absContentsDir, err := filepath.Abs(os.Getenv("FILE_CONTAINER_PATH"))
if err != nil {
http.Error(w, "Invalid contents directory path", http.StatusInternalServerError)
return
+7 -99
View File
@@ -4,7 +4,6 @@ import (
"fmt"
"net/http"
"os"
"path/filepath"
"teletype_softwares/domain"
"teletype_softwares/lib/template_utils"
@@ -13,59 +12,19 @@ import (
type PlayController struct {
softwareService domain.SoftwareServiceInterface
fileService domain.FileServiceInterface
}
func NewPlayController(softwareService domain.SoftwareServiceInterface) *PlayController {
func NewPlayController(softwareService domain.SoftwareServiceInterface, fileService domain.FileServiceInterface) *PlayController {
return &PlayController{
softwareService: softwareService,
fileService: fileService,
}
}
func (c *PlayController) PlayV1(w http.ResponseWriter, r *http.Request) {
name := chi.URLParam(r, "name")
if name == "" {
http.Error(w, "Name not provided", http.StatusBadRequest)
return
}
software, err := c.softwareService.GetByNameWithReleases(name)
if err != nil {
if err == domain.ErrSoftwareNotFound {
http.Error(w, "Software not found", http.StatusNotFound)
return
}
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
var webPlayableRelease *domain.Release
for _, release := range software.Releases {
if release.WebPlayable {
webPlayableRelease = &release
break
}
}
if webPlayableRelease == nil {
http.Error(w, "No web-playable version found for this software", http.StatusNotFound)
return
}
http.Redirect(w, r, fmt.Sprintf("/play/%s/%s", name, webPlayableRelease.Version), http.StatusFound)
}
func (c *PlayController) Play(w http.ResponseWriter, r *http.Request) {
name := chi.URLParam(r, "name")
if name == "" {
http.Error(w, "Name not provided", http.StatusBadRequest)
return
}
version := chi.URLParam(r, "version")
if version == "" {
http.Error(w, "Version not provided", http.StatusBadRequest)
return
}
software, err := c.softwareService.GetByNameWithReleases(name)
if err != nil {
@@ -79,7 +38,7 @@ func (c *PlayController) Play(w http.ResponseWriter, r *http.Request) {
var webPlayableRelease *domain.Release
for _, release := range software.Releases {
if release.Version == version && release.WebPlayable {
if release.Version == version && release.HTMLFolderPath != "" {
webPlayableRelease = &release
break
}
@@ -102,64 +61,13 @@ func (c *PlayController) Play(w http.ResponseWriter, r *http.Request) {
})
}
func (c *PlayController) ServeContentV1(w http.ResponseWriter, r *http.Request) {
contentsPath := os.Getenv("GAMES_DIR")
name := chi.URLParam(r, "name")
if name == "" {
http.Error(w, "Name not provided", http.StatusBadRequest)
return
}
software, err := c.softwareService.GetByNameWithReleases(name)
if err != nil {
http.Error(w, fmt.Sprintf("Content for '%s' not found.", name), http.StatusNotFound)
return
}
var webPlayableRelease *domain.Release
for _, release := range software.Releases {
if release.WebPlayable {
webPlayableRelease = &release
break
}
}
if webPlayableRelease == nil {
http.Error(w, "No web-playable version found for this software", http.StatusNotFound)
return
}
htmlBaseDir := filepath.Join(contentsPath, "html", name, webPlayableRelease.Version)
if _, err := os.Stat(htmlBaseDir); os.IsNotExist(err) {
http.Error(w, fmt.Sprintf("Content for '%s' not found.", name), http.StatusNotFound)
return
} else if err != nil {
http.Error(w, fmt.Sprintf("Error accessing content for '%s': %v", name, err), http.StatusInternalServerError)
return
}
fs := http.StripPrefix(fmt.Sprintf("/play/%s/content", name), http.FileServer(http.Dir(htmlBaseDir)))
fs.ServeHTTP(w, r)
}
func (c *PlayController) ServeContent(w http.ResponseWriter, r *http.Request) {
contentsPath := os.Getenv("GAMES_DIR")
name := chi.URLParam(r, "name")
if name == "" {
http.Error(w, "Name not provided", http.StatusBadRequest)
return
}
version := chi.URLParam(r, "version")
if version == "" {
http.Error(w, "Version not provided", http.StatusBadRequest)
return
}
htmlBaseDir := filepath.Join(contentsPath, name, version, "html")
html_base_dir := c.fileService.GetPath(name + "-" + version)
if _, err := os.Stat(htmlBaseDir); os.IsNotExist(err) {
if _, err := os.Stat(html_base_dir); os.IsNotExist(err) {
http.Error(w, fmt.Sprintf("Content for '%s' not found.", name), http.StatusNotFound)
return
} else if err != nil {
@@ -167,6 +75,6 @@ func (c *PlayController) ServeContent(w http.ResponseWriter, r *http.Request) {
return
}
fs := http.StripPrefix(fmt.Sprintf("/play/%s/%s/content", name, version), http.FileServer(http.Dir(htmlBaseDir)))
fs := http.StripPrefix(fmt.Sprintf("/play/%s/%s/content", name, version), http.FileServer(http.Dir(html_base_dir)))
fs.ServeHTTP(w, r)
}
+1 -1
View File
@@ -10,7 +10,7 @@ func StartHttpServer(domainInstance domain.Domain) {
NewSoftwareController(domainInstance.SoftwareService),
NewSoftwareUpdaterController(domainInstance.SoftwareUpdaterService),
NewDownloadController(domainInstance.DownloadService),
NewPlayController(domainInstance.SoftwareService),
NewPlayController(domainInstance.SoftwareService, domainInstance.FileService),
NewRootController(),
).Init()
+2 -3
View File
@@ -1,8 +1,9 @@
package http
import (
"github.com/go-chi/chi/v5"
"net/http"
"github.com/go-chi/chi/v5"
)
type Router struct {
@@ -40,8 +41,6 @@ func (r *Router) Init() *chi.Mux {
router.Get("/download/{name}/cartridge", r.downloadController.GetLatestCartridge)
router.Get("/download/{name}/{version}/source", r.downloadController.GetSource)
router.Get("/download/{name}/{version}/cartridge", r.downloadController.GetCartridge)
router.Get("/play/{name}", r.playController.PlayV1)
router.Get("/play/{name}/content*", r.playController.ServeContentV1)
router.Get("/play/{name}/{version}", r.playController.Play)
router.Get("/play/{name}/{version}/content*", r.playController.ServeContent)