add local filesystem storage for packages and assets with upload handlers

This commit is contained in:
2026-01-18 21:16:42 +01:00
parent 01a0ac68a4
commit 149736108e
7 changed files with 481 additions and 12 deletions

View File

@@ -12,6 +12,7 @@ import (
"github.com/omixlab/mosis-portal/internal/auth"
"github.com/omixlab/mosis-portal/internal/config"
"github.com/omixlab/mosis-portal/internal/database"
"github.com/omixlab/mosis-portal/internal/storage"
"github.com/omixlab/mosis-portal/internal/web"
)
@@ -25,6 +26,12 @@ func NewRouter(cfg *config.Config, db *database.DB) http.Handler {
r.Use(chimw.RealIP)
r.Use(chimw.RequestID)
// Initialize storage
store, err := storage.New(cfg.StoragePath)
if err != nil {
log.Fatalf("Failed to initialize storage: %v", err)
}
// Initialize auth components
jwtManager := auth.NewJWTManager(cfg.JWTSecret)
oauthManager := auth.NewOAuthManager(
@@ -34,8 +41,8 @@ func NewRouter(cfg *config.Config, db *database.DB) http.Handler {
)
authMiddleware := middleware.NewAuthMiddleware(jwtManager, db)
authHandler := handlers.NewAuthHandler(oauthManager, jwtManager, db)
appHandler := handlers.NewAppHandler(db)
storeHandler := handlers.NewStoreHandler(db)
appHandler := handlers.NewAppHandler(db, store)
storeHandler := handlers.NewStoreHandler(db, store)
// Health check
r.Get("/health", func(w http.ResponseWriter, r *http.Request) {
@@ -73,6 +80,9 @@ func NewRouter(cfg *config.Config, db *database.DB) http.Handler {
r.Patch("/{appID}", appHandler.Update)
r.Delete("/{appID}", appHandler.Delete)
// Icon upload
r.Post("/{appID}/icon", appHandler.UploadIcon)
// Versions
r.Route("/{appID}/versions", func(r chi.Router) {
r.Get("/", appHandler.ListVersions)
@@ -80,6 +90,9 @@ func NewRouter(cfg *config.Config, db *database.DB) http.Handler {
r.Get("/{versionID}", appHandler.GetVersion)
r.Post("/{versionID}/submit", appHandler.SubmitVersion)
r.Post("/{versionID}/publish", appHandler.PublishVersion)
// Package upload
r.Post("/{versionID}/upload", appHandler.UploadPackage)
})
})
@@ -170,5 +183,14 @@ func NewRouter(cfg *config.Config, db *database.DB) http.Handler {
})
}
// Static file servers for packages and assets
// Downloads - serve package files with proper headers
r.Handle("/downloads/*", http.StripPrefix("/downloads/",
http.FileServer(http.Dir(store.PackagesPath()))))
// Assets - serve icons and screenshots
r.Handle("/assets/*", http.StripPrefix("/assets/",
http.FileServer(http.Dir(store.AssetsPath()))))
return r
}