serve library files for download
This commit is contained in:
parent
da66c2fdf9
commit
445c1321ba
2 changed files with 27 additions and 0 deletions
26
server/file.go
Normal file
26
server/file.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func handleFile(w http.ResponseWriter, r *http.Request) {
|
||||
id := r.PathValue("id")
|
||||
if id == "" {
|
||||
http.Error(w, "No id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO check if worker is working on a task involving this file
|
||||
|
||||
var path string
|
||||
err := db.QueryRow(r.Context(), "SELECT path FROM files WHERE id = $1", id).Scan(&path)
|
||||
if err != nil {
|
||||
http.Error(w, "Error Getting Path: "+err.Error(), http.StatusBadRequest)
|
||||
slog.ErrorContext(r.Context(), "Getting Path", "err", err)
|
||||
return
|
||||
}
|
||||
|
||||
http.ServeFile(w, r, path)
|
||||
}
|
|
@ -75,6 +75,7 @@ func Start(_conf config.Config, tmplFS embed.FS, staticFS embed.FS, migrationsFS
|
|||
mux.HandleFunc("/worker", handleWorkerWebsocket)
|
||||
mux.Handle("/static/", fs)
|
||||
mux.HandleFunc("/tasks", handleTasks)
|
||||
mux.HandleFunc("/files/{id}", handleFile)
|
||||
mux.HandleFunc("/tasks/{id}", handleTask)
|
||||
mux.HandleFunc("/scan/{id}", handleScan)
|
||||
mux.HandleFunc("/libraries/{id}", handleLibrary)
|
||||
|
|
Loading…
Add table
Reference in a new issue