|
|
@ -104,16 +104,16 @@ exports.delete = (req, res, next) => { |
|
|
|
multer({ dest: `${dir}` }); |
|
|
|
multer({ dest: `${dir}` }); |
|
|
|
const path = req.body.path.replace(cdnConfig.uri, storageConfig.uri); |
|
|
|
const path = req.body.path.replace(cdnConfig.uri, storageConfig.uri); |
|
|
|
const newpath = req.body.path.replace(cdnConfig.uri, storageConfig.uri_backup); |
|
|
|
const newpath = req.body.path.replace(cdnConfig.uri, storageConfig.uri_backup); |
|
|
|
// fs.rm(path, { recursive: true }, err => {
|
|
|
|
fs.rm(path, { recursive: true }, err => { |
|
|
|
// if (err) {
|
|
|
|
if (err) { |
|
|
|
// return res.status(400).json({ code: 400, message: 'lỗi', detail: err });
|
|
|
|
return res.status(400).json({ code: 400, message: 'lỗi', detail: err }); |
|
|
|
// }
|
|
|
|
} |
|
|
|
// return res.json({ code: 0, message: 'success' });
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
fs.rename(path, newpath, (err) => { |
|
|
|
|
|
|
|
if (err) throw err; |
|
|
|
|
|
|
|
return res.json({ code: 0, message: 'success' }); |
|
|
|
return res.json({ code: 0, message: 'success' }); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
// fs.rename(path, newpath, (err) => {
|
|
|
|
|
|
|
|
// if (err) throw err;
|
|
|
|
|
|
|
|
// return res.json({ code: 0, message: 'success' });
|
|
|
|
|
|
|
|
// });
|
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} catch (ex) { |
|
|
|
} catch (ex) { |
|
|
|
return ErrorHandel(ex, req, res, next); |
|
|
|
return ErrorHandel(ex, req, res, next); |
|
|
@ -172,24 +172,40 @@ exports.forceDelete = (req, res, next) => { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// exports.deleteMultiple = (req, res, next) => {
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// const user = req.user;
|
|
|
|
|
|
|
|
// const dir = `${storageConfig.uri_backup}/${user.id}`;
|
|
|
|
|
|
|
|
// multer({ dest: `${dir}` });
|
|
|
|
|
|
|
|
// if (req.body.data) {
|
|
|
|
|
|
|
|
// req.body.data.forEach((e) => {
|
|
|
|
|
|
|
|
// const path = e.path.replace(cdnConfig.uri, storageConfig.uri);
|
|
|
|
|
|
|
|
// const newpath = e.path.replace(cdnConfig.uri, storageConfig.uri_backup);
|
|
|
|
|
|
|
|
// console.log(path, newpath);
|
|
|
|
|
|
|
|
// fs.rename(path, newpath, (err) => {
|
|
|
|
|
|
|
|
// if (err) throw err;
|
|
|
|
|
|
|
|
// return { code: 0, message: 'success' };
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return res.json({ code: 0, message: 'success' });
|
|
|
|
|
|
|
|
// } catch (ex) {
|
|
|
|
|
|
|
|
// return ErrorHandel(ex, req, res, next);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.deleteMultiple = (req, res, next) => { |
|
|
|
exports.deleteMultiple = (req, res, next) => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const user = req.user; |
|
|
|
const path = req.body.path.replace(cdnConfig.uri, storageConfig.uri); |
|
|
|
const dir = `${storageConfig.uri_backup}/${user.id}`; |
|
|
|
fs.rm(path, { recursive: true }, err => { |
|
|
|
multer({ dest: `${dir}` }); |
|
|
|
if (err) { |
|
|
|
if (req.body.data) { |
|
|
|
return res.status(400).json({ code: 400, message: 'lỗi', detail: err }); |
|
|
|
req.body.data.forEach((e) => { |
|
|
|
} |
|
|
|
const path = e.path.replace(cdnConfig.uri, storageConfig.uri); |
|
|
|
return res.json({ code: 0, message: 'success' }); |
|
|
|
const newpath = e.path.replace(cdnConfig.uri, storageConfig.uri_backup); |
|
|
|
}); |
|
|
|
console.log(path, newpath); |
|
|
|
return null; |
|
|
|
fs.rename(path, newpath, (err) => { |
|
|
|
|
|
|
|
if (err) throw err; |
|
|
|
|
|
|
|
return { code: 0, message: 'success' }; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return res.json({ code: 0, message: 'success' }); |
|
|
|
|
|
|
|
} catch (ex) { |
|
|
|
} catch (ex) { |
|
|
|
return ErrorHandel(ex, req, res, next); |
|
|
|
return ErrorHandel(ex, req, res, next); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |