feat: add modlist export to Arma 3 Launcher HTML format
- RenderModlistHTML: generates compatible preset HTML from a modlist - GET /api/modlists/:id/export: returns downloadable .html file - Export button on ModlistEditor page - Skips local mods (no workshop ID), includes only Steam workshop mods
This commit is contained in:
@@ -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"`
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user