Merge pull request #1073 from vector-im/bwindels/export-blobhandle-sdk

export BlobHandle and add method to create handle from buffer with un…
This commit is contained in:
Bruno Windels 2023-04-06 15:20:03 +02:00 committed by GitHub
commit c37e86115d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -19,6 +19,7 @@ export type {ILogItem} from "./logging/types";
export {IDBLogPersister} from "./logging/IDBLogPersister";
export {ConsoleReporter} from "./logging/ConsoleReporter";
export {Platform} from "./platform/web/Platform.js";
export {BlobHandle} from "./platform/web/dom/BlobHandle";
export {Client, LoadStatus} from "./matrix/Client.js";
export {RoomStatus} from "./matrix/room/common";
// export everything needed to observe state events on all rooms using session.observeRoomState

View File

@ -74,12 +74,23 @@ const ALLOWED_BLOB_MIMETYPES = {
const DEFAULT_MIMETYPE = 'application/octet-stream';
export class BlobHandle {
/**
* @internal
* Don't use the constructor directly, instead use fromBuffer, fromBlob or fromBufferUnsafe
* */
constructor(blob, buffer = null) {
this._blob = blob;
this._buffer = buffer;
this._url = null;
}
/** Does not filter out mimetypes that could execute embedded javascript.
* It's up to the callee of this method to ensure that the blob won't be
* rendered by the browser in a way that could allow cross-signing scripting. */
static fromBufferUnsafe(buffer, mimetype) {
return new BlobHandle(new Blob([buffer], {type: mimetype}), buffer);
}
static fromBuffer(buffer, mimetype) {
mimetype = mimetype ? mimetype.split(";")[0].trim() : '';
if (!ALLOWED_BLOB_MIMETYPES[mimetype]) {