aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--app/js/app.js26
1 files changed, 20 insertions, 6 deletions
diff --git a/app/js/app.js b/app/js/app.js
index 8721486..228184d 100644
--- a/app/js/app.js
+++ b/app/js/app.js
@@ -21,7 +21,7 @@ function login(username, password) {
21 localStorage.username = username; 21 localStorage.username = username;
22 localStorage.password = password; 22 localStorage.password = password;
23 23
24 loadDirectory(app.path); 24 loadDirectory(window.location.hash.slice(1));
25 }); 25 });
26} 26}
27 27
@@ -43,6 +43,10 @@ function encode(filePath) {
43 return filePath.split('/').map(encodeURIComponent).join('/'); 43 return filePath.split('/').map(encodeURIComponent).join('/');
44} 44}
45 45
46function decode(filePath) {
47 return filePath.split('/').map(decodeURIComponent).join('/');
48}
49
46var mimeTypes = { 50var mimeTypes = {
47 images: [ '.png', '.jpg', '.jpeg', '.tiff', '.gif' ], 51 images: [ '.png', '.jpg', '.jpeg', '.tiff', '.gif' ],
48 text: [ '.txt', '.md' ], 52 text: [ '.txt', '.md' ],
@@ -81,13 +85,16 @@ function loadDirectory(filePath) {
81 if (error) return console.error(error); 85 if (error) return console.error(error);
82 if (result.statusCode === 401) return logout(); 86 if (result.statusCode === 401) return logout();
83 87
84 result.body.entries.sort(function (a, b) { return a.isDirectory && b.isFile ? -1 : 1 }); 88 result.body.entries.sort(function (a, b) { return a.isDirectory && b.isFile ? -1 : 1; });
85 app.entries = result.body.entries.map(function (entry) { 89 app.entries = result.body.entries.map(function (entry) {
86 entry.previewUrl = getPreviewUrl(entry, filePath); 90 entry.previewUrl = getPreviewUrl(entry, filePath);
87 return entry; 91 return entry;
88 }); 92 });
89 app.path = filePath; 93 app.path = filePath;
90 app.pathParts = filePath.split('/').filter(function (e) { return !!e; }); 94 app.pathParts = decode(filePath).split('/').filter(function (e) { return !!e; });
95
96 // update in case this was triggered from code
97 window.location.hash = app.path;
91 98
92 Vue.nextTick(function () { 99 Vue.nextTick(function () {
93 $(function () { 100 $(function () {
@@ -98,15 +105,18 @@ function loadDirectory(filePath) {
98} 105}
99 106
100function open(entry) { 107function open(entry) {
101 var path = sanitize(app.path + '/' + entry.filePath); 108 var path = encode(sanitize(app.path + '/' + entry.filePath));
102 109
103 if (entry.isDirectory) return loadDirectory(path); 110 if (entry.isDirectory) {
111 window.location.hash = path;
112 return;
113 }
104 114
105 window.open(path); 115 window.open(path);
106} 116}
107 117
108function up() { 118function up() {
109 loadDirectory(app.path.split('/').slice(0, -1).filter(function (p) { return !!p; }).join('/')); 119 window.location.hash = encode(sanitize(app.path.split('/').slice(0, -1).filter(function (p) { return !!p; }).join('/')));
110} 120}
111 121
112function upload() { 122function upload() {
@@ -219,4 +229,8 @@ var app = new Vue({
219 229
220login(localStorage.username, localStorage.password); 230login(localStorage.username, localStorage.password);
221 231
232$(window).on('hashchange', function () {
233 loadDirectory(window.location.hash.slice(1));
234});
235
222})(); 236})();