diff --git a/internal/download/download.go b/internal/download/download.go index 73cf4dc..c535022 100644 --- a/internal/download/download.go +++ b/internal/download/download.go @@ -22,10 +22,36 @@ func renderPathHTML(path models.PathDownload) string {
- - - - + + + + + + + +
`, @@ -36,6 +62,7 @@ func renderPathHTML(path models.PathDownload) string { path.ID, path.ID) } + func GetFirstActiveAccount(client *debridlink.Client) *debridlink.DebridAccount { ctx := context.Background() // ✅ on remplace ici @@ -70,11 +97,14 @@ func CreateSavePath(db *gorm.DB) http.HandlerFunc { } fullPath := "/app/upload/" + pathDownload.PathName - if _, err := os.Stat(fullPath); os.IsNotExist(err) { - if err := os.MkdirAll(fullPath, 0755); err != nil { - http.Error(w, `{"error": "Failed to create directory"}`, http.StatusInternalServerError) - return - } + if _, err := os.Stat(fullPath); err == nil { + http.Error(w, `{"error": "Path already exists"}`, http.StatusConflict) + return + } + + if err := os.MkdirAll(fullPath, 0755); err != nil { + http.Error(w, `{"error": "Failed to create directory"}`, http.StatusInternalServerError) + return } pathDownload.Path = fullPath @@ -83,11 +113,11 @@ func CreateSavePath(db *gorm.DB) http.HandlerFunc { return } - // 👉 On renvoie uniquement la ligne HTML nouvellement créée fmt.Fprint(w, renderPathHTML(pathDownload)) } } + func ReadAllSavePath(db *gorm.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") @@ -100,31 +130,14 @@ func ReadAllSavePath(db *gorm.DB) http.HandlerFunc { var response strings.Builder for _, path := range paths { - response.WriteString(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)) + response.WriteString(renderPathHTML(path)) } - w.WriteHeader(http.StatusOK) fmt.Fprint(w, response.String()) } } + func UpdateSavePath(db *gorm.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") @@ -158,28 +171,22 @@ func UpdateSavePath(db *gorm.DB) http.HandlerFunc { return } - // 👉 On renvoie uniquement la ligne HTML mise à jour fmt.Fprint(w, renderPathHTML(existingPath)) } } + func DeleteSavePath(db *gorm.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json") id := mux.Vars(r)["id"] var pathDownload models.PathDownload if err := db.First(&pathDownload, "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 } - // Supprimer physiquement le dossier fullPath := "/app/upload/" + pathDownload.PathName if err := os.RemoveAll(fullPath); err != nil { http.Error(w, `{"error": "Failed to delete directory"}`, http.StatusInternalServerError) @@ -190,8 +197,6 @@ func DeleteSavePath(db *gorm.DB) http.HandlerFunc { http.Error(w, `{"error": "Failed to delete path"}`, http.StatusInternalServerError) return } - - ReadAllSavePath(db)(w, r) } } diff --git a/templates/settings.pages.tmpl b/templates/settings.pages.tmpl index 9d164a6..e9b2fb5 100644 --- a/templates/settings.pages.tmpl +++ b/templates/settings.pages.tmpl @@ -53,16 +53,50 @@
-
-

Section

-
-
-
- -
- +
+
+

Settings

+

Gestion des dossiers Upload

+ +
+ +
+