From 0503215e7a5c8f9acbb2551716674b3807fc07f8 Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Tue, 3 Aug 2021 19:58:03 +0200 Subject: [PATCH] web client: try to prevent browsers from caching requests Fixes #493 --- httpd/webclient.go | 4 +++- templates/webclient/files.html | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/httpd/webclient.go b/httpd/webclient.go index bdef63c3..0bd55965 100644 --- a/httpd/webclient.go +++ b/httpd/webclient.go @@ -80,6 +80,7 @@ type filesPage struct { CanCreateDirs bool CanRename bool CanDelete bool + CanDownload bool Error string Paths []dirMapping } @@ -100,7 +101,7 @@ type credentialsPage struct { } func getFileObjectURL(baseDir, name string) string { - return fmt.Sprintf("%v?path=%v", webClientFilesPath, url.QueryEscape(path.Join(baseDir, name))) + return fmt.Sprintf("%v?path=%v&_=%v", webClientFilesPath, url.QueryEscape(path.Join(baseDir, name)), time.Now().UTC().Unix()) } func getFileObjectModTime(t time.Time) string { @@ -211,6 +212,7 @@ func renderFilesPage(w http.ResponseWriter, r *http.Request, dirName, error stri CanCreateDirs: user.CanAddDirsFromWeb(dirName), CanRename: user.CanRenameFromWeb(dirName, dirName), CanDelete: user.CanDeleteFromWeb(dirName), + CanDownload: user.HasPerm(dataprovider.PermDownload, dirName), } paths := []dirMapping{} if dirName != "/" { diff --git a/templates/webclient/files.html b/templates/webclient/files.html index 35193b65..b175f442 100644 --- a/templates/webclient/files.html +++ b/templates/webclient/files.html @@ -467,7 +467,8 @@ var files = fixedEncodeURIComponent(JSON.stringify(filesArray)); var downloadURL = '{{.DownloadURL}}'; var currentDir = '{{.CurrentDir}}'; - window.location = `${downloadURL}?path=${currentDir}&files=${files}`; + var ts = new Date().getTime().toString(); + window.location = `${downloadURL}?path=${currentDir}&files=${files}&_=${ts}`; }, enabled: false }; @@ -614,7 +615,9 @@ "initComplete": function (settings, json) { table.button().add(0, 'refresh'); table.button().add(0, 'pageLength'); + {{if .CanDownload}} table.button().add(0, 'download'); + {{end}} {{if .CanDelete}} table.button().add(0, 'delete'); {{end}}