put thumbs in a folder, tests would have been nice to have cos this will probably cause regressions, heh... reference #307

merge-requests/218/head
Thomas Lynch 4 years ago
parent 02fad13518
commit d31a60e69a
  1. 2
      gulp/res/js/hideimages.js
  2. 2
      helpers/files/audiothumbnail.js
  3. 2
      helpers/files/deletepostfiles.js
  4. 4
      helpers/files/imagethumbnail.js
  5. 6
      helpers/files/videothumbnail.js
  6. 4
      models/forms/makepost.js
  7. 2
      package.json
  8. 2
      schedules/prune.js
  9. 2
      views/mixins/catalogtile.pug
  10. 4
      views/mixins/post.pug

@ -28,7 +28,7 @@ const handleHiddenImages = (e) => {
const hasHiddenImages = e.detail.json.files.forEach(f => { const hasHiddenImages = e.detail.json.files.forEach(f => {
let hideFilename = '/file/'; let hideFilename = '/file/';
if (f.hasThumb) { if (f.hasThumb) {
hideFilename += `thumb-${f.hash}${f.thumbextension}` hideFilename += `thumb/${f.hash}${f.thumbextension}`
} else { } else {
hideFilename += f.filename; hideFilename += f.filename;
} }

@ -16,7 +16,7 @@ module.exports = (file) => {
filter: 'showwavespic', filter: 'showwavespic',
options: { split_channels: 1, s: `${thumbSize}x${thumbSize}` } options: { split_channels: 1, s: `${thumbSize}x${thumbSize}` }
}]) }])
.save(`${uploadDirectory}/file/thumb-${file.hash}${file.thumbextension}`); .save(`${uploadDirectory}/file/thumb/${file.hash}${file.thumbextension}`);
}); });
}; };

