feat(modpack): modpack updates

This commit is contained in:
2025-06-18 18:18:16 +03:00
parent 2c682c5123
commit 96fb472497
4 changed files with 121 additions and 19 deletions

View File

@@ -1,20 +1,24 @@
package api
import (
"context"
"fmt"
"io"
"net/http"
"os"
"gitea.mrixs.me/minecraft-platform/backend/internal/core"
"gitea.mrixs.me/minecraft-platform/backend/internal/core/importer"
"gitea.mrixs.me/minecraft-platform/backend/internal/database"
"gitea.mrixs.me/minecraft-platform/backend/internal/models"
)
type ModpackHandler struct {
ModpackRepo *database.ModpackRepository
ModpackRepo *database.ModpackRepository
JanitorService *core.FileJanitorService
}
// ImportModpack обрабатывает загрузку и импорт модпака.
func (h *ModpackHandler) ImportModpack(w http.ResponseWriter, r *http.Request) {
if err := r.ParseMultipartForm(512 << 20); err != nil { // 512 MB лимит
http.Error(w, "File too large", http.StatusBadRequest)
@@ -65,4 +69,7 @@ func (h *ModpackHandler) ImportModpack(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, "Modpack '%s' imported successfully with %d files.", modpack.DisplayName, len(files))
// Запускаем очистку в фоне, чтобы не блокировать ответ
go h.JanitorService.CleanOrphanedFiles(context.Background())
}