Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var att = docInfo.data._attachments[key];
if (att.stub) {
// still need to update the refs mapping
var id = docInfo.data._id;
var rev = docInfo.data._rev;
saveAttachmentRefs(id, rev, att.digest, attachmentSaved);
continue;
}
var data;
if (typeof att.data === 'string') {
// input is assumed to be a base64 string
try {
data = pouchdbBinaryUtils.atob(att.data);
} catch (e) {
callback(pouchdbErrors.createError(pouchdbErrors.BAD_ARG,
'Attachment is not a valid base64 string'));
return;
}
doMD5(docInfo, key, attachmentSaved)(data);
} else {
prepareAttachmentForStorage(att.data,
doMD5(docInfo, key, attachmentSaved));
}
}
function finish() {
var seq = docInfo.metadata.rev_map[docInfo.metadata.rev];
/* istanbul ignore if */
if (seq) {
// check that there aren't any existing revisions with the same
// revision id, else we shouldn't do anything
var att = docInfo.data._attachments[key];
if (att.stub) {
// still need to update the refs mapping
var id = docInfo.data._id;
var rev = docInfo.data._rev;
saveAttachmentRefs(id, rev, att.digest, attachmentSaved);
continue;
}
var data;
if (typeof att.data === 'string') {
// input is assumed to be a base64 string
try {
data = pouchdbBinaryUtils.atob(att.data);
} catch (e) {
callback(pouchdbErrors.createError(pouchdbErrors.BAD_ARG,
'Attachment is not a valid base64 string'));
return;
}
doMD5(docInfo, key, attachmentSaved)(data);
} else {
prepareAttachmentForStorage(att.data,
doMD5(docInfo, key, attachmentSaved));
}
}
function finish() {
var seq = docInfo.metadata.rev_map[docInfo.metadata.rev];
/* istanbul ignore if */
if (seq) {
// check that there aren't any existing revisions with the same
// revision id, else we shouldn't do anything