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 } slog.InfoContext(r.Context(), "Serving File Download", "id", id, "path", path) // had timeout issues http.ServeFile(w, r, path) /* reader, err := os.Open(path) if err != nil { http.Error(w, "Error Opening File: "+err.Error(), http.StatusInternalServerError) slog.ErrorContext(r.Context(), "Opening File", "err", err) return } w.Header().Set("Content-Disposition", "attachment;filename="+filepath.Base(path)) _, err = io.Copy(w, reader) if err != nil { http.Error(w, "Copy File: "+err.Error(), http.StatusBadRequest) slog.ErrorContext(r.Context(), "Copy File", "err", err) return } */ }