From 6b884ce24b91e9144ea852853c9470a06c56dc6d Mon Sep 17 00:00:00 2001 From: julien Date: Thu, 19 Jun 2025 16:50:30 +0200 Subject: [PATCH] up --- internal/download/download.go | 44 ++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/internal/download/download.go b/internal/download/download.go index 54666aa..73cf4dc 100644 --- a/internal/download/download.go +++ b/internal/download/download.go @@ -15,6 +15,27 @@ import ( "github.com/gorilla/mux" "gorm.io/gorm" ) +func renderPathHTML(path models.PathDownload) string { + return fmt.Sprintf(` +
+
+
+ + + + + + +
+
+
`, + path.ID, path.ID, path.PathName, + path.ID, path.ID, path.ID, + path.ID, path.ID, + path.ID, path.ID, path.ID, + path.ID, path.ID) +} + func GetFirstActiveAccount(client *debridlink.Client) *debridlink.DebridAccount { ctx := context.Background() // ✅ on remplace ici @@ -35,10 +56,9 @@ func GetFirstActiveAccount(client *debridlink.Client) *debridlink.DebridAccount func CreateSavePath(db *gorm.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json") + w.Header().Set("Content-Type", "text/html") var pathDownload models.PathDownload - if err := json.NewDecoder(r.Body).Decode(&pathDownload); err != nil { http.Error(w, `{"error": "Invalid JSON format"}`, http.StatusBadRequest) return @@ -49,7 +69,6 @@ func CreateSavePath(db *gorm.DB) http.HandlerFunc { return } - // Création du dossier physique fullPath := "/app/upload/" + pathDownload.PathName if _, err := os.Stat(fullPath); os.IsNotExist(err) { if err := os.MkdirAll(fullPath, 0755); err != nil { @@ -58,16 +77,14 @@ func CreateSavePath(db *gorm.DB) http.HandlerFunc { } } - // Enregistrement en base pathDownload.Path = fullPath - if err := db.Create(&pathDownload).Error; err != nil { http.Error(w, `{"error": "Failed to save path"}`, http.StatusInternalServerError) return } - // Recharge la liste - ReadAllSavePath(db)(w, r) + // 👉 On renvoie uniquement la ligne HTML nouvellement créée + fmt.Fprint(w, renderPathHTML(pathDownload)) } } @@ -110,7 +127,7 @@ func ReadAllSavePath(db *gorm.DB) http.HandlerFunc { func UpdateSavePath(db *gorm.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json") + w.Header().Set("Content-Type", "text/html") id := mux.Vars(r)["id"] var pathDownload models.PathDownload @@ -121,15 +138,10 @@ func UpdateSavePath(db *gorm.DB) http.HandlerFunc { var existingPath models.PathDownload if err := db.First(&existingPath, "id = ?", id).Error; err != nil { - if err == gorm.ErrRecordNotFound { - http.Error(w, `{"error": "Path not found"}`, http.StatusNotFound) - return - } - http.Error(w, `{"error": "Failed to retrieve path"}`, http.StatusInternalServerError) + http.Error(w, `{"error": "Path not found"}`, http.StatusNotFound) return } - // Renommage physique du dossier oldFullPath := "/app/upload/" + existingPath.PathName newFullPath := "/app/upload/" + pathDownload.PathName if oldFullPath != newFullPath { @@ -141,13 +153,13 @@ func UpdateSavePath(db *gorm.DB) http.HandlerFunc { existingPath.PathName = pathDownload.PathName existingPath.Path = newFullPath - if err := db.Save(&existingPath).Error; err != nil { http.Error(w, `{"error": "Failed to update path"}`, http.StatusInternalServerError) return } - ReadAllSavePath(db)(w, r) + // 👉 On renvoie uniquement la ligne HTML mise à jour + fmt.Fprint(w, renderPathHTML(existingPath)) } }