]> git.immae.eu Git - perso/Immae/Projets/Nodejs/Surfer.git/blobdiff - frontend/js/app.js
Add file download button
[perso/Immae/Projets/Nodejs/Surfer.git] / frontend / js / app.js
index de61dcf8f522aa48c49d929feba1e52e0891bc30..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,
@@ -344,7 +351,11 @@ var app = new Vue({
 
 window.app = app;
 
-getProfile(localStorage.accessToken);
+getProfile(localStorage.accessToken, function (error) {
+    if (error) return console.error(error);
+
+    loadDirectory(window.location.hash.slice(1));
+});
 
 $(window).on('hashchange', function () {
     loadDirectory(window.location.hash.slice(1));