Attachment-add flow: capture renamed filename, file type checks

This commit is contained in:
Scott Nonnenberg 2019-09-18 10:25:52 -07:00
parent 3719724337
commit 344e7e5e76

View file

@ -1179,7 +1179,7 @@
return; return;
} }
this.addAttachment(attachment); await this.addAttachment(attachment);
}, },
isSizeOkay(attachment) { isSizeOkay(attachment) {
@ -1256,29 +1256,37 @@
if (MIME.isJPEG(file.type)) { if (MIME.isJPEG(file.type)) {
const rotatedDataUrl = await window.autoOrientImage(file); const rotatedDataUrl = await window.autoOrientImage(file);
const rotatedBlob = VisualAttachment.dataURLToBlobSync(rotatedDataUrl); const rotatedBlob = VisualAttachment.dataURLToBlobSync(rotatedDataUrl);
const { contentType, file: resizedBlob } = await this.autoScale({ const {
contentType,
file: resizedBlob,
fileName,
} = await this.autoScale({
contentType: file.type, contentType: file.type,
rotatedBlob, fileName: file.name,
file: rotatedBlob,
}); });
const data = await await VisualAttachment.blobToArrayBuffer( const data = await await VisualAttachment.blobToArrayBuffer(
resizedBlob resizedBlob
); );
return { return {
fileName: file.name, fileName: fileName || file.name,
contentType, contentType,
data, data,
size: data.byteLength, size: data.byteLength,
}; };
} }
const { contentType, file: resizedBlob } = await this.autoScale({ const { contentType, file: resizedBlob, fileName } = await this.autoScale(
contentType: file.type, {
file, contentType: file.type,
}); fileName: file.name,
file,
}
);
const data = await await VisualAttachment.blobToArrayBuffer(resizedBlob); const data = await await VisualAttachment.blobToArrayBuffer(resizedBlob);
return { return {
fileName: file.name, fileName: fileName || file.name,
contentType, contentType,
data, data,
size: data.byteLength, size: data.byteLength,
@ -1286,7 +1294,7 @@
}, },
autoScale(attachment) { autoScale(attachment) {
const { contentType, file } = attachment; const { contentType, file, fileName } = attachment;
if ( if (
contentType.split('/')[0] !== 'image' || contentType.split('/')[0] !== 'image' ||
contentType === 'image/tiff' contentType === 'image/tiff'
@ -1351,7 +1359,7 @@
resolve({ resolve({
...attachment, ...attachment,
fileName: this.fixExtension(attachment.fileName, targetContentType), fileName: this.fixExtension(fileName, targetContentType),
contentType: targetContentType, contentType: targetContentType,
file: blob, file: blob,
}); });