]> git.immae.eu Git - perso/Immae/Projets/Nodejs/Surfer.git/commitdiff
Add file download button
authorJohannes Zellner <johannes@cloudron.io>
Fri, 7 Apr 2017 14:49:43 +0000 (16:49 +0200)
committerJohannes Zellner <johannes@cloudron.io>
Fri, 7 Apr 2017 14:49:43 +0000 (16:49 +0200)
frontend/index.html
frontend/js/app.js
src/files.js

index 5374339945b588b554062b8ed9cfad17c43453f7..a6d0eb007ed63d0582e5f0ba702b49b7192f98bb 100644 (file)
                             <th><span v-my-tooltip="foobar" data-toggle="tooltip" title="{{ entry.mtime }}">{{ entry.mtime | prettyDate }}</span></th>
                             <th style="text-align: right;">
                                 <span class="entry-toolbar">
+                                    <button class="btn btn-sm btn-default" v-on:click.stop="download(entry)" title="Download" v-show="entry.isFile"><i class="fa fa-download"></i></button>
                                     <button class="btn btn-sm btn-default" v-on:click.stop="renameAsk(entry)" title="Rename"><i class="fa fa-pencil"></i></button>
                                     <button class="btn btn-sm btn-danger" v-on:click.stop="delAsk(entry)" title="Delete"><i class="fa fa-trash"></i></button>
                                 </span>
index befed24f251ce893642c436df4a8241ccb972785..bf9b5348953abfc6d67effd7ce29394cddffd857 100644 (file)
@@ -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,
index 876ff4e96798b938708cec8dfca372b8e39b56d5..1af4a18a3ece1f215342cd2b90fda8fa871d28ff 100644 (file)
@@ -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) {