Use `saveURLAsFile`

pull/1/head
Daniel Gasienica 7 years ago
parent 394d2f0bff
commit 21db2e7182

@ -179,6 +179,7 @@
saveFile() { saveFile() {
Signal.Types.AttachmentTS.save({ Signal.Types.AttachmentTS.save({
attachment: this.model, attachment: this.model,
document,
timestamp: this.timestamp, timestamp: this.timestamp,
}); });
}, },

@ -5,6 +5,7 @@ import is from '@sindresorhus/is';
import moment from 'moment'; import moment from 'moment';
import * as GoogleChrome from '../util/GoogleChrome'; import * as GoogleChrome from '../util/GoogleChrome';
import { saveURLAsFile } from '../util/saveURLAsFile';
import { arrayBufferToObjectURL } from '../util/arrayBufferToObjectURL'; import { arrayBufferToObjectURL } from '../util/arrayBufferToObjectURL';
import { MIMEType } from './MIME'; import { MIMEType } from './MIME';
@ -41,19 +42,19 @@ export const isVisualMedia = (attachment: Attachment): boolean => {
export const save = ({ export const save = ({
attachment, attachment,
document,
timestamp, timestamp,
}: { }: {
attachment: Attachment; attachment: Attachment;
document: Document;
timestamp?: number; timestamp?: number;
}): void => { }): void => {
const url = arrayBufferToObjectURL({ const url = arrayBufferToObjectURL({
data: attachment.data, data: attachment.data,
type: SAVE_CONTENT_TYPE, type: SAVE_CONTENT_TYPE,
}); });
const anchorElement = document.createElement('a'); const filename = getSuggestedFilename({ attachment, timestamp });
anchorElement.href = url; saveURLAsFile({ url, filename, document });
anchorElement.download = getSuggestedFilename({ attachment, timestamp });
anchorElement.click();
URL.revokeObjectURL(url); URL.revokeObjectURL(url);
}; };

Loading…
Cancel
Save