bugfix (UI): fix issues with file renaming/deletion/creation in UI

This commit is contained in:
Mickael KERJEAN
2018-03-26 13:37:43 +11:00
parent 950f56bbdf
commit 7795b6d74b
3 changed files with 28 additions and 29 deletions

View File

@ -163,7 +163,6 @@ Data.prototype.destroy = function(){
this._init(); this._init();
} }
// // test // // test
// cache = new Data(); // cache = new Data();
// cache.put(cache.FILE_PATH, '/', {a:3}); // cache.put(cache.FILE_PATH, '/', {a:3});

View File

@ -171,7 +171,7 @@ class FileSystem{
function ui_before_request(from, to){ function ui_before_request(from, to){
return update_from() return update_from()
.then((file) => { .then((file) => {
if(Path.dirname(from) !== Path.dirname(to)){ if(dirname(from) !== dirname(to)){
return update_to(file); return update_to(file);
} }
return Promise.resolve(); return Promise.resolve();
@ -205,7 +205,7 @@ class FileSystem{
function ui_when_fail(from, to){ function ui_when_fail(from, to){
return update_from() return update_from()
.then((file) => { .then((file) => {
if(Path.dirname(from) !== Path.dirname(to)){ if(dirname(from) !== dirname(to)){
return update_to(); return update_to();
} }
return Promise.resolve(); return Promise.resolve();
@ -241,7 +241,7 @@ class FileSystem{
} }
} }
function ui_when_success(from, to){ 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); return this._replace(dirname(from)+basename(to), null);
}else{ }else{
return update_from() return update_from()
@ -286,9 +286,9 @@ class FileSystem{
// manage nested directories when we try to rename a directory // manage nested directories when we try to rename a directory
if(/\/$/.test(from) === true){ if(/\/$/.test(from) === true){
return cache.update_path((data) => { 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; 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) return cache.remove(cache.FILE_PATH, old_path)
.then(() => cache.put(cache.FILE_PATH, data.path, data)); .then(() => cache.put(cache.FILE_PATH, data.path, data));
} }
@ -318,7 +318,7 @@ class FileSystem{
}); });
res.results = files; res.results = files;
return cache.put(cache.FILE_PATH, dirname(path), res) 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; if(icon) file.icon = icon;
res.results.push(file); res.results.push(file);
return cache.put(cache.FILE_PATH, dirname(path), res) 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){ _remove(path){
@ -346,7 +346,7 @@ class FileSystem{
}); });
res.results = files; res.results = files;
return cache.put(cache.FILE_PATH, dirname(path), res) 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)));
}); });
} }
} }

View File

@ -25,17 +25,17 @@ app.get('/ls', function(req, res){
res.send({status: 'ok', results: results}); res.send({status: 'ok', results: results});
}) })
.catch(function(err){ .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{ }else{
res.send({status: 'error', message: 'unknown path'}) res.send({status: 'error', message: 'unknown path'});
} }
}); });
// get a file content // get a file content
app.get('/cat', function(req, res){ app.get('/cat', function(req, res){
let path = decodeURIComponent(req.query.path); let path = decodeURIComponent(req.query.path);
res.cookie('download', path, { maxAge: 1000 }) res.cookie('download', path, { maxAge: 1000 });
if(path){ if(path){
Files.cat(path, req.cookies.auth, res) Files.cat(path, req.cookies.auth, res)
.then(function(stream){ .then(function(stream){
@ -43,10 +43,10 @@ app.get('/cat', function(req, res){
stream.pipe(res); stream.pipe(res);
}) })
.catch(function(err){ .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{ }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){ if(path){
form.on('part', function(part) { form.on('part', function(part) {
part.on('error', function(err){ 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) Files.write(path, part, req.cookies.auth)
@ -67,12 +67,12 @@ app.post('/cat', function(req, res){
res.send({status: 'ok'}); res.send({status: 'ok'});
}) })
.catch(function(err){ .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); form.parse(req);
}else{ }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){ if(from && to){
Files.mv(from, to, req.cookies.auth) Files.mv(from, to, req.cookies.auth)
.then((message) => { .then((message) => {
res.send({status: 'ok'}) res.send({status: 'ok'});
}) })
.catch((err) => { .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{ }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){ if(path){
Files.rm(path, req.cookies.auth) Files.rm(path, req.cookies.auth)
.then((message) => { .then((message) => {
res.send({status: 'ok', result: message}) res.send({status: 'ok'});
}) })
.catch((err) => { .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{ }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){ if(path){
Files.mkdir(path, req.cookies.auth) Files.mkdir(path, req.cookies.auth)
.then((message) => { .then((message) => {
res.send({status: 'ok'}) res.send({status: 'ok'});
}) })
.catch((err) => { .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{ }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){ if(path){
Files.touch(path, req.cookies.auth) Files.touch(path, req.cookies.auth)
.then((message) => { .then((message) => {
res.send({status: 'ok'}) res.send({status: 'ok'});
}) })
.catch((err) => { .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{ }else{
res.send({status: 'error', message: 'unknown path'}) res.send({status: 'error', message: 'unknown path'});
} }
}); });