From 80cbfbafb7b3bd87814cd2d4d3fc6f6ca2c72f26 Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Tue, 23 Mar 2021 11:31:11 +0100 Subject: [PATCH] Redirect to API if user agent is wget Fixes #7 --- webcontroller/file_viewer.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/webcontroller/file_viewer.go b/webcontroller/file_viewer.go index 3f227ba..779e279 100644 --- a/webcontroller/file_viewer.go +++ b/webcontroller/file_viewer.go @@ -83,6 +83,13 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request, return } + // If the user agent is Wget we redirect it to the API so that the file can + // be downloaded directly + if strings.HasPrefix(r.UserAgent(), "Wget/") { + http.Redirect(w, r, "/api/file/"+p.ByName("id"), http.StatusSeeOther) + return + } + var ids = strings.Split(p.ByName("id"), ",") templateData := wc.newTemplateData(w, r)