change path

master
Lucas 2 years ago
parent 2994342be0
commit 17a3eb84db
  1. 9
      src/api/controllers/v1/path.controller.js

@ -137,14 +137,14 @@ exports.delete = (req, res, next) => {
return ErrorHandel(ex, req, res, next); return ErrorHandel(ex, req, res, next);
} }
}; };
exports.download = (req, res, next) => { exports.download = async (req, res, next) => {
try { try {
const user = req.user; const user = req.user;
const namefile = `${user.name}-${Date.now()}.zip`; const namefile = `${user.name}-${Date.now()}.zip`;
const dir = `${storageConfig.uri}/download/${user.id}/${namefile}`; const dir = `${storageConfig.uri}/download/${user.id}/${namefile}`;
const folder = `${storageConfig.uri}/download/${user.id}`; const folder = `${storageConfig.uri}/download/${user.id}`;
multer({ dest: `${dir}` });
deleteFolderRecursive(folder); await deleteFolderRecursive(folder);
const output = fs.createWriteStream(dir); const output = fs.createWriteStream(dir);
const archive = archiver('zip', { const archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level. zlib: { level: 9 } // Sets the compression level.
@ -171,7 +171,7 @@ exports.download = (req, res, next) => {
code: 0, code: 0,
data: { data: {
name: namefile, name: namefile,
path: `${cdnConfig.uri}/${user.id}/${namefile}`, path: `${cdnConfig.uri}/download/${user.id}/${namefile}`,
} }
}); });
} catch (ex) { } catch (ex) {
@ -234,6 +234,5 @@ function deleteFolderRecursive(folderPath) {
console.log('Deleted file:', currentPath); console.log('Deleted file:', currentPath);
} }
}); });
} }
} }

Loading…
Cancel
Save