up
This commit is contained in:
parent
6b884ce24b
commit
ac15bd91e5
@ -22,10 +22,36 @@ func renderPathHTML(path models.PathDownload) string {
|
|||||||
<div id="path-%d" class="path-update grid is-col-min-1">
|
<div id="path-%d" class="path-update grid is-col-min-1">
|
||||||
<input class="input is-primary cell" name="id" disabled value="%d"></input>
|
<input class="input is-primary cell" name="id" disabled value="%d"></input>
|
||||||
<input class="input is-primary fff cell" name="pathName" value="%s" disabled></span>
|
<input class="input is-primary fff cell" name="pathName" value="%s" disabled></span>
|
||||||
<button class="button is-primary is-dark" id="btn-path-edit-%d" hx-trigger="click" hx-target="#path-%d" hx-swap="outerHTML" onclick="enableAllInputPath(%d)">Edit</button>
|
|
||||||
<button class="button is-danger" type="button" id="btn-path-annuler-%d" onclick="disableAllInputPath(%d)" style="display:none" >Annuler</button>
|
<button class="button is-primary is-dark" id="btn-path-edit-%d"
|
||||||
<button class="button is-primary is-dark" id="btn-path-valider-%d" hx-put="/api/pathDownload/update/%d" hx-trigger="click[checkGlobalState()]" hx-target="#path-%d" hx-swap="outerHTML" hx-ext="json-enc" style="display:none">Valider</button>
|
hx-trigger="click"
|
||||||
<button class="button is-danger" hx-delete="/api/pathDownload/delete/%d" hx-trigger="click" hx-target="#path-%d" hx-swap="outerHTML" hx-confirm="Are you sure?" hx-swap="outerHTML swap:1s">Delete</button>
|
hx-target="#path-%d"
|
||||||
|
hx-swap="outerHTML"
|
||||||
|
onclick="enableAllInputPath(%d)">
|
||||||
|
Edit
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button class="button is-danger" type="button" id="btn-path-annuler-%d"
|
||||||
|
onclick="disableAllInputPath(%d)" style="display:none">
|
||||||
|
Annuler
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button class="button is-primary is-dark" id="btn-path-valider-%d"
|
||||||
|
hx-put="/api/pathDownload/update/%d"
|
||||||
|
hx-trigger="click[checkGlobalState()]"
|
||||||
|
hx-target="#path-%d"
|
||||||
|
hx-swap="outerHTML"
|
||||||
|
hx-ext="json-enc" style="display:none">
|
||||||
|
Valider
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button class="button is-danger"
|
||||||
|
hx-delete="/api/pathDownload/delete/%d"
|
||||||
|
hx-target="#path-%d"
|
||||||
|
hx-swap="outerHTML swap:1s"
|
||||||
|
hx-confirm="Are you sure?">
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>`,
|
</div>`,
|
||||||
@ -36,6 +62,7 @@ func renderPathHTML(path models.PathDownload) string {
|
|||||||
path.ID, path.ID)
|
path.ID, path.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func GetFirstActiveAccount(client *debridlink.Client) *debridlink.DebridAccount {
|
func GetFirstActiveAccount(client *debridlink.Client) *debridlink.DebridAccount {
|
||||||
ctx := context.Background() // ✅ on remplace ici
|
ctx := context.Background() // ✅ on remplace ici
|
||||||
|
|
||||||
@ -70,12 +97,15 @@ func CreateSavePath(db *gorm.DB) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fullPath := "/app/upload/" + pathDownload.PathName
|
fullPath := "/app/upload/" + pathDownload.PathName
|
||||||
if _, err := os.Stat(fullPath); os.IsNotExist(err) {
|
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 {
|
if err := os.MkdirAll(fullPath, 0755); err != nil {
|
||||||
http.Error(w, `{"error": "Failed to create directory"}`, http.StatusInternalServerError)
|
http.Error(w, `{"error": "Failed to create directory"}`, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pathDownload.Path = fullPath
|
pathDownload.Path = fullPath
|
||||||
if err := db.Create(&pathDownload).Error; err != nil {
|
if err := db.Create(&pathDownload).Error; err != nil {
|
||||||
@ -83,11 +113,11 @@ func CreateSavePath(db *gorm.DB) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 👉 On renvoie uniquement la ligne HTML nouvellement créée
|
|
||||||
fmt.Fprint(w, renderPathHTML(pathDownload))
|
fmt.Fprint(w, renderPathHTML(pathDownload))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func ReadAllSavePath(db *gorm.DB) http.HandlerFunc {
|
func ReadAllSavePath(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "text/html")
|
w.Header().Set("Content-Type", "text/html")
|
||||||
@ -100,31 +130,14 @@ func ReadAllSavePath(db *gorm.DB) http.HandlerFunc {
|
|||||||
|
|
||||||
var response strings.Builder
|
var response strings.Builder
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
response.WriteString(fmt.Sprintf(`
|
response.WriteString(renderPathHTML(path))
|
||||||
<div class="column">
|
|
||||||
<form>
|
|
||||||
<div id="path-%d" class="path-update grid is-col-min-1">
|
|
||||||
<input class="input is-primary cell" name="id" disabled value="%d"></input>
|
|
||||||
<input class="input is-primary fff cell" name="pathName" value="%s" disabled></span>
|
|
||||||
<button class="button is-primary is-dark" id="btn-path-edit-%d" hx-trigger="click" hx-target="#path-%d" hx-swap="outerHTML" onclick="enableAllInputPath(%d)">Edit</button>
|
|
||||||
<button class="button is-danger" type="button" id="btn-path-annuler-%d" onclick="disableAllInputPath(%d)" style="display:none" >Annuler</button>
|
|
||||||
<button class="button is-primary is-dark" id="btn-path-valider-%d" hx-put="/api/pathDownload/update/%d" hx-trigger="click[checkGlobalState()]" hx-target="#path-%d" hx-swap="outerHTML" hx-ext="json-enc" style="display:none">Valider</button>
|
|
||||||
<button class="button is-danger" hx-delete="/api/pathDownload/delete/%d" hx-trigger="click" hx-target="#path-%d" hx-swap="outerHTML" hx-confirm="Are you sure?" hx-swap="outerHTML swap:1s">Delete</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>`,
|
|
||||||
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))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
fmt.Fprint(w, response.String())
|
fmt.Fprint(w, response.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func UpdateSavePath(db *gorm.DB) http.HandlerFunc {
|
func UpdateSavePath(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "text/html")
|
w.Header().Set("Content-Type", "text/html")
|
||||||
@ -158,28 +171,22 @@ func UpdateSavePath(db *gorm.DB) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 👉 On renvoie uniquement la ligne HTML mise à jour
|
|
||||||
fmt.Fprint(w, renderPathHTML(existingPath))
|
fmt.Fprint(w, renderPathHTML(existingPath))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func DeleteSavePath(db *gorm.DB) http.HandlerFunc {
|
func DeleteSavePath(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
id := mux.Vars(r)["id"]
|
id := mux.Vars(r)["id"]
|
||||||
|
|
||||||
var pathDownload models.PathDownload
|
var pathDownload models.PathDownload
|
||||||
if err := db.First(&pathDownload, "id = ?", id).Error; err != nil {
|
if err := db.First(&pathDownload, "id = ?", id).Error; err != nil {
|
||||||
if err == gorm.ErrRecordNotFound {
|
|
||||||
http.Error(w, `{"error": "Path not found"}`, http.StatusNotFound)
|
http.Error(w, `{"error": "Path not found"}`, http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
http.Error(w, `{"error": "Failed to retrieve path"}`, http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Supprimer physiquement le dossier
|
|
||||||
fullPath := "/app/upload/" + pathDownload.PathName
|
fullPath := "/app/upload/" + pathDownload.PathName
|
||||||
if err := os.RemoveAll(fullPath); err != nil {
|
if err := os.RemoveAll(fullPath); err != nil {
|
||||||
http.Error(w, `{"error": "Failed to delete directory"}`, http.StatusInternalServerError)
|
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)
|
http.Error(w, `{"error": "Failed to delete path"}`, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadAllSavePath(db)(w, r)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -53,16 +53,50 @@
|
|||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<section class="section is-primary">
|
<section class="hero has-background-primary">
|
||||||
<h1 class="title">Section</h1>
|
<div class="hero-body">
|
||||||
<div class="column">
|
<p class="title">Settings</p>
|
||||||
<div hx-get="/godownloader/settings" hx-trigger="load" hx-target="#download-list"> </div>
|
<p class="subtitle">Gestion des dossiers Upload</p>
|
||||||
<div id="download-list">
|
|
||||||
<!-- Liste des chemins apparaîtra ici -->
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<section class="section is-link">
|
||||||
|
<div class="column">
|
||||||
|
<h1 class="title">Ajouter un dossier</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="column">
|
||||||
|
<div class="field">
|
||||||
|
<label class="label">Nom du dossier :</label>
|
||||||
|
<div class="control has-icons-right">
|
||||||
|
<input type="text" id="path-input" class="input" placeholder="Ex: Manga" oninput="validatePath()" />
|
||||||
|
<span class="icon is-small is-right">
|
||||||
|
<span id="path-status-icon"></span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form
|
||||||
|
hx-post="/api/pathDownload/create"
|
||||||
|
hx-target="#path-list"
|
||||||
|
hx-swap="beforeend"
|
||||||
|
hx-ext="json-enc"
|
||||||
|
style="margin-top: 10px;">
|
||||||
|
<input type="hidden" id="pathName" name="pathName">
|
||||||
|
<button id="validate-btn" class="button is-primary" disabled type="submit">
|
||||||
|
Valider
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="column">
|
||||||
|
<div hx-get="/api/pathDownload/all/" hx-trigger="load once" hx-target="#path-list" hx-swap="innerHTML"></div>
|
||||||
|
<div id="path-list"></div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<section class="section is-info">
|
<section class="section is-info">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user