mirror of
https://github.com/plankanban/planka.git
synced 2026-03-01 11:21:46 +03:00
fix: Enhance response headers for file attachments
This commit is contained in:
@@ -77,16 +77,32 @@ module.exports = {
|
||||
const fileManager = sails.hooks['file-manager'].getInstance();
|
||||
|
||||
let readStream;
|
||||
let headers;
|
||||
|
||||
try {
|
||||
readStream = await fileManager.read(
|
||||
[readStream, headers] = await fileManager.read(
|
||||
`${sails.config.custom.attachmentsPathSegment}/${attachment.data.uploadedFileId}/thumbnails/${inputs.fileName}.${inputs.fileExtension}`,
|
||||
{
|
||||
withHeaders: true,
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
throw Errors.FILE_ATTACHMENT_NOT_FOUND;
|
||||
}
|
||||
|
||||
this.res.type(attachment.data.mimeType);
|
||||
this.res.set('Cache-Control', 'private, max-age=86400, no-transform'); // TODO: move to config
|
||||
this.res.set({
|
||||
...headers,
|
||||
'Content-Type': attachment.data.mimeType,
|
||||
'Cache-Control': 'private, max-age=86400, no-transform', // TODO: move to config
|
||||
});
|
||||
|
||||
readStream.on('error', () => {
|
||||
if (this.res.headersSent) {
|
||||
this.res.destroy();
|
||||
} else {
|
||||
throw Errors.FILE_ATTACHMENT_NOT_FOUND;
|
||||
}
|
||||
});
|
||||
|
||||
return exits.success(readStream);
|
||||
},
|
||||
|
||||
@@ -70,21 +70,38 @@ module.exports = {
|
||||
const fileManager = sails.hooks['file-manager'].getInstance();
|
||||
|
||||
let readStream;
|
||||
let headers;
|
||||
|
||||
try {
|
||||
readStream = await fileManager.read(
|
||||
[readStream, headers] = await fileManager.read(
|
||||
`${sails.config.custom.attachmentsPathSegment}/${attachment.data.uploadedFileId}/${attachment.data.filename}`,
|
||||
{
|
||||
withHeaders: true,
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
throw Errors.FILE_ATTACHMENT_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (attachment.data.mimeType) {
|
||||
this.res.type(attachment.data.mimeType);
|
||||
headers['Content-Type'] = attachment.data.mimeType;
|
||||
}
|
||||
if (!INLINE_MIME_TYPES_SET.has(attachment.data.mimeType) && !attachment.data.image) {
|
||||
this.res.set('Content-Disposition', 'attachment');
|
||||
headers['Content-Disposition'] = 'attachment';
|
||||
}
|
||||
this.res.set('Cache-Control', 'private, max-age=86400, no-transform'); // TODO: move to config
|
||||
|
||||
this.res.set({
|
||||
...headers,
|
||||
'Cache-Control': 'private, max-age=86400, no-transform', // TODO: move to config
|
||||
});
|
||||
|
||||
readStream.on('error', () => {
|
||||
if (this.res.headersSent) {
|
||||
this.res.destroy();
|
||||
} else {
|
||||
throw Errors.FILE_ATTACHMENT_NOT_FOUND;
|
||||
}
|
||||
});
|
||||
|
||||
return exits.success(readStream);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user