diff --git a/db/files.js b/db/files.js index 9f07dff5..81ebc0a3 100644 --- a/db/files.js +++ b/db/files.js @@ -16,6 +16,9 @@ module.exports = { '$inc': { 'count': 1 }, + '$addToSet': {//save list of thumb exts incase config is changed to track old exts + 'exts': file.thumbextension, + }, '$setOnInsert': { 'size': file.size } diff --git a/gulp/res/js/post.js b/gulp/res/js/post.js index afff16c9..cb03666b 100644 --- a/gulp/res/js/post.js +++ b/gulp/res/js/post.js @@ -83,7 +83,7 @@ pug_html = pug_html + "\u003Cimg class=\"file-thumb\" src=\"\u002Fimg\u002Fspoil } else if (file.hasThumb) { -pug_html = pug_html + "\u003Cimg" + (" class=\"file-thumb\""+pug_attr("src", `/img/thumb-${file.hash}.jpg`, true, false)+pug_attr("height", file.geometry.thumbheight, true, false)+pug_attr("width", file.geometry.thumbwidth, true, false)) + "\u002F\u003E"; +pug_html = pug_html + "\u003Cimg" + (" class=\"file-thumb\""+pug_attr("src", `/img/thumb-${file.hash}${file.thumbextension}`, true, false)+pug_attr("height", file.geometry.thumbheight, true, false)+pug_attr("width", file.geometry.thumbwidth, true, false)) + "\u002F\u003E"; } else { pug_html = pug_html + "\u003Cimg" + (" class=\"file-thumb\""+pug_attr("src", `/img/${file.filename}`, true, false)+pug_attr("height", file.geometry.height, true, false)+pug_attr("width", file.geometry.width, true, false)) + "\u002F\u003E"; @@ -105,7 +105,7 @@ pug_html = pug_html + "\u003Cimg class=\"file-thumb\" src=\"\u002Fimg\u002Fspoil } else if (file.hasThumb) { -pug_html = pug_html + "\u003Cimg" + (" class=\"file-thumb\""+pug_attr("src", `/img/thumb-${file.hash}.jpg`, true, false)+pug_attr("height", file.geometry.thumbheight, true, false)+pug_attr("width", file.geometry.thumbwidth, true, false)) + "\u002F\u003E"; +pug_html = pug_html + "\u003Cimg" + (" class=\"file-thumb\""+pug_attr("src", `/img/thumb-${file.hash}${file.thumbextension}`, true, false)+pug_attr("height", file.geometry.thumbheight, true, false)+pug_attr("width", file.geometry.thumbwidth, true, false)) + "\u002F\u003E"; } else { pug_html = pug_html + "\u003Cimg" + (" class=\"file-thumb\""+pug_attr("src", `/img/${file.filename}`, true, false)+pug_attr("height", file.geometry.height, true, false)+pug_attr("width", file.geometry.width, true, false)) + "\u002F\u003E"; diff --git a/helpers/files/deletepostfiles.js b/helpers/files/deletepostfiles.js index 39b04347..2c16ff8d 100644 --- a/helpers/files/deletepostfiles.js +++ b/helpers/files/deletepostfiles.js @@ -7,10 +7,12 @@ module.exports = (files) => { //delete all the files and thumbs return Promise.all(files.map(async file => { - return Promise.all([ - remove(`${uploadDirectory}/img/${file.filename}`), - remove(`${uploadDirectory}/img/thumb-${file.hash}.jpg`) - ]).catch(e => console.error) + return Promise.all( + [remove(`${uploadDirectory}/img/${file.filename}`)] + .concat(file.exts.map(ext => { + remove(`${uploadDirectory}/img/thumb-${file.hash}${file.thumbextension}`) + })) + ).catch(e => console.error) })); } diff --git a/helpers/files/imagethumbnail.js b/helpers/files/imagethumbnail.js index d05b71b9..268dc2ac 100644 --- a/helpers/files/imagethumbnail.js +++ b/helpers/files/imagethumbnail.js @@ -5,9 +5,9 @@ const gm = require('gm') module.exports = (file) => { return new Promise((resolve, reject) => { - gm(`${uploadDirectory}/img/${file.filename}`) + gm(`${uploadDirectory}/img/${file.filename}[0]`) //0 for first gif frame .resize(128, 128) - .write(`${uploadDirectory}/img/thumb-${file.hash}.jpg`, function (err) { + .write(`${uploadDirectory}/img/thumb-${file.hash}${configs.thumbExtension}`, function (err) { if (err) { return reject(err); } diff --git a/helpers/files/videothumbnail.js b/helpers/files/videothumbnail.js index 59f13c24..e492dfb6 100644 --- a/helpers/files/videothumbnail.js +++ b/helpers/files/videothumbnail.js @@ -12,7 +12,7 @@ module.exports = (file, geometry) => { .screenshots({ timestamps: ['1%'],//1% should remedy black first frames or fade-ins count: 1, - filename: `thumb-${file.hash}.jpg`, + filename: `thumb-${file.hash}${thumbExtension}`, folder: `${uploadDirectory}/img/`, size: geometry.width > geometry.height ? '128x?' : '?x128' //keep aspect ratio, but also making sure taller/wider thumbs dont exceed 128 in either dimension diff --git a/models/forms/makepost.js b/models/forms/makepost.js index 75abad8e..84186ff7 100644 --- a/models/forms/makepost.js +++ b/models/forms/makepost.js @@ -27,7 +27,7 @@ const path = require('path') , msTime = require(__dirname+'/../../helpers/mstime.js') , deletePosts = require(__dirname+'/deletepost.js') , spamCheck = require(__dirname+'/../../helpers/checks/spamcheck.js') - , { postPasswordSecret } = require(__dirname+'/../../configs/main.json') + , { thumbExtension, postPasswordSecret } = require(__dirname+'/../../configs/main.json') , buildQueue = require(__dirname+'/../../queue.js') , dynamicResponse = require(__dirname+'/../../helpers/dynamic.js') , { buildThread } = require(__dirname+'/../../helpers/tasks.js'); @@ -160,13 +160,15 @@ module.exports = async (req, res, next) => { originalFilename: file.name, mimetype: file.mimetype, size: file.size, + extension, + thumbextension: thumbExtension, }; await Files.increment(processedFile); //check if already exists const existsFull = await pathExists(`${uploadDirectory}/img/${processedFile.filename}`); - const existsThumb = await pathExists(`${uploadDirectory}/img/thumb-${processedFile.hash}.jpg`); + const existsThumb = await pathExists(`${uploadDirectory}/img/thumb-${processedFile.hash}${processedFile.thumbextension}`); //handle video/image ffmpeg or graphicsmagick switch (processedFile.mimetype.split('/')[0]) { @@ -199,7 +201,7 @@ module.exports = async (req, res, next) => { }); } processedFile.duration = videoData.format.duration; - processedFile.durationString = new Date(videoData.format.duration*1000).toLocaleString('en-US', {hour12:false}).split(' ')[1].replace(/^00:/, ''); + processedFile.durationString = new Date(videoData.format.duration*1000).toLocaleString('en-US', {hour12:false}).split(' ')[1].replace(/^00:/, '');//break for over 24h video processedFile.geometry = {width: videoData.streams[0].coded_width, height: videoData.streams[0].coded_height} // object with width and height pixels processedFile.sizeString = formatSize(processedFile.size) // 123 Ki string processedFile.geometryString = `${processedFile.geometry.width}x${processedFile.geometry.height}` // 123 x 123 string diff --git a/schedules/index.js b/schedules/index.js index 975e6ca2..ba980261 100644 --- a/schedules/index.js +++ b/schedules/index.js @@ -24,7 +24,7 @@ const msTime = require(__dirname+'/../helpers/mstime.js') //update webring if (enableWebring) { const updateWebring = require(__dirname+'/webring.js'); - updateWebring().catch(e => console.error); +// updateWebring().catch(e => console.error); setInterval(() => { updateWebring().catch(e => console.error); }, msTime.hour); diff --git a/schedules/prune.js b/schedules/prune.js index cf3a3341..4b93ee69 100644 --- a/schedules/prune.js +++ b/schedules/prune.js @@ -15,18 +15,18 @@ module.exports = async() => { 'count': 0, 'size': 0 } - }).toArray().then(res => { - return res.map(x => x._id); - }); + }).toArray() await Files.db.removeMany({ 'count': { '$lte': 0 } }); - await Promise.all(files.map(async filename => { - return Promise.all([ - remove(`${uploadDirectory}/img/${filename}`), - remove(`${uploadDirectory}/img/thumb-${filename.split('.')[0]}.jpg`) - ]) + await Promise.all(files.map(async file => { + return Promise.all( + [remove(`${uploadDirectory}/img/${file._id}`)] + .concat(file.exts.map(ext => { + remove(`${uploadDirectory}/img/thumb-${file._id.split('.')[0]}${ext}`) + })) + ) })); } diff --git a/views/mixins/catalogtile.pug b/views/mixins/catalogtile.pug index 8689e1f1..4361d9c0 100644 --- a/views/mixins/catalogtile.pug +++ b/views/mixins/catalogtile.pug @@ -17,7 +17,7 @@ mixin catalogtile(board, post, index) img.catalog-thumb(src='/img/spoiler.png' width='64' height='64') else if post.files[0].hasThumb - img.catalog-thumb(src=`/img/thumb-${post.files[0].hash}.jpg` width='64' height='64') + img.catalog-thumb(src=`/img/thumb-${post.files[0].hash}${post.files[0].thumbextension}` width='64' height='64') else img.catalog-thumb(src=`/img/${post.files[0].filename}` width='64' height='64') if post.message diff --git a/views/mixins/post.pug b/views/mixins/post.pug index dc6f6f36..3a3cb816 100644 --- a/views/mixins/post.pug +++ b/views/mixins/post.pug @@ -61,7 +61,7 @@ mixin post(post, truncate, manage=false, globalmanage=false, ban=false) if post.spoiler img.file-thumb(src='/img/spoiler.png' width='128' height='128') else if file.hasThumb - img.file-thumb(src=`/img/thumb-${file.hash}.jpg` height=file.geometry.thumbheight width=file.geometry.thumbwidth) + img.file-thumb(src=`/img/thumb-${file.hash}${file.thumbextension}` height=file.geometry.thumbheight width=file.geometry.thumbwidth) else img.file-thumb(src=`/img/${file.filename}` height=file.geometry.height width=file.geometry.width) - let truncatedMessage = post.message; diff --git a/views/pages/thread.pug b/views/pages/thread.pug index 8b50021d..64462182 100644 --- a/views/pages/thread.pug +++ b/views/pages/thread.pug @@ -14,7 +14,7 @@ block head if thread.spoiler meta(property='og:image', content='/img/spoiler.png') else if thread.files[0].hasThumb === true - meta(property='og:image', content=`/img/thumb-${thread.files[0].hash}.jpg`) + meta(property='og:image', content=`/img/thumb-${thread.files[0].hash}${thread.files[0].thumbextension}`) else meta(property='og:image', content=`/img/${thread.files[0].filename}`)