@ -9,7 +9,7 @@ module.exports = (files) => {
return Promise.all(files.map(async file => { return Promise.all(files.map(async file => {
return Promise.all([ return Promise.all([
remove(`${uploadDirectory}/file/${file.filename}`), remove(`${uploadDirectory}/file/${file.filename}`),
file.hasThumb ? remove(`${uploadDirectory}/file/thumb-${file.hash}${file.thumbextension}`) : void 0, file.hasThumb ? remove(`${uploadDirectory}/file/thumb/${file.hash}${file.thumbextension}`) : void 0,
]).catch(e => console.error); ]).catch(e => console.error);
})); }));

@ -21,7 +21,7 @@ module.exports = (file, firstFrameOnly=true) => {
return reject(err); return reject(err);
}) })
.complexFilter(complexFilters) .complexFilter(complexFilters)
.save(`${uploadDirectory}/file/thumb-${file.hash}${file.thumbextension}`); .save(`${uploadDirectory}/file/thumb/${file.hash}${file.thumbextension}`);
} else { } else {
//[0] for first frame (gifs, etc) //[0] for first frame (gifs, etc)
const thumbnailing = gm(`${uploadDirectory}/file/${file.filename}${firstFrameOnly ? '[0]' : ''}`); const thumbnailing = gm(`${uploadDirectory}/file/${file.filename}${firstFrameOnly ? '[0]' : ''}`);
@ -30,7 +30,7 @@ module.exports = (file, firstFrameOnly=true) => {
thumbnailing.coalesce(); thumbnailing.coalesce();
} }
thumbnailing.resize(Math.min(thumbSize, file.geometry.width), Math.min(thumbSize, file.geometry.height)) thumbnailing.resize(Math.min(thumbSize, file.geometry.width), Math.min(thumbSize, file.geometry.height))
.write(`${uploadDirectory}/file/thumb-${file.hash}${file.thumbextension}`, function (err) { .write(`${uploadDirectory}/file/thumb/${file.hash}${file.thumbextension}`, function (err) {
if (err) { if (err) {
return reject(err); return reject(err);
} }

@ -20,14 +20,14 @@ module.exports = (file, geometry, timestamp) => {
.outputOptions([ .outputOptions([
`-vf scale=${geometry.width > geometry.height ? thumbSize + ':-2' : '-2:' + thumbSize}` `-vf scale=${geometry.width > geometry.height ? thumbSize + ':-2' : '-2:' + thumbSize}`
]) ])
.output(`${uploadDirectory}/file/thumb-${file.hash}${file.thumbextension}`) .output(`${uploadDirectory}/file/thumb/${file.hash}${file.thumbextension}`)
.run(); .run();
} else { } else {
command.screenshots({ command.screenshots({
timestamps: [timestamp], timestamps: [timestamp],
count: 1, count: 1,
filename: `thumb-${file.hash}${file.thumbextension}`, filename: `${file.hash}${file.thumbextension}`,
folder: `${uploadDirectory}/file/`, folder: `${uploadDirectory}/file/thumb/`,
size: geometry.width > geometry.height ? `${thumbSize}x?` : `?x${thumbSize}` size: geometry.width > geometry.height ? `${thumbSize}x?` : `?x${thumbSize}`
//keep aspect ratio, but also making sure taller/wider thumbs dont exceed thumbSize in either dimension //keep aspect ratio, but also making sure taller/wider thumbs dont exceed thumbSize in either dimension
}); });

@ -263,7 +263,7 @@ ${res.locals.numFiles > 0 ? req.files.file.map(f => f.name+'|'+(f.phash || '')).
processedFile.attachment = true; processedFile.attachment = true;
await saveFull(); await saveFull();
} else { } else {
const existsThumb = await pathExists(`${uploadDirectory}/file/thumb-${processedFile.hash}${processedFile.thumbextension}`); const existsThumb = await pathExists(`${uploadDirectory}/file/thumb/${processedFile.hash}${processedFile.thumbextension}`);
switch (type) { switch (type) {
case 'image': { case 'image': {
processedFile.thumbextension = thumbExtension; processedFile.thumbextension = thumbExtension;
@ -328,7 +328,7 @@ ${res.locals.numFiles > 0 ? req.files.file.map(f => f.name+'|'+(f.phash || '')).
await videoThumbnail(processedFile, processedFile.geometry, videoThumbPercentage+'%'); await videoThumbnail(processedFile, processedFile.geometry, videoThumbPercentage+'%');
let videoThumbStat = null; let videoThumbStat = null;
try { try {
videoThumbStat = await fsStat(`${uploadDirectory}/file/thumb-${processedFile.hash}${processedFile.thumbextension}`); videoThumbStat = await fsStat(`${uploadDirectory}/file/thumb/${processedFile.hash}${processedFile.thumbextension}`);
} catch (err) { /*ENOENT, the thumb failed to create. No need to handle this.*/ } } catch (err) { /*ENOENT, the thumb failed to create. No need to handle this.*/ }
if (!videoThumbStat || videoThumbStat.size === 0) { if (!videoThumbStat || videoThumbStat.size === 0) {
await videoThumbnail(processedFile, processedFile.geometry, 0); await videoThumbnail(processedFile, processedFile.geometry, 0);

@ -1,7 +1,7 @@
{ {
"name": "jschan", "name": "jschan",
"version": "0.0.1", "version": "0.0.1",
"migrateVersion": "0.0.19", "migrateVersion": "0.0.20",
"description": "", "description": "",
"main": "server.js", "main": "server.js",
"dependencies": { "dependencies": {

@ -28,7 +28,7 @@ module.exports = async(fileNames) => {
return Promise.all( return Promise.all(
[remove(`${uploadDirectory}/file/${file._id}`)] [remove(`${uploadDirectory}/file/${file._id}`)]
.concat(file.exts ? file.exts.filter(ext => ext).map(ext => { .concat(file.exts ? file.exts.filter(ext => ext).map(ext => {
remove(`${uploadDirectory}/file/thumb-${file._id.split('.')[0]}${ext}`) remove(`${uploadDirectory}/file/thumb/${file._id.split('.')[0]}${ext}`)
}) : []) }) : [])
) )
})); }));

@ -42,7 +42,7 @@ mixin catalogtile(post, index, overboard=false)
if post.spoiler || file.spoiler if post.spoiler || file.spoiler
div.spoilerimg.catalog-thumb div.spoilerimg.catalog-thumb
else if file.hasThumb else if file.hasThumb
img.catalog-thumb(src=`/file/thumb-${file.hash}${file.thumbextension}` width=file.geometry.thumbwidth height=file.geometry.thumbheight loading='lazy') img.catalog-thumb(src=`/file/thumb/${file.hash}${file.thumbextension}` width=file.geometry.thumbwidth height=file.geometry.thumbheight loading='lazy')
else if file.attachment else if file.attachment
div.attachmentimg.catalog-thumb(data-mimetype=file.mimetype) div.attachmentimg.catalog-thumb(data-mimetype=file.mimetype)
else if file.mimetype.startsWith('audio') else if file.mimetype.startsWith('audio')

@ -75,7 +75,7 @@ mixin post(post, truncate, manage=false, globalmanage=false, ban=false, overboar
if file.hasThumb && !(post.spoiler || file.spoiler) if file.hasThumb && !(post.spoiler || file.spoiler)
span.jsonly span.jsonly
b [ b [
a.dummy-link.hide-image(data-src=`/file/thumb-${file.hash}${file.thumbextension}`) Hide a.dummy-link.hide-image(data-src=`/file/thumb/${file.hash}${file.thumbextension}`) Hide
b ] b ]
span span
| (#{file.sizeString} | (#{file.sizeString}
@ -90,7 +90,7 @@ mixin post(post, truncate, manage=false, globalmanage=false, ban=false, overboar
if post.spoiler || file.spoiler if post.spoiler || file.spoiler
div.spoilerimg.file-thumb div.spoilerimg.file-thumb
else if file.hasThumb else if file.hasThumb
img.file-thumb(src=`/file/thumb-${file.hash}${file.thumbextension}` height=file.geometry.thumbheight width=file.geometry.thumbwidth loading='lazy') img.file-thumb(src=`/file/thumb/${file.hash}${file.thumbextension}` height=file.geometry.thumbheight width=file.geometry.thumbwidth loading='lazy')
else if file.attachment else if file.attachment
div.attachmentimg.file-thumb(data-mimetype=file.mimetype) div.attachmentimg.file-thumb(data-mimetype=file.mimetype)
else if type === 'audio' else if type === 'audio'

Loading…
Cancel
Save