mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-18 17:21:33 +00:00
fix: animated thumbs in album pages
This commit is contained in:
parent
b6b645df93
commit
3d9c400cab
@ -498,10 +498,14 @@ self.get = async (req, res) => {
|
|||||||
|
|
||||||
const extname = utils.extname(file.name)
|
const extname = utils.extname(file.name)
|
||||||
if (utils.mayGenerateThumb(extname)) {
|
if (utils.mayGenerateThumb(extname)) {
|
||||||
file.thumb = `${config.domain}/thumbs/${file.name.slice(0, -extname.length)}.png`
|
let thumbext = '.png'
|
||||||
|
if (utils.isAnimatedThumb(extname)) thumbext = '.gif'
|
||||||
|
file.thumb = `${config.domain}/thumbs/${file.name.slice(0, -extname.length)}${thumbext}`
|
||||||
|
/* // TODO: Upstream's API response is no longer identical to this.
|
||||||
if (req.locals.upstreamCompat) {
|
if (req.locals.upstreamCompat) {
|
||||||
file.thumbSquare = file.thumb
|
file.thumbSquare = file.thumb
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -519,6 +523,7 @@ self.getUpstreamCompat = async (req, res) => {
|
|||||||
// If requested via /api/album/:identifier,
|
// If requested via /api/album/:identifier,
|
||||||
// map to .get() with chibisafe/upstream compatibility
|
// map to .get() with chibisafe/upstream compatibility
|
||||||
// This API is known to be used in Pitu/Magane
|
// This API is known to be used in Pitu/Magane
|
||||||
|
// TODO: Upstream's API response is no longer identical to this, please fix.
|
||||||
req.locals.upstreamCompat = true
|
req.locals.upstreamCompat = true
|
||||||
|
|
||||||
res._json = res.json
|
res._json = res.json
|
||||||
|
@ -1810,9 +1810,7 @@ self.list = async (req, res) => {
|
|||||||
file.extname = utils.extname(file.name)
|
file.extname = utils.extname(file.name)
|
||||||
if (utils.mayGenerateThumb(file.extname)) {
|
if (utils.mayGenerateThumb(file.extname)) {
|
||||||
let thumbext = '.png'
|
let thumbext = '.png'
|
||||||
if (file.extname === '.gif' && config.uploads.generateThumbs.animated) {
|
if (utils.isAnimatedThumb(file.extname)) thumbext = '.gif'
|
||||||
thumbext = '.gif'
|
|
||||||
}
|
|
||||||
file.thumb = `thumbs/${file.name.slice(0, -file.extname.length)}${thumbext}`
|
file.thumb = `thumbs/${file.name.slice(0, -file.extname.length)}${thumbext}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
const self = {
|
const self = {
|
||||||
IMAGE_EXTS: ['.gif', '.jpeg', '.jpg', '.png', '.svg', '.tif', '.tiff', '.webp'],
|
IMAGE_EXTS: ['.gif', '.jpeg', '.jpg', '.png', '.svg', '.tif', '.tiff', '.webp'],
|
||||||
VIDEO_EXTS: ['.3g2', '.3gp', '.asf', '.avchd', '.avi', '.divx', '.evo', '.flv', '.h264', '.h265', '.hevc', '.m2p', '.m2ts', '.m4v', '.mk3d', '.mkv', '.mov', '.mp4', '.mpeg', '.mpg', '.mxf', '.ogg', '.ogv', '.ps', '.qt', '.rmvb', '.ts', '.vob', '.webm', '.wmv'],
|
VIDEO_EXTS: ['.3g2', '.3gp', '.asf', '.avchd', '.avi', '.divx', '.evo', '.flv', '.h264', '.h265', '.hevc', '.m2p', '.m2ts', '.m4v', '.mk3d', '.mkv', '.mov', '.mp4', '.mpeg', '.mpg', '.mxf', '.ogg', '.ogv', '.ps', '.qt', '.rmvb', '.ts', '.vob', '.webm', '.wmv'],
|
||||||
AUDIO_EXTS: ['.flac', '.mp3', '.wav', '.wma']
|
AUDIO_EXTS: ['.flac', '.mp3', '.wav', '.wma'],
|
||||||
|
ANIMATED_EXTS: ['.gif'] // must also exists in either IMAGE_EXTS or VIDEO_EXTS for thumbnails generation
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = self
|
module.exports = self
|
||||||
|
@ -251,6 +251,11 @@ self.mayGenerateThumb = extname => {
|
|||||||
(config.uploads.generateThumbs.video && Constants.VIDEO_EXTS.includes(extname))
|
(config.uploads.generateThumbs.video && Constants.VIDEO_EXTS.includes(extname))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.isAnimatedThumb = extname => {
|
||||||
|
extname = extname.toLowerCase()
|
||||||
|
return (config.uploads.generateThumbs.animated && Constants.ANIMATED_EXTS.includes(extname))
|
||||||
|
}
|
||||||
|
|
||||||
// Expand if necessary (should be case-insensitive)
|
// Expand if necessary (should be case-insensitive)
|
||||||
const extPreserves = [
|
const extPreserves = [
|
||||||
/\.tar\.\w+/i // tarballs
|
/\.tar\.\w+/i // tarballs
|
||||||
@ -401,9 +406,7 @@ self.generateThumbs = async (name, extname, force) => {
|
|||||||
extname = extname.toLowerCase()
|
extname = extname.toLowerCase()
|
||||||
const thumbname = name.slice(0, -extname.length)
|
const thumbname = name.slice(0, -extname.length)
|
||||||
let thumbext = '.png'
|
let thumbext = '.png'
|
||||||
if (extname === '.gif' && config.uploads.generateThumbs.animated) {
|
if (self.isAnimatedThumb(extname)) thumbext = '.gif'
|
||||||
thumbext = '.gif'
|
|
||||||
}
|
|
||||||
|
|
||||||
const thumbfile = path.join(paths.thumbs, thumbname + thumbext)
|
const thumbfile = path.join(paths.thumbs, thumbname + thumbext)
|
||||||
|
|
||||||
|
@ -59,7 +59,9 @@ routes.get('/a/:identifier', async (req, res) => {
|
|||||||
|
|
||||||
file.extname = path.extname(file.name)
|
file.extname = path.extname(file.name)
|
||||||
if (utils.mayGenerateThumb(file.extname)) {
|
if (utils.mayGenerateThumb(file.extname)) {
|
||||||
file.thumb = `thumbs/${file.name.slice(0, -file.extname.length)}.png`
|
let thumbext = '.png'
|
||||||
|
if (utils.isAnimatedThumb(file.extname)) thumbext = '.gif'
|
||||||
|
file.thumb = `thumbs/${file.name.slice(0, -file.extname.length)}${thumbext}`
|
||||||
// If thumbnail for album is still not set, set it to current file's full URL.
|
// If thumbnail for album is still not set, set it to current file's full URL.
|
||||||
// A potential improvement would be to let the user set a specific image as an album cover.
|
// A potential improvement would be to let the user set a specific image as an album cover.
|
||||||
if (!album.thumb) album.thumb = file.name
|
if (!album.thumb) album.thumb = file.name
|
||||||
|
Loading…
Reference in New Issue
Block a user