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