readStorageMap -> conversion.blobToObj

This commit is contained in:
Timothy Farrell 2018-06-26 08:22:18 -05:00
parent 0fe0a9a05f
commit 1900322bf1
2 changed files with 7 additions and 7 deletions

View File

@ -1,6 +1,6 @@
import core from 'pouchdb-core'; import core from 'pouchdb-core';
import { backgroundTask } from '../utils/event.js'; 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'; import { error, log } from '../services/console.js';
const pouchBulkDocs = core.prototype.bulkDocs; const pouchBulkDocs = core.prototype.bulkDocs;
@ -8,10 +8,6 @@ const pouchGetAttachment = core.prototype.getAttachment;
const pouchRemoveAttachment = core.prototype.removeAttachment; const pouchRemoveAttachment = core.prototype.removeAttachment;
const STORAGE_MIMETYPE = 'application/b2storagemap'; const STORAGE_MIMETYPE = 'application/b2storagemap';
async function readStorageMap(blob) {
return JSON.parse(await blobToString(blob));
}
export function PouchDBAttachmentProxy({ save, getFn, remove }) { export function PouchDBAttachmentProxy({ save, getFn, remove }) {
const override = { const override = {
$attachmentsProxied: true $attachmentsProxied: true
@ -23,7 +19,7 @@ export function PouchDBAttachmentProxy({ save, getFn, remove }) {
if (att.type !== STORAGE_MIMETYPE) { if (att.type !== STORAGE_MIMETYPE) {
return att; 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) { const cleanupFiles = backgroundTask(function(att) {
if (att.type === STORAGE_MIMETYPE) { if (att.type === STORAGE_MIMETYPE) {
readStorageMap(att) blobToObj(att)
.then(remove) .then(remove)
.catch(e => error(`Failed to remove attachment ${args}`, e)); .catch(e => error(`Failed to remove attachment ${args}`, e));
} }

View File

@ -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 const arrayHashWrapper = hash => arr => (Array.isArray(arr) ? arr.map(hash).join('?') : arr);
export function pouchDocHash(d) { export function pouchDocHash(d) {