diff --git a/handlers.go b/handlers.go index 6e92aa5..76b9701 100644 --- a/handlers.go +++ b/handlers.go @@ -209,3 +209,26 @@ func handleAbort(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Abort signal sent for %s", filename) } + +func handleClearCompleted(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodPost { + http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) + return + } + + clearCompletedJobs() + + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(map[string]bool{"success": true}) +} + +func clearCompletedJobs() { + progressMutex.Lock() + defer progressMutex.Unlock() + + for filename, info := range progress { + if info.Percentage >= 100 { + delete(progress, filename) + } + } +} diff --git a/main.go b/main.go index 86360aa..1b66682 100644 --- a/main.go +++ b/main.go @@ -81,6 +81,7 @@ func startWebServer() { http.HandleFunc("/abort", handleAbort) http.HandleFunc("/pause", handlePause) http.HandleFunc("/resume", handleResume) + http.HandleFunc("/clear-completed", handleClearCompleted) fmt.Println("Starting web server on http://0.0.0.0:8080") http.ListenAndServe(":8080", nil) diff --git a/templates/index b/templates/index index b0e7cc1..bc57763 100644 --- a/templates/index +++ b/templates/index @@ -45,6 +45,7 @@ ul { list-style-type: none; padding: 0; + margin-bottom: 10px; } li { background-color: #2d2d2d; @@ -83,6 +84,25 @@ input[type="file"], input[type="submit"] { font-size: 16px; } + input[type="submit"], #clear-completed { + font-size: 16px; + } + } + input[type="submit"], #clear-completed { + cursor: pointer; + color: white; + border: 1px solid #444; + padding: 8px 12px; + border-radius: 4px; + margin-bottom: 10px; + max-width: 100%; + width: 100%; + } + #clear-completed { + background-color: #f44336; + } + #clear-completed:hover { + background-color: #d32f2f; } @@ -107,5 +127,19 @@