commit 5742d5c174c69b803f2007449a2c281f95eb76b4
parent bc6052e93a2a67da68bd3ec860b21507b4921c01
Author: breadcat <breadcat@users.noreply.github.com>
Date: Sun, 17 May 2026 11:22:09 +0100
Allow deletion of source after upload
Diffstat:
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/include-upload-local.go b/include-upload-local.go
@@ -49,11 +49,20 @@ func localFileHandler(w http.ResponseWriter, r *http.Request) {
}
defer f.Close()
+ deleteSource := r.FormValue("delete_source") == "on"
+
id, warningMsg, err := processUpload(f, filepath.Base(absPath))
if err != nil {
renderError(w, err.Error(), http.StatusInternalServerError)
return
}
+ if deleteSource {
+ f.Close()
+ if removeErr := os.Remove(absPath); removeErr != nil {
+ warningMsg = strings.TrimPrefix(fmt.Sprintf("%s; could not delete source file: %v", warningMsg, removeErr), "; ")
+ }
+ }
+
redirectWithWarning(w, r, fmt.Sprintf("/file/%d", id), warningMsg)
}
diff --git a/templates/add.html b/templates/add.html
@@ -19,7 +19,7 @@
<h2>Add Local File</h2>
<form method="post" action="/add-local">
- <input type="text" name="filepath" required placeholder="/path/to/your/file.mp4">
+ <input type="text" name="filepath" required placeholder="/path/to/your/file.mp4"><label><input type="checkbox" name="delete_source"> Delete source file after upload</label>
<br><button type="submit" class="text-button">Add File</button>
</form>