Skip to content

Commit

Permalink
Merge pull request #1073 from vector-im/bwindels/export-blobhandle-sdk
Browse files Browse the repository at this point in the history
export BlobHandle and add method to create handle from buffer
  • Loading branch information
bwindels authored and Nate Martin committed Apr 6, 2023
1 parent 4b8db13 commit a913fbb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export {ConsoleReporter} from "./logging/ConsoleReporter";
export {Platform} from "./platform/web/Platform.js";
export {FeatureSet, FeatureFlag} from "./features.js";
export {Client, LoadStatus, LoginFailure} from "./matrix/Client.js";
export {BlobHandle} from "./platform/web/dom/BlobHandle";
export {RoomStatus} from "./matrix/room/common";
export {AttachmentUpload} from "./matrix/room/AttachmentUpload";
export {CallIntent} from "./matrix/calls/callEventTypes";
Expand Down
11 changes: 11 additions & 0 deletions src/platform/web/dom/BlobHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down

0 comments on commit a913fbb

Please sign in to comment.