change thumbs to png and try handling dedupes when thumb format has been changed and file uploaded

merge-requests/208/head
fatchan 5 years ago
parent 08e93bdd2a
commit 93cd4c4d64
  1. 3
      db/files.js
  2. 4
      gulp/res/js/post.js
  3. 10
      helpers/files/deletepostfiles.js
  4. 4
      helpers/files/imagethumbnail.js
  5. 2
      helpers/files/videothumbnail.js
  6. 8
      models/forms/makepost.js
  7. 2
      schedules/index.js
  8. 16
      schedules/prune.js
  9. 2
      views/mixins/catalogtile.pug
  10. 2
      views/mixins/post.pug
  11. 2
      views/pages/thread.pug

@ -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
}

@ -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";

@ -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)
}));
}

@ -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);
}

@ -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

@ -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

@ -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);

@ -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}`)
}))
)
}));
}

@ -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

@ -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;

@ -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}`)

Loading…
Cancel
Save