]> 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 b07560affa57d8bff120ad7c87d3ac92bbfd12a1..bf9b5348953abfc6d67effd7ce29394cddffd857 100644 (file)
@@ -27,7 +27,7 @@ function login(username, password) {
 
     app.busy = true;
 
-    superagent.post('/api/login').query({ username: username, password: password }).end(function (error, result) {
+    superagent.post('/api/login').send({ username: username, password: password }).end(function (error, result) {
         app.busy = false;
 
         if (error) return console.error(error);
@@ -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));