Don't use original filenames when saving multi-attachment messages
This commit is contained in:
parent
fde917c983
commit
46428b5af6
2 changed files with 38 additions and 3 deletions
|
@ -62,7 +62,7 @@ describe('Attachment', () => {
|
|||
});
|
||||
});
|
||||
context('for attachment with index', () => {
|
||||
it('should use filename if provided', () => {
|
||||
it('should use filename if it is provided', () => {
|
||||
const attachment: Attachment.AttachmentType = fakeAttachment({
|
||||
fileName: 'funny-cat.mov',
|
||||
data: Bytes.fromString('foo'),
|
||||
|
@ -74,12 +74,47 @@ describe('Attachment', () => {
|
|||
const actual = Attachment.getSuggestedFilename({
|
||||
attachment,
|
||||
timestamp,
|
||||
index: 3,
|
||||
});
|
||||
const expected = 'funny-cat.mov';
|
||||
assert.strictEqual(actual, expected);
|
||||
});
|
||||
|
||||
it('should use filename if it is provided and index is 1', () => {
|
||||
const attachment: Attachment.AttachmentType = fakeAttachment({
|
||||
fileName: 'funny-cat.mov',
|
||||
data: Bytes.fromString('foo'),
|
||||
contentType: MIME.VIDEO_QUICKTIME,
|
||||
});
|
||||
const timestamp = new Date(
|
||||
DAY + new Date(DAY).getTimezoneOffset() * 60 * 1000
|
||||
);
|
||||
const actual = Attachment.getSuggestedFilename({
|
||||
attachment,
|
||||
timestamp,
|
||||
index: 1,
|
||||
});
|
||||
const expected = 'funny-cat.mov';
|
||||
assert.strictEqual(actual, expected);
|
||||
});
|
||||
|
||||
it('should use filename if it is provided and index is >1', () => {
|
||||
const attachment: Attachment.AttachmentType = fakeAttachment({
|
||||
fileName: 'funny-cat.mov',
|
||||
data: Bytes.fromString('foo'),
|
||||
contentType: MIME.VIDEO_QUICKTIME,
|
||||
});
|
||||
const timestamp = new Date(
|
||||
DAY + new Date(DAY).getTimezoneOffset() * 60 * 1000
|
||||
);
|
||||
const actual = Attachment.getSuggestedFilename({
|
||||
attachment,
|
||||
timestamp,
|
||||
index: 2,
|
||||
});
|
||||
const expected = 'signal-1970-01-02-000000_002.mov';
|
||||
assert.strictEqual(actual, expected);
|
||||
});
|
||||
|
||||
it('should use provided index if > 1 and filename not provided', () => {
|
||||
const attachment: Attachment.AttachmentType = fakeAttachment({
|
||||
data: Bytes.fromString('foo'),
|
||||
|
|
|
@ -1001,7 +1001,7 @@ export const getSuggestedFilename = ({
|
|||
index?: number;
|
||||
}): string => {
|
||||
const { fileName } = attachment;
|
||||
if (fileName) {
|
||||
if (fileName && (!isNumber(index) || index === 1)) {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue