From f66b47bd92369aa3c289a8f08de98e7e2ba7b2b0 Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Fri, 7 Apr 2017 16:49:43 +0200 Subject: Add file download button --- frontend/index.html | 1 + frontend/js/app.js | 7 +++++++ src/files.js | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/frontend/index.html b/frontend/index.html index 5374339..a6d0eb0 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -183,6 +183,7 @@ {{ entry.mtime | prettyDate }} + diff --git a/frontend/js/app.js b/frontend/js/app.js index befed24..bf9b534 100644 --- a/frontend/js/app.js +++ b/frontend/js/app.js @@ -135,6 +135,12 @@ function open(entry) { window.open(encode(path)); } +function download(entry) { + if (entry.isDirectory) return; + + window.open(encode('/api/files/' + sanitize(app.path + '/' + entry.filePath)) + '?access_token=' + localStorage.accessToken); +} + function up() { window.location.hash = sanitize(app.path.split('/').slice(0, -1).filter(function (p) { return !!p; }).join('/')); } @@ -329,6 +335,7 @@ var app = new Vue({ logout: logout, loadDirectory: loadDirectory, open: open, + download: download, up: up, upload: upload, delAsk: delAsk, diff --git a/src/files.js b/src/files.js index 876ff4e..1af4a18 100644 --- a/src/files.js +++ b/src/files.js @@ -88,7 +88,7 @@ function get(req, res, next) { debug('get', absoluteFilePath); if (!result.isDirectory() && !result.isFile()) return next(new HttpError(500, 'unsupported type')); - if (result.isFile()) return res.sendFile(absoluteFilePath); + if (result.isFile()) return res.download(absoluteFilePath); async.map(fs.readdirSync(absoluteFilePath), function (filePath, callback) { fs.stat(path.join(absoluteFilePath, filePath), function (error, result) { -- cgit v1.2.3