|
|
@ -88,7 +88,7 @@ exports.create = (req, res, next) => { |
|
|
|
if (!fs.existsSync(dir)) { |
|
|
|
if (!fs.existsSync(dir)) { |
|
|
|
uploadAdapter.createFolder({ path: dir }); |
|
|
|
uploadAdapter.createFolder({ path: dir }); |
|
|
|
} |
|
|
|
} |
|
|
|
return res.json({ code: 0, message: 'success'}); |
|
|
|
return res.json({ code: 0, message: 'success' }); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -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); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|