diff --git a/client/helpers/cache.js b/client/helpers/cache.js index e5d792bc..3ed58cfe 100644 --- a/client/helpers/cache.js +++ b/client/helpers/cache.js @@ -163,7 +163,6 @@ Data.prototype.destroy = function(){ this._init(); } - // // test // cache = new Data(); // cache.put(cache.FILE_PATH, '/', {a:3}); diff --git a/client/model/files.js b/client/model/files.js index 996023d9..fb8bba9f 100644 --- a/client/model/files.js +++ b/client/model/files.js @@ -171,7 +171,7 @@ class FileSystem{ function ui_before_request(from, to){ return update_from() .then((file) => { - if(Path.dirname(from) !== Path.dirname(to)){ + if(dirname(from) !== dirname(to)){ return update_to(file); } return Promise.resolve(); @@ -205,7 +205,7 @@ class FileSystem{ function ui_when_fail(from, to){ return update_from() .then((file) => { - if(Path.dirname(from) !== Path.dirname(to)){ + if(dirname(from) !== dirname(to)){ return update_to(); } return Promise.resolve(); @@ -241,7 +241,7 @@ class FileSystem{ } } function ui_when_success(from, to){ - if(Path.dirname(from) === Path.dirname(to)){ + if(dirname(from) === dirname(to)){ return this._replace(dirname(from)+basename(to), null); }else{ return update_from() @@ -286,9 +286,9 @@ class FileSystem{ // manage nested directories when we try to rename a directory if(/\/$/.test(from) === true){ return cache.update_path((data) => { - if(data.path !== Path.dirname(to) + "/" && data.path !== Path.dirname(from) + "/" && data.path.indexOf(Path.dirname(from) + "/") === 0){ + if(data.path !== dirname(to) && data.path !== dirname(from) && data.path.indexOf(dirname(from)) === 0){ const old_path = data.path; - data.path = data.path.replace(Path.dirname(from) + "/", Path.dirname(to) + "/"); + data.path = data.path.replace(dirname(from), dirname(to)); return cache.remove(cache.FILE_PATH, old_path) .then(() => cache.put(cache.FILE_PATH, data.path, data)); } @@ -318,7 +318,7 @@ class FileSystem{ }); res.results = files; return cache.put(cache.FILE_PATH, dirname(path), res) - .then((res) => this._ls_from_cache(Path.dirname(path)+"/")); + .then((res) => this._ls_from_cache(dirname(path))); }); } @@ -334,7 +334,7 @@ class FileSystem{ if(icon) file.icon = icon; res.results.push(file); return cache.put(cache.FILE_PATH, dirname(path), res) - .then((res) => this._ls_from_cache(Path.dirname(path)+"/")); + .then((res) => this._ls_from_cache(dirname(path))); }); } _remove(path){ @@ -346,7 +346,7 @@ class FileSystem{ }); res.results = files; return cache.put(cache.FILE_PATH, dirname(path), res) - .then((res) => this._ls_from_cache(Path.dirname(path)+"/")); + .then((res) => this._ls_from_cache(dirname(path))); }); } } diff --git a/server/ctrl/files.js b/server/ctrl/files.js index 44711f7a..258b4a7c 100644 --- a/server/ctrl/files.js +++ b/server/ctrl/files.js @@ -25,17 +25,17 @@ app.get('/ls', function(req, res){ res.send({status: 'ok', results: results}); }) .catch(function(err){ - res.send({status: 'error', message: err.message || 'cannot fetch files', trace: err}) + res.send({status: 'error', message: err.message || 'cannot fetch files', trace: err}); }); }else{ - res.send({status: 'error', message: 'unknown path'}) + res.send({status: 'error', message: 'unknown path'}); } }); // get a file content app.get('/cat', function(req, res){ let path = decodeURIComponent(req.query.path); - res.cookie('download', path, { maxAge: 1000 }) + res.cookie('download', path, { maxAge: 1000 }); if(path){ Files.cat(path, req.cookies.auth, res) .then(function(stream){ @@ -43,10 +43,10 @@ app.get('/cat', function(req, res){ stream.pipe(res); }) .catch(function(err){ - res.send({status: 'error', message: err.message || 'couldn\t read the file', trace: err}) + res.send({status: 'error', message: err.message || 'couldn\t read the file', trace: err}); }); }else{ - res.send({status: 'error', message: 'unknown path'}) + res.send({status: 'error', message: 'unknown path'}); } }); @@ -59,7 +59,7 @@ app.post('/cat', function(req, res){ if(path){ form.on('part', function(part) { part.on('error', function(err){ - res.send({status: 'error', message: 'internal error'}) + res.send({status: 'error', message: 'internal error'}); }); Files.write(path, part, req.cookies.auth) @@ -67,12 +67,12 @@ app.post('/cat', function(req, res){ res.send({status: 'ok'}); }) .catch(function(err){ - res.send({status: 'error', message: err.message || 'couldn\'t write the file', code: err.code}) + res.send({status: 'error', message: err.message || 'couldn\'t write the file', code: err.code}); }); }); form.parse(req); }else{ - res.send({status: 'error', message: 'unknown path'}) + res.send({status: 'error', message: 'unknown path'}); } }); @@ -83,13 +83,13 @@ app.get('/mv', function(req, res){ if(from && to){ Files.mv(from, to, req.cookies.auth) .then((message) => { - res.send({status: 'ok'}) + res.send({status: 'ok'}); }) .catch((err) => { - res.send({status: 'error', message: err.message || 'couldn\'t rename your file', trace: err}) + res.send({status: 'error', message: err.message || 'couldn\'t rename your file', trace: err}); }); }else{ - res.send({status: 'error', message: 'unknown path'}) + res.send({status: 'error', message: 'unknown path'}); } }); @@ -99,13 +99,13 @@ app.get('/rm', function(req, res){ if(path){ Files.rm(path, req.cookies.auth) .then((message) => { - res.send({status: 'ok', result: message}) + res.send({status: 'ok'}); }) .catch((err) => { - res.send({status: 'error', message: err.message || 'couldn\'t delete your file', trace: err}) + res.send({status: 'error', message: err.message || 'couldn\'t delete your file', trace: err}); }); }else{ - res.send({status: 'error', message: 'unknown path'}) + res.send({status: 'error', message: 'unknown path'}); } }); @@ -115,13 +115,13 @@ app.get('/mkdir', function(req, res){ if(path){ Files.mkdir(path, req.cookies.auth) .then((message) => { - res.send({status: 'ok'}) + res.send({status: 'ok'}); }) .catch((err) => { - res.send({status: 'error', message: err.message || 'couldn\'t create a directory', trace: err}) + res.send({status: 'error', message: err.message || 'couldn\'t create a directory', trace: err}); }); }else{ - res.send({status: 'error', message: 'unknown path'}) + res.send({status: 'error', message: 'unknown path'}); } }); @@ -130,13 +130,13 @@ app.get('/touch', function(req, res){ if(path){ Files.touch(path, req.cookies.auth) .then((message) => { - res.send({status: 'ok'}) + res.send({status: 'ok'}); }) .catch((err) => { - res.send({status: 'error', message: err.message || 'couldn\'t create a file', trace: err}) + res.send({status: 'error', message: err.message || 'couldn\'t create a file', trace: err}); }); }else{ - res.send({status: 'error', message: 'unknown path'}) + res.send({status: 'error', message: 'unknown path'}); } });