tagliatelle

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit bc6052e93a2a67da68bd3ec860b21507b4921c01
parent fb0b8116106fb4ab360dd0326bf0313d850040d9
Author: breadcat <breadcat@users.noreply.github.com>
Date:   Sun, 17 May 2026 10:34:15 +0100

Add local file upload

It's quirky, but useful to some people I guess

Diffstat:
Minclude-routes.go | 1+
Ainclude-upload-local.go | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtemplates/add.html | 9+++++++--
3 files changed, 67 insertions(+), 2 deletions(-)

diff --git a/include-routes.go b/include-routes.go @@ -10,6 +10,7 @@ func RegisterRoutes() { http.HandleFunc("/", listFilesHandler) http.HandleFunc("/add", uploadHandler) http.HandleFunc("/add-yt", ytdlpHandler) + http.HandleFunc("/add-local", localFileHandler) http.HandleFunc("/admin", adminHandler) http.HandleFunc("/bulk-tag", bulkTagHandler) http.HandleFunc("/cbz/", cbzViewerHandler) diff --git a/include-upload-local.go b/include-upload-local.go @@ -0,0 +1,59 @@ +package main + +import ( + "fmt" + "net/http" + "os" + "path/filepath" + "strings" +) + +func localFileHandler(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodPost { + http.Redirect(w, r, "/upload", http.StatusSeeOther) + return + } + + rawPath := strings.TrimSpace(r.FormValue("filepath")) + if rawPath == "" { + renderError(w, "No file path provided", http.StatusBadRequest) + return + } + + // Resolve to an absolute, cleaned path to prevent traversal tricks + absPath, err := filepath.Abs(rawPath) + if err != nil { + renderError(w, "Invalid file path", http.StatusBadRequest) + return + } + + // Confirm the file actually exists and is a regular file (not a dir/symlink) + info, err := os.Stat(absPath) + if err != nil { + if os.IsNotExist(err) { + renderError(w, fmt.Sprintf("File not found: %s", absPath), http.StatusBadRequest) + } else { + renderError(w, fmt.Sprintf("Cannot access file: %v", err), http.StatusInternalServerError) + } + return + } + if !info.Mode().IsRegular() { + renderError(w, "Path must point to a regular file", http.StatusBadRequest) + return + } + + f, err := os.Open(absPath) + if err != nil { + renderError(w, fmt.Sprintf("Failed to open file: %v", err), http.StatusInternalServerError) + return + } + defer f.Close() + + id, warningMsg, err := processUpload(f, filepath.Base(absPath)) + if err != nil { + renderError(w, err.Error(), http.StatusInternalServerError) + return + } + + redirectWithWarning(w, r, fmt.Sprintf("/file/%d", id), warningMsg) +} diff --git a/templates/add.html b/templates/add.html @@ -17,4 +17,10 @@ <br><button type="submit" class="text-button">Download Video</button> </form> -{{template "_footer"}} -\ No newline at end of file +<h2>Add Local File</h2> +<form method="post" action="/add-local"> + <input type="text" name="filepath" required placeholder="/path/to/your/file.mp4"> + <br><button type="submit" class="text-button">Add File</button> +</form> + +{{template "_footer"}}