file content-disposition
This commit is contained in:
parent
73ddec4ca7
commit
8af2d4e8cf
2 changed files with 11 additions and 2 deletions
|
|
@ -5,10 +5,10 @@ export enum AttachmentType {
|
||||||
File = 'file',
|
File = 'file',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const validImageExtensions = ['.jpg', '.png', '.jpeg', 'gif'];
|
export const validImageExtensions = ['.jpg', '.png', '.jpeg'];
|
||||||
export const MAX_AVATAR_SIZE = '5MB';
|
export const MAX_AVATAR_SIZE = '5MB';
|
||||||
|
|
||||||
export const InlineFileExtensions = [
|
export const inlineFileExtensions = [
|
||||||
'.jpg',
|
'.jpg',
|
||||||
'.png',
|
'.png',
|
||||||
'.jpeg',
|
'.jpeg',
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import {
|
||||||
import { getMimeType } from '../../common/helpers';
|
import { getMimeType } from '../../common/helpers';
|
||||||
import {
|
import {
|
||||||
AttachmentType,
|
AttachmentType,
|
||||||
|
inlineFileExtensions,
|
||||||
MAX_AVATAR_SIZE,
|
MAX_AVATAR_SIZE,
|
||||||
MAX_FILE_SIZE,
|
MAX_FILE_SIZE,
|
||||||
} from './attachment.constants';
|
} from './attachment.constants';
|
||||||
|
|
@ -177,6 +178,14 @@ export class AttachmentController {
|
||||||
'Content-Type': attachment.mimeType,
|
'Content-Type': attachment.mimeType,
|
||||||
'Cache-Control': 'public, max-age=3600',
|
'Cache-Control': 'public, max-age=3600',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!inlineFileExtensions.includes(attachment.fileExt)) {
|
||||||
|
res.header(
|
||||||
|
'Content-Disposition',
|
||||||
|
`attachment; filename="${attachment.fileName}"`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return res.send(fileStream);
|
return res.send(fileStream);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.error(err);
|
this.logger.error(err);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue