On attachment save include date, include album index
This commit is contained in:
parent
0b0dfbce9d
commit
bf904ddd12
4 changed files with 29 additions and 6 deletions
|
@ -1294,8 +1294,9 @@
|
|||
Signal.Types.Attachment.save({
|
||||
attachment: options.attachment,
|
||||
document,
|
||||
index: options.index + 1,
|
||||
getAbsolutePath: getAbsoluteAttachmentPath,
|
||||
timestamp: options.message.received_at,
|
||||
timestamp: options.message.get('sent_at'),
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ interface Props {
|
|||
i18n: Localizer;
|
||||
media: Array<MediaItemType>;
|
||||
onSave?: (
|
||||
{ attachment, message }: { attachment: AttachmentType; message: Message }
|
||||
options: { attachment: AttachmentType; message: Message; index: number }
|
||||
) => void;
|
||||
selectedIndex: number;
|
||||
}
|
||||
|
@ -98,8 +98,8 @@ export class LightboxGallery extends React.Component<Props, State> {
|
|||
|
||||
const { selectedIndex } = this.state;
|
||||
const mediaItem = media[selectedIndex];
|
||||
const { attachment, message } = mediaItem;
|
||||
const { attachment, message, index } = mediaItem;
|
||||
|
||||
onSave({ attachment, message });
|
||||
onSave({ attachment, message, index });
|
||||
};
|
||||
}
|
||||
|
|
|
@ -53,6 +53,22 @@ describe('Attachment', () => {
|
|||
assert.strictEqual(actual, expected);
|
||||
});
|
||||
});
|
||||
context('for attachment with index', () => {
|
||||
it('should generate a filename based on timestamp', () => {
|
||||
const attachment: Attachment.Attachment = {
|
||||
data: stringToArrayBuffer('foo'),
|
||||
contentType: MIME.VIDEO_QUICKTIME,
|
||||
};
|
||||
const timestamp = new Date(new Date(0).getTimezoneOffset() * 60 * 1000);
|
||||
const actual = Attachment.getSuggestedFilename({
|
||||
attachment,
|
||||
timestamp,
|
||||
index: 3,
|
||||
});
|
||||
const expected = 'signal-attachment-1970-01-01-000000_003.mov';
|
||||
assert.strictEqual(actual, expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isVisualMedia', () => {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import is from '@sindresorhus/is';
|
||||
import moment from 'moment';
|
||||
import { padStart } from 'lodash';
|
||||
|
||||
import * as MIME from './MIME';
|
||||
import { arrayBufferToObjectURL } from '../util/arrayBufferToObjectURL';
|
||||
|
@ -82,11 +83,13 @@ export const isVoiceMessage = (attachment: Attachment): boolean => {
|
|||
export const save = ({
|
||||
attachment,
|
||||
document,
|
||||
index,
|
||||
getAbsolutePath,
|
||||
timestamp,
|
||||
}: {
|
||||
attachment: Attachment;
|
||||
document: Document;
|
||||
index: number;
|
||||
getAbsolutePath: (relativePath: string) => string;
|
||||
timestamp?: number;
|
||||
}): void => {
|
||||
|
@ -97,7 +100,7 @@ export const save = ({
|
|||
data: attachment.data,
|
||||
type: MIME.APPLICATION_OCTET_STREAM,
|
||||
});
|
||||
const filename = getSuggestedFilename({ attachment, timestamp });
|
||||
const filename = getSuggestedFilename({ attachment, timestamp, index });
|
||||
saveURLAsFile({ url, filename, document });
|
||||
if (isObjectURLRequired) {
|
||||
URL.revokeObjectURL(url);
|
||||
|
@ -107,9 +110,11 @@ export const save = ({
|
|||
export const getSuggestedFilename = ({
|
||||
attachment,
|
||||
timestamp,
|
||||
index,
|
||||
}: {
|
||||
attachment: Attachment;
|
||||
timestamp?: number | Date;
|
||||
index?: number;
|
||||
}): string => {
|
||||
if (attachment.fileName) {
|
||||
return attachment.fileName;
|
||||
|
@ -121,8 +126,9 @@ export const getSuggestedFilename = ({
|
|||
: '';
|
||||
const fileType = getFileExtension(attachment);
|
||||
const extension = fileType ? `.${fileType}` : '';
|
||||
const indexSuffix = index ? `_${padStart(index.toString(), 3, '0')}` : '';
|
||||
|
||||
return `${prefix}${suffix}${extension}`;
|
||||
return `${prefix}${suffix}${indexSuffix}${extension}`;
|
||||
};
|
||||
|
||||
export const getFileExtension = (attachment: Attachment): string | null => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue