Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
convertImgToBlob(`https://www.thetvdb.com/banners/${res.filename}`).then(blob => {
db.insert({
_id: `img${tvelem.show.replace(' ', '')}S${tvelem.season}E${tvelem.episode}`,
elempath: data[2],
elem: data[0],
tvelem: data[1],
imgData: blob
});
blobUtil.base64StringToBlob(blob, 'image/jpeg').then(blob => {
console.info(blob);
img.children[0].style.backgroundImage = `url(${URL.createObjectURL(blob)})`; // eslint-disable-line
}).catch(err => {
Raven.captureException(err);
Raven.showReportDialog();
});
});
} else if (res.filename === '') {
async function addPlantLocalforage (state, meta) {
// FIXME: This is generally a bad idea. Use feature detection instead.
// However, I could not find a reliable way to test if IndexedDB supports blobs,
// as it fails silently. We have to convert the blob to base64,
// because mobile Safari 10 has a bug with storing Blobs in IndexedDB.
if (iOS && !!meta.blob) {
const base64String = await blobToBase64String(meta.blob)
await addEntryLF(namespace + meta.guid, { ...meta, blob: base64String })
} else {
await addEntryLF(namespace + meta.guid, meta)
}
}
const qrCodeAsBase64 = await ScanExchangeHelper.generateQRCode(scanDocData.shortLink)
scanDocData.qrCodeAsBase64 = qrCodeAsBase64
}
if (
scanDocData.status === ScanExchangerCodes.Step07_ResultIsAvailable &&
(scanDocData.result || scanDocData.resultUrl)
) {
let scanResultDec
if (scanDocData.result) {
scanResultDec = CryptoHelper.decrypt(scanDocData.result, secretKey)
} else if (scanDocData.resultUrl) {
const resultUrl = CryptoHelper.decrypt(scanDocData.resultUrl, secretKey)
const response = await fetch(resultUrl)
const blob = await response.blob()
const text = await blobToBase64String(blob)
scanDocData.result = text
scanResultDec = CryptoHelper.decrypt(text, secretKey)
firebase
.storage()
.refFromURL(resultUrl)
.delete()
}
// Notify success listeners
this.notifyOnSuccessListeners({ result: scanResultDec, sourceBlob: null }, true)
// After successfully read 'result', remove it from the Firestore
scan.update({
result: null,
resultUrl: null
})
db.find({_id: `img${tvelem.show.replace(' ', '')}S${tvelem.season}E${tvelem.episode}`}, (err, doc) => {
if (err) {
Raven.captureException(err);
Raven.showReportDialog();
}
blobUtil.base64StringToBlob(doc[0].imgData, 'image/jpeg').then(blob => {
img.children[0].style.backgroundImage = `url(${URL.createObjectURL(blob)})`; // eslint-disable-line
resolve(['got from db']);
}).catch(err => {
Raven.captureException(err);
Raven.showReportDialog();
});
});
}
exports.makeVideoThumbnail = async ({
size,
videoObjectUrl,
logger,
contentType,
}) => {
let screenshotObjectUrl;
try {
const blob = await exports.makeVideoScreenshot({
objectUrl: videoObjectUrl,
contentType,
logger,
});
const data = await blobToArrayBuffer(blob);
screenshotObjectUrl = arrayBufferToObjectURL({
data,
type: contentType,
});
// We need to wait for this, otherwise the finally below will run first
const resultBlob = await exports.makeImageThumbnail({
size,
objectUrl: screenshotObjectUrl,
contentType,
logger,
});
return resultBlob;
} finally {
exports.revokeObjectUrl(screenshotObjectUrl);
exports.autoOrientJPEG = async attachment => {
if (!MIME.isJPEG(attachment.contentType)) {
return attachment;
}
// If we haven't downloaded the attachment yet, we won't have the data
if (!attachment.data) {
return attachment;
}
const dataBlob = await arrayBufferToBlob(
attachment.data,
attachment.contentType
);
const newDataBlob = await dataURLToBlob(await autoOrientImage(dataBlob));
const newDataArrayBuffer = await blobToArrayBuffer(newDataBlob);
// IMPORTANT: We overwrite the existing `data` `ArrayBuffer` losing the original
// image data. Ideally, we’d preserve the original image data for users who want to
// retain it but due to reports of data loss, we don’t want to overburden IndexedDB
// by potentially doubling stored image data.
// See: https://github.com/signalapp/Signal-Desktop/issues/1589
const newAttachment = Object.assign({}, attachment, {
data: newDataArrayBuffer,
size: newDataArrayBuffer.byteLength,
});
// `digest` is no longer valid for auto-oriented image data, so we discard it:
delete newAttachment.digest;
return newAttachment;
};
async function showPage(pageId) {
const page = await getPage({pageId, followRedirects: true})
if (page._id !== pageId) {
// Apparently getPage followed one or more redirects. Reload the viewer
// with the resolved page's id in the ?page query.
const location = new URL(window.location)
location.searchParams.set('page', page._id)
window.location = location
}
const timestamp = getTimestamp(page)
// Read the html file from the database.
const blob = await db.getAttachment(pageId, 'frozen-page.html')
// We assume utf-8 encoding. TODO: read encoding from document.
const html = new TextDecoder('utf-8').decode(await blobToArrayBuffer(blob))
document.title = `📄 ${page.title}`
const bar = (
<div id="bar">
<span id="description">
Snapshot of
<a style="{{margin:" href="{page.url}">
{shortUrl(page.url)}
</a>
<time datetime="{new">
{niceTime(timestamp)}
</time>
</span></div>
export async function stringToDataUrl(string, type='text/plain') {
// Using self.btoa is faster but fails for unicode strings.
const blob = new Blob([string], {type})
const dataUrl = await blobToDataURL(blob)
return dataUrl
}
// If we got passed the doc itself, we can check whether the attachment exists.
(doc && !get(['_attachments', attachmentId, 'digest'])(doc))
) {
return undefined
}
let blobOrBuffer
try {
blobOrBuffer = await db.getAttachment(docId, attachmentId)
} catch (err) {
return undefined
}
const contentType = get(['_attachments', attachmentId, 'content_type'])(doc)
const isBrowser = typeof window !== 'undefined' && !window.process
const blob = isBrowser
? blobOrBuffer
: await arrayBufferToBlob(blobOrBuffer, contentType)
const base64 = await blobToBase64String(blob)
const dataUrl = `data:${blob.type};base64,${base64}`
return dataUrl
}
exports.autoOrientJPEG = async attachment => {
if (!MIME.isJPEG(attachment.contentType)) {
return attachment;
}
// If we haven't downloaded the attachment yet, we won't have the data
if (!attachment.data) {
return attachment;
}
const dataBlob = await arrayBufferToBlob(
attachment.data,
attachment.contentType
);
const newDataBlob = await dataURLToBlob(await autoOrientImage(dataBlob));
const newDataArrayBuffer = await blobToArrayBuffer(newDataBlob);
// IMPORTANT: We overwrite the existing `data` `ArrayBuffer` losing the original
// image data. Ideally, we’d preserve the original image data for users who want to
// retain it but due to reports of data loss, we don’t want to overburden IndexedDB
// by potentially doubling stored image data.
// See: https://github.com/signalapp/Signal-Desktop/issues/1589
const newAttachment = Object.assign({}, attachment, {
data: newDataArrayBuffer,
size: newDataArrayBuffer.byteLength,
});