add local filesystem storage for packages and assets with upload handlers
This commit is contained in:
@@ -1,21 +1,24 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/omixlab/mosis-portal/internal/database"
|
||||
"github.com/omixlab/mosis-portal/internal/storage"
|
||||
)
|
||||
|
||||
// StoreHandler handles public store endpoints
|
||||
type StoreHandler struct {
|
||||
db *database.DB
|
||||
db *database.DB
|
||||
storage *storage.Storage
|
||||
}
|
||||
|
||||
// NewStoreHandler creates a new store handler
|
||||
func NewStoreHandler(db *database.DB) *StoreHandler {
|
||||
return &StoreHandler{db: db}
|
||||
func NewStoreHandler(db *database.DB, store *storage.Storage) *StoreHandler {
|
||||
return &StoreHandler{db: db, storage: store}
|
||||
}
|
||||
|
||||
// ListApps returns published apps for the store
|
||||
@@ -69,14 +72,25 @@ func (h *StoreHandler) GetApp(w http.ResponseWriter, r *http.Request) {
|
||||
func (h *StoreHandler) Download(w http.ResponseWriter, r *http.Request) {
|
||||
packageID := chi.URLParam(r, "packageID")
|
||||
|
||||
// Get app to find developer ID
|
||||
app, err := h.db.GetAppByPackageID(r.Context(), packageID)
|
||||
if err != nil {
|
||||
Error(w, "app not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
version, err := h.db.GetLatestPublishedVersion(r.Context(), packageID)
|
||||
if err != nil {
|
||||
Error(w, "no published version found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
// Build download URL
|
||||
downloadURL := fmt.Sprintf("/downloads/%s/%s/%d/package.mosis",
|
||||
app.DeveloperID, app.ID, version.VersionCode)
|
||||
|
||||
JSON(w, http.StatusOK, map[string]interface{}{
|
||||
"download_url": version.PackageURL,
|
||||
"download_url": downloadURL,
|
||||
"version": version.VersionName,
|
||||
"version_code": version.VersionCode,
|
||||
"size": version.PackageSize,
|
||||
@@ -95,14 +109,25 @@ func (h *StoreHandler) DownloadVersion(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Get app to find developer ID
|
||||
app, err := h.db.GetAppByPackageID(r.Context(), packageID)
|
||||
if err != nil {
|
||||
Error(w, "app not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
version, err := h.db.GetPublishedVersionByCode(r.Context(), packageID, versionCode)
|
||||
if err != nil {
|
||||
Error(w, "version not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
// Build download URL
|
||||
downloadURL := fmt.Sprintf("/downloads/%s/%s/%d/package.mosis",
|
||||
app.DeveloperID, app.ID, version.VersionCode)
|
||||
|
||||
JSON(w, http.StatusOK, map[string]interface{}{
|
||||
"download_url": version.PackageURL,
|
||||
"download_url": downloadURL,
|
||||
"version": version.VersionName,
|
||||
"version_code": version.VersionCode,
|
||||
"size": version.PackageSize,
|
||||
|
||||
Reference in New Issue
Block a user