Updated albumsController.js

Allow JSZip to be configured from config.js file.
This commit is contained in:
Bobby Wibowo 2019-07-18 06:22:47 +07:00
parent 1b79ee3e91
commit cf20bdbd1a
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
2 changed files with 25 additions and 7 deletions

View File

@ -293,7 +293,20 @@ module.exports = {
The file is generated when the user clicks the download button in the view The file is generated when the user clicks the download button in the view
and is re-used if the album has not changed between download requests. and is re-used if the album has not changed between download requests.
*/ */
generateZips: true generateZips: true,
/*
JSZip's options to use when generating album ZIPs.
https://stuk.github.io/jszip/documentation/api_jszip/generate_async.html
NOTE: Changing this option will not re-generate existing ZIPs.
*/
jsZipOptions: {
streamFiles: true,
compression: 'DEFLATE',
compressionOptions: {
level: 1
}
}
}, },
/* /*

View File

@ -15,6 +15,16 @@ const uploadsDir = path.join(__dirname, '..', config.uploads.folder)
const zipsDir = path.join(uploadsDir, 'zips') const zipsDir = path.join(uploadsDir, 'zips')
const zipMaxTotalSize = config.cloudflare.zipMaxTotalSize const zipMaxTotalSize = config.cloudflare.zipMaxTotalSize
const zipMaxTotalSizeBytes = parseInt(config.cloudflare.zipMaxTotalSize) * 1000000 const zipMaxTotalSizeBytes = parseInt(config.cloudflare.zipMaxTotalSize) * 1000000
const zipOptions = config.uploads.jsZipOptions
// Force 'type' option to 'nodebuffer'
zipOptions.type = 'nodebuffer'
// Apply fallbacks for missing config values
if (zipOptions.streamFiles === undefined) zipOptions.streamFiles = true
if (zipOptions.compression === undefined) zipOptions.compression = 'DEFLATE'
if (zipOptions.compressionOptions === undefined || zipOptions.compressionOptions.level === undefined)
zipOptions.compressionOptions = { level: 1 }
albumsController.zipEmitters = new Map() albumsController.zipEmitters = new Map()
@ -402,12 +412,7 @@ albumsController.generateZip = async (req, res, next) => {
iteration++ iteration++
if (iteration === files.length) if (iteration === files.length)
archive archive
.generateNodeStream({ .generateNodeStream(zipOptions)
type: 'nodebuffer',
streamFiles: true,
compression: 'DEFLATE',
compressionOptions: { level: 1 }
})
.pipe(fs.createWriteStream(zipPath)) .pipe(fs.createWriteStream(zipPath))
.on('finish', async () => { .on('finish', async () => {
console.log(`Finished zip task for album: ${identifier} (success).`) console.log(`Finished zip task for album: ${identifier} (success).`)