mirror of
https://github.com/plankanban/planka.git
synced 2025-07-23 15:19:44 +02:00
parent
f20a3d50f5
commit
97f4c0ab0d
27 changed files with 2180 additions and 702 deletions
|
@ -1,6 +1,3 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const Errors = {
|
||||
ATTACHMENT_NOT_FOUND: {
|
||||
attachmentNotFound: 'Attachment not found',
|
||||
|
@ -46,20 +43,20 @@ module.exports = {
|
|||
throw Errors.ATTACHMENT_NOT_FOUND;
|
||||
}
|
||||
|
||||
const filePath = path.join(
|
||||
sails.config.custom.attachmentsPath,
|
||||
attachment.dirname,
|
||||
'thumbnails',
|
||||
`cover-256.${attachment.image.thumbnailsExtension}`,
|
||||
);
|
||||
const fileManager = sails.hooks['file-manager'].getInstance();
|
||||
|
||||
if (!fs.existsSync(filePath)) {
|
||||
let readStream;
|
||||
try {
|
||||
readStream = await fileManager.read(
|
||||
`${sails.config.custom.attachmentsPathSegment}/${attachment.dirname}/thumbnails/cover-256.${attachment.image.thumbnailsExtension}`,
|
||||
);
|
||||
} catch (error) {
|
||||
throw Errors.ATTACHMENT_NOT_FOUND;
|
||||
}
|
||||
|
||||
this.res.type('image/jpeg');
|
||||
this.res.set('Cache-Control', 'private, max-age=900'); // TODO: move to config
|
||||
|
||||
return exits.success(fs.createReadStream(filePath));
|
||||
return exits.success(readStream);
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue