package server import ( "github.com/labstack/echo/v5" "log" "music-server/internal/backend" "net/http" ) type DownloadHandler struct { } func NewDownloadHandler() *DownloadHandler { return &DownloadHandler{} } // CheckLatest godoc // @Summary Check for latest version // @Description Checks for the latest version of the application // @Tags download // @Accept json // @Produce json // @Success 200 {string} string // @Router /download [get] func (d *DownloadHandler) checkLatest(ctx *echo.Context) error { log.Println("Checking latest version") latest := backend.CheckLatest() return ctx.JSON(http.StatusOK, latest) } // ListAssetsOfLatest godoc // @Summary List assets of latest version // @Description Lists all assets available for the latest version // @Tags download // @Accept json // @Produce json // @Success 200 {array} string // @Router /download/list [get] func (d *DownloadHandler) listAssetsOfLatest(ctx *echo.Context) error { log.Println("Listing assets") assets := backend.ListAssetsOfLatest() return ctx.JSON(http.StatusOK, assets) } // DownloadLatestWindows godoc // @Summary Download latest Windows version // @Description Redirects to download the latest Windows version // @Tags download // @Produce octet-stream // @Success 302 {string} string // @Router /download/windows [get] func (d *DownloadHandler) downloadLatestWindows(ctx *echo.Context) error { log.Println("Downloading latest windows") asset := backend.DownloadLatestWindows() ctx.Response().Header().Set("Content-Type", "application/octet-stream") return ctx.Redirect(http.StatusFound, asset) } // DownloadLatestLinux godoc // @Summary Download latest Linux version // @Description Redirects to download the latest Linux version // @Tags download // @Produce octet-stream // @Success 302 {string} string // @Router /download/linux [get] func (d *DownloadHandler) downloadLatestLinux(ctx *echo.Context) error { log.Println("Downloading latest linux") asset := backend.DownloadLatestLinux() ctx.Response().Header().Set("Content-Type", "application/octet-stream") return ctx.Redirect(http.StatusFound, asset) }