Save attachments with macOS quarantine attribute

* Attachments: Always save file to downloads directory, show toast
* Add new build:dev command for casual builds
This commit is contained in:
Scott Nonnenberg 2020-01-09 11:57:43 -08:00 committed by Ken Powers
parent 65befde0fa
commit 1bf9ca7233
11 changed files with 202 additions and 52 deletions

View file

@ -3,8 +3,6 @@ import moment from 'moment';
import { isNumber, padStart } from 'lodash';
import * as MIME from './MIME';
import { arrayBufferToObjectURL } from '../util/arrayBufferToObjectURL';
import { saveURLAsFile } from '../util/saveURLAsFile';
import { SignalService } from '../protobuf';
import {
isImageTypeSupported,
@ -326,31 +324,37 @@ export const isVoiceMessage = (attachment: Attachment): boolean => {
return false;
};
export const save = ({
export const save = async ({
attachment,
document,
index,
getAbsolutePath,
readAttachmentData,
writeToDownloads,
timestamp,
}: {
attachment: Attachment;
document: Document;
index: number;
getAbsolutePath: (relativePath: string) => string;
readAttachmentData: (relativePath: string) => Promise<ArrayBuffer>;
writeToDownloads: (options: {
data: ArrayBuffer;
name: string;
}) => Promise<{ name: string; fullPath: string }>;
timestamp?: number;
}): void => {
const isObjectURLRequired = is.undefined(attachment.path);
const url = !is.undefined(attachment.path)
? getAbsolutePath(attachment.path)
: arrayBufferToObjectURL({
data: attachment.data,
type: MIME.APPLICATION_OCTET_STREAM,
});
const filename = getSuggestedFilename({ attachment, timestamp, index });
saveURLAsFile({ url, filename, document });
if (isObjectURLRequired) {
URL.revokeObjectURL(url);
}): Promise<string> => {
if (!attachment.path && !attachment.data) {
throw new Error('Attachment had neither path nor data');
}
const data = attachment.path
? await readAttachmentData(attachment.path)
: attachment.data;
const name = getSuggestedFilename({ attachment, timestamp, index });
const { name: savedFilename } = await writeToDownloads({
data,
name,
});
return savedFilename;
};
export const getSuggestedFilename = ({

View file

@ -1135,7 +1135,7 @@
"rule": "jQuery-html(",
"path": "js/views/toast_view.js",
"line": " this.$el.html(",
"lineNumber": 21,
"lineNumber": 22,
"reasonCategory": "usageTrusted",
"updated": "2018-09-15T00:38:04.183Z"
},
@ -1143,7 +1143,7 @@
"rule": "jQuery-appendTo(",
"path": "js/views/toast_view.js",
"line": " toast.$el.appendTo(el);",
"lineNumber": 34,
"lineNumber": 36,
"reasonCategory": "usageTrusted",
"updated": "2019-11-06T19:56:38.557Z",
"reasonDetail": "Protected from arbitrary input"

View file

@ -1,17 +0,0 @@
/**
* @prettier
*/
export const saveURLAsFile = ({
filename,
url,
document,
}: {
filename: string;
url: string;
document: Document;
}): void => {
const anchorElement = document.createElement('a');
anchorElement.href = url;
anchorElement.download = filename;
anchorElement.click();
};