Finish first version of WebUI

Close #10
This commit is contained in:
2025-03-04 12:05:31 +01:00
parent dcc46f679b
commit b7923c9091
9 changed files with 216 additions and 40 deletions

View File

@@ -93,3 +93,40 @@ func UploadMediaFiles(c *gowebdav.Client, w io.Writer, files []string) {
uploadFiles(c, w, files, "IMPORT_IMG", "Uploading media files")
}
// Removes a list of files.
func BatchUnlink(w io.Writer, files []string) {
_, wImplementsHttpFlusher := interface{}(w).(http.Flusher)
maxConcTasks := min(10, runtime.NumCPU())
// Set a semaphore to restrict the number of concurrent upload tasks.
semaphore := make(chan struct{}, maxConcTasks)
wg := &sync.WaitGroup{}
for _, f := range(files) {
semaphore <- struct{}{} // acquire
wg.Add(1)
go func() {
defer wg.Done()
err := os.Remove(f)
if err != nil {
panic("Failed to delete file " + f)
}
fmt.Fprintf(w, "Delete file %s\n", f)
<-semaphore // release
}()
}
wg.Wait()
if wImplementsHttpFlusher == true {
w.(http.Flusher).Flush()
}
}