mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-18 17:21:33 +00:00
Updated
* Updated path resolving for upload folder option. This SHOULD now allow using an absolute path, even those outside of the lolisafe installation. * Added a config option at uploads -> generateThumbs, named placeholder. It's a string option that lets you set path of the placeholder image for files whose thumbnail could not be generated. It defaults to the old hard-coded path when set to falsy value. * Fixed thumbs script not using upload folder from config file. * Added filters for thumb generation error handling. This is used to ignore some common error messages, such as file formats not being supported.
This commit is contained in:
parent
3a398721b5
commit
e45d854c09
@ -282,10 +282,12 @@ module.exports = {
|
||||
/*
|
||||
Thumbnails are only used in the dashboard and album's public pages.
|
||||
You need to install a separate binary called ffmpeg (https://ffmpeg.org/) for video thumbnails.
|
||||
NOTE: Placeholder defaults to 'public/images/unavailable.png'.
|
||||
*/
|
||||
generateThumbs: {
|
||||
image: true,
|
||||
video: false
|
||||
video: false,
|
||||
placeholder: null
|
||||
},
|
||||
|
||||
/*
|
||||
|
@ -11,7 +11,7 @@ const albumsController = {}
|
||||
|
||||
const maxTries = config.uploads.maxTries || 1
|
||||
const homeDomain = config.homeDomain || config.domain
|
||||
const uploadsDir = path.join(__dirname, '..', config.uploads.folder)
|
||||
const uploadsDir = path.resolve(config.uploads.folder)
|
||||
const zipsDir = path.join(uploadsDir, 'zips')
|
||||
const zipMaxTotalSize = config.cloudflare.zipMaxTotalSize
|
||||
const zipMaxTotalSizeBytes = parseInt(config.cloudflare.zipMaxTotalSize) * 1000000
|
||||
|
@ -36,9 +36,9 @@ const _stats = {
|
||||
}
|
||||
}
|
||||
|
||||
const uploadsDir = path.join(__dirname, '..', config.uploads.folder)
|
||||
const uploadsDir = path.resolve(config.uploads.folder)
|
||||
const thumbsDir = path.join(uploadsDir, 'thumbs')
|
||||
const thumbUnavailable = path.join(__dirname, '../public/images/unavailable.png')
|
||||
const thumbPlaceholder = path.resolve(config.uploads.generateThumbs.placeholder || 'public/images/unavailable.png')
|
||||
const cloudflareAuth = config.cloudflare.apiKey && config.cloudflare.email && config.cloudflare.zoneId
|
||||
|
||||
utilsController.imageExtensions = ['.webp', '.jpg', '.jpeg', '.gif', '.png', '.tiff', '.tif', '.svg']
|
||||
@ -250,11 +250,17 @@ utilsController.generateThumbs = (name, force) => {
|
||||
})
|
||||
.then(resolve)
|
||||
.catch(error => {
|
||||
console.error(`${name}: ${error.toString()}`)
|
||||
fs.symlink(thumbUnavailable, thumbname, error => {
|
||||
if (error) console.error(error)
|
||||
const errorString = error.toString()
|
||||
const tests = [
|
||||
/Error: Input file contains unsupported image format/,
|
||||
/Error: ffprobe exited with code 1/
|
||||
]
|
||||
if (!tests.some(t => t.test(errorString)))
|
||||
console.error(`${name}: ${errorString}`)
|
||||
fs.symlink(thumbPlaceholder, thumbname, err => {
|
||||
if (err) console.error(err)
|
||||
// We return true if we could make a symlink to the placeholder image
|
||||
resolve(!error)
|
||||
resolve(!err)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,4 +1,5 @@
|
||||
const { stripIndents } = require('./_utils')
|
||||
const config = require('./../config')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const utils = require('./../controllers/utilsController')
|
||||
@ -58,7 +59,7 @@ thumbs.do = async () => {
|
||||
cfcache: 0 = do not clear cloudflare cache (default), 1 = clear cloudflare cache
|
||||
`))
|
||||
|
||||
const uploadsDir = path.join(__dirname, '..', 'uploads')
|
||||
const uploadsDir = path.resolve(config.uploads.folder)
|
||||
const thumbsDir = path.join(uploadsDir, 'thumbs')
|
||||
const _uploads = await thumbs.getFiles(uploadsDir)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user