diff --git a/packages/gallery/src/utils/attachmentProxy.js b/packages/gallery/src/utils/attachmentProxy.js index 5109293..2ca3dc1 100644 --- a/packages/gallery/src/utils/attachmentProxy.js +++ b/packages/gallery/src/utils/attachmentProxy.js @@ -1,6 +1,6 @@ import core from 'pouchdb-core'; import { backgroundTask } from '../utils/event.js'; -import { deepAssign, blobToString } from '../utils/conversion.js'; +import { deepAssign, blobToObj } from '../utils/conversion.js'; import { error, log } from '../services/console.js'; const pouchBulkDocs = core.prototype.bulkDocs; @@ -8,10 +8,6 @@ const pouchGetAttachment = core.prototype.getAttachment; const pouchRemoveAttachment = core.prototype.removeAttachment; const STORAGE_MIMETYPE = 'application/b2storagemap'; -async function readStorageMap(blob) { - return JSON.parse(await blobToString(blob)); -} - export function PouchDBAttachmentProxy({ save, getFn, remove }) { const override = { $attachmentsProxied: true @@ -23,7 +19,7 @@ export function PouchDBAttachmentProxy({ save, getFn, remove }) { if (att.type !== STORAGE_MIMETYPE) { return att; } - return await getFn(await readStorageMap(att)); + return await getFn(await blobToObj(att)); }; } @@ -83,7 +79,7 @@ export function PouchDBAttachmentProxy({ save, getFn, remove }) { const cleanupFiles = backgroundTask(function(att) { if (att.type === STORAGE_MIMETYPE) { - readStorageMap(att) + blobToObj(att) .then(remove) .catch(e => error(`Failed to remove attachment ${args}`, e)); } diff --git a/packages/gallery/src/utils/conversion.js b/packages/gallery/src/utils/conversion.js index 15ad1b2..e1b39b7 100644 --- a/packages/gallery/src/utils/conversion.js +++ b/packages/gallery/src/utils/conversion.js @@ -34,6 +34,10 @@ export function blobToString(blob) { }); } +export function blobToObj(blob) { + return blobToString(blob).then(JSON.parse); +} + export const arrayHashWrapper = hash => arr => (Array.isArray(arr) ? arr.map(hash).join('?') : arr); export function pouchDocHash(d) {