From 534c456a5b74f43e4b6e01d857d003d3c52f6738 Mon Sep 17 00:00:00 2001
From: Wim Brand
Date: Tue, 6 Nov 2018 22:19:57 +0100
Subject: [PATCH] remove file download api
---
res/static/script/Toolbar.js | 12 ++++++------
res/template/apidoc.html | 1 -
res/template/fragments/api/file.html | 24 +++++++++++-------------
webcontroller/filePreview.go | 2 +-
4 files changed, 18 insertions(+), 21 deletions(-)
diff --git a/res/static/script/Toolbar.js b/res/static/script/Toolbar.js
index 677850e..6a6f848 100644
--- a/res/static/script/Toolbar.js
+++ b/res/static/script/Toolbar.js
@@ -1,8 +1,8 @@
-/*
+/*
* Time for a more Java-like approach.
- *
+ *
* Feel free to use this of course
- *
+ *
* Made by Fornax
*/
@@ -36,13 +36,13 @@ var Toolbar = {
}
},
download: function () {
- $("#frmDownload").attr("src", "/api/file/" + Viewer.currentFile + "/download");
+ $("#frmDownload").attr("src", "/api/file/" + Viewer.currentFile + "?download");
},
downloadList: function(){
if(!Viewer.isList){
return;
}
-
+
$("#frmDownload").attr("src", "/api/list/" + Viewer.listId + "/zip");
},
copyUrl: function () {
@@ -59,7 +59,7 @@ var Toolbar = {
$("#btnCopy>span").text("Error!");
alert("Your browser does not support copying text.");
}
-
+
// Return to normal
setTimeout(function(){
$("#btnCopy>span").text("Copy");
diff --git a/res/template/apidoc.html b/res/template/apidoc.html
index 20908a2..cef14a0 100644
--- a/res/template/apidoc.html
+++ b/res/template/apidoc.html
@@ -70,7 +70,6 @@
File Methods
{{template "api-file-post"}}
{{template "api-file-id-get"}}
- {{template "api-file-id-download-get"}}
{{template "api-file-id-info-get"}}
{{template "api-file-id-thumbnail-get"}}
{{template "api-file-id-delete"}}
diff --git a/res/template/fragments/api/file.html b/res/template/fragments/api/file.html
index d8598fa..6d747dc 100644
--- a/res/template/fragments/api/file.html
+++ b/res/template/fragments/api/file.html
@@ -80,6 +80,11 @@
Returns the full file associated with the ID. Supports
byte range requests.
+
+ When '?download' is added to the URL the server will send an
+ attachment header instead of inline rendering, which causes the
+ browser to show a 'Save File' dialog.
+
Parameters
@@ -94,25 +99,18 @@
URL |
ID of the file to request |
+
+ download |
+ false |
+ URL |
+ Sends file attachment instead of inline |
+
Returns
A file output stream.
{{end}}
-{{define "api-file-id-download-get"}}
-
- GET/file/{id}/download
-
-
Description
-
- Same as GET /file/{id}, but with File Transfer HTTP
- headers. Will trigger a save file dialog when opened in
- a web browser. Also supports byte range requests.
-
-
-
-{{end}}
{{define "api-file-id-info-get"}}
GET/file/{id}/info
diff --git a/webcontroller/filePreview.go b/webcontroller/filePreview.go
index 0558528..7ea3d7b 100644
--- a/webcontroller/filePreview.go
+++ b/webcontroller/filePreview.go
@@ -49,7 +49,7 @@ type filePreview struct {
func (f filePreview) run(inf *pixelapi.FileInfo) string {
f.FileInfo = inf
f.FileURL = f.APIURL + "/file/" + f.FileInfo.ID
- f.DownloadURL = f.APIURL + "/file/" + f.FileInfo.ID + "/download"
+ f.DownloadURL = f.APIURL + "/file/" + f.FileInfo.ID + "?download"
if strings.HasPrefix(f.FileInfo.MimeType, "image") {
return f.image()