web: use mimetype when saving base64 data attachments

This allows the caching layer to correctly cache images.
This commit is contained in:
Abdullah Atta
2023-01-07 22:17:13 +05:00
committed by Abdullah Atta
parent 6ba3732327
commit 966130dc52

View File

@@ -102,14 +102,14 @@ async function writeEncryptedFile(file, key, hash) {
* 3. We encrypt the Uint8Array
* 4. We save the encrypted Uint8Array
*/
async function writeEncrypted(filename, { data, type, key }) {
async function writeEncrypted(filename, { data, type, key, mimeType }) {
if (type === "base64") data = new Uint8Array(Buffer.from(data, "base64"));
const { hash, type: hashType } = await hashBuffer(data);
if (!filename) filename = hash;
const file = new File([data.buffer], filename, {
type: "application/octet-stream"
type: mimeType || "application/octet-stream"
});
const result = await writeEncryptedFile(file, key, hash);
@@ -291,6 +291,7 @@ async function uploadFile(filename, requestOptions) {
await fileHandle.addAdditionalData("uploaded", true);
// Keep the images cached; delete everything else.
if (!fileHandle.file.type?.startsWith("image/")) {
console.log("DELETING FILE", fileHandle);
await streamablefs.deleteFile(filename);
}
await checkUpload(filename);