readStorageMap -> conversion.blobToObj
This commit is contained in:
parent
0fe0a9a05f
commit
1900322bf1
@ -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));
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user