diff --git a/backend/internal/api/modlists.go b/backend/internal/api/modlists.go index 9444ae1..99981a7 100644 --- a/backend/internal/api/modlists.go +++ b/backend/internal/api/modlists.go @@ -1,7 +1,9 @@ package api import ( + "fmt" "net/http" + "strings" "arma3-web-server/internal/models" "arma3-web-server/internal/services" @@ -121,6 +123,25 @@ func (h *Handler) ImportModlist(c *gin.Context) { c.JSON(http.StatusCreated, ml) } +func (h *Handler) ExportModlist(c *gin.Context) { + ml, err := h.modlists.Get(c.Param("id")) + if err != nil { + c.JSON(http.StatusNotFound, gin.H{"error": err.Error()}) + return + } + + html, err := services.RenderModlistHTML(ml.Name, ml.Mods) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + + filename := fmt.Sprintf("%s.html", strings.ReplaceAll(ml.Name, `"`, `_`)) + c.Header("Content-Type", "text/html; charset=utf-8") + c.Header("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, filename)) + c.String(http.StatusOK, html) +} + type modStatus struct { ID string `json:"id"` Name string `json:"name"` diff --git a/backend/internal/api/router.go b/backend/internal/api/router.go index 7d2c686..aeac260 100644 --- a/backend/internal/api/router.go +++ b/backend/internal/api/router.go @@ -80,6 +80,7 @@ func (h *Handler) SetupRoutes(r *gin.Engine) { api.GET("/modlists/:id/check", h.CheckModlistMods) api.POST("/modlists/:id/download-missing", h.DownloadMissingMods) api.POST("/modlists/:id/update-all", h.UpdateAllMods) + api.GET("/modlists/:id/export", h.ExportModlist) api.GET("/mods", h.ListMods) api.DELETE("/mods", h.DeleteMod) diff --git a/backend/internal/services/modlist_parser.go b/backend/internal/services/modlist_parser.go index 139f0ec..8e327ac 100644 --- a/backend/internal/services/modlist_parser.go +++ b/backend/internal/services/modlist_parser.go @@ -1,7 +1,9 @@ package services import ( + "bytes" "fmt" + "html/template" "io" "net/url" "path" @@ -11,6 +13,42 @@ import ( "golang.org/x/net/html" ) +const modlistHTMLTmpl = ` + +
+ + ++ To import this preset, drag this file onto the Launcher window. Or click the MODS tab, then PRESET in the top right, then IMPORT at the bottom, and finally select this file. +
+| {{.Name}} | +Steam | +https://steamcommunity.com/sharedfiles/filedetails/?id={{.ID}} | +