Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getDownloadUrl(path: string): Promise {
if (this._parent && !path.startsWith('attachment:')) {
return this._parent.getDownloadUrl(path);
}
// Return a data URL with the data of the url
const key = path.slice('attachment:'.length);
if (!this._model.has(key)) {
// Resolve with unprocessed path, to show as broken image
return Promise.resolve(path);
}
const { data } = this._model.get(key);
const mimeType = Object.keys(data)[0];
// Only support known safe types:
if (imageRendererFactory.mimeTypes.indexOf(mimeType) === -1) {
return Promise.reject(
`Cannot render unknown image mime type "${mimeType}".`
);
}
const dataUrl = `data:${mimeType};base64,${data[mimeType]}`;
return Promise.resolve(dataUrl);
}
return this._parent.getDownloadUrl(path);
}
// Return a data URL with the data of the url
const key = path.slice('attachment:'.length);
const attachment = DatastoreExt.getField(this._data.datastore, {
...this._data.record,
field: 'attachments'
});
if (!attachment || !attachment[key]) {
// Resolve with unprocessed path, to show as broken image
return Promise.resolve(path);
}
const data = AttachmentsData.getData(attachment[key]);
const mimeType = Object.keys(data)[0];
// Only support known safe types:
if (imageRendererFactory.mimeTypes.indexOf(mimeType) === -1) {
return Promise.reject(
`Cannot render unknown image mime type "${mimeType}".`
);
}
const dataUrl = `data:${mimeType};base64,${data[mimeType]}`;
return Promise.resolve(dataUrl);
}
it('should support multiple mimeTypes', () => {
expect(imageRendererFactory.mimeTypes).to.deep.equal([
'image/bmp',
'image/png',
'image/jpeg',
'image/gif'
]);
});
});
it('should support multiple mimeTypes', () => {
expect(imageRendererFactory.mimeTypes).to.deep.equal([
'image/bmp',
'image/png',
'image/jpeg',
'image/gif'
]);
});
});