mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-19 01:31:34 +00:00
Updated albumsController.js
Allow JSZip to be configured from config.js file.
This commit is contained in:
parent
1b79ee3e91
commit
cf20bdbd1a
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -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).`)
|
||||||
|
Loading…
Reference in New Issue
Block a user