+function sanitize(filePath) {
+ filePath = '/' + filePath;
+ return filePath.replace(/\/+/g, '/');
+}
+
+function loadDirectory(filePath) {
+ app.busy = true;
+
+ filePath = filePath ? sanitize(filePath) : '/';
+
+ console.log(filePath);
+
+ superagent.get('/api/files/' + filePath).query({ username: app.session.username, password: app.session.password }).end(function (error, result) {
+ app.busy = false;
+
+ if (error) return console.error(error);
+ if (result.statusCode === 401) return logout();
+
+ app.entries = result.body.entries;
+ app.path = filePath;
+ app.pathParts = filePath.split('/').filter(function (e) { return !!e; });
+ console.log(app.pathParts)
+ });
+}
+
+function open(entry) {
+ var path = sanitize(app.path + '/' + entry.filePath);
+
+ if (entry.isDirectory) return loadDirectory(path);
+
+ window.location.href = window.location.origin + path;
+}
+
+function up() {
+ loadDirectory(app.path.split('/').slice(0, -1).filter(function (p) { return !!p; }).join('/'));
+}
+