mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-22 19:14:52 +01:00
export BlobHandle and add method to create handle from buffer with unfiltered mimetype (for thirdroom)
This commit is contained in:
parent
a925ec622a
commit
457f1e52c9
@ -19,6 +19,7 @@ export type {ILogItem} from "./logging/types";
|
|||||||
export {IDBLogPersister} from "./logging/IDBLogPersister";
|
export {IDBLogPersister} from "./logging/IDBLogPersister";
|
||||||
export {ConsoleReporter} from "./logging/ConsoleReporter";
|
export {ConsoleReporter} from "./logging/ConsoleReporter";
|
||||||
export {Platform} from "./platform/web/Platform.js";
|
export {Platform} from "./platform/web/Platform.js";
|
||||||
|
export {BlobHandle} from "./platform/web/dom/BlobHandle";
|
||||||
export {Client, LoadStatus} from "./matrix/Client.js";
|
export {Client, LoadStatus} from "./matrix/Client.js";
|
||||||
export {RoomStatus} from "./matrix/room/common";
|
export {RoomStatus} from "./matrix/room/common";
|
||||||
// export everything needed to observe state events on all rooms using session.observeRoomState
|
// export everything needed to observe state events on all rooms using session.observeRoomState
|
||||||
|
@ -74,12 +74,23 @@ const ALLOWED_BLOB_MIMETYPES = {
|
|||||||
const DEFAULT_MIMETYPE = 'application/octet-stream';
|
const DEFAULT_MIMETYPE = 'application/octet-stream';
|
||||||
|
|
||||||
export class BlobHandle {
|
export class BlobHandle {
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* Don't use the constructor directly, instead use fromBuffer, fromBlob or fromBufferUnsafe
|
||||||
|
* */
|
||||||
constructor(blob, buffer = null) {
|
constructor(blob, buffer = null) {
|
||||||
this._blob = blob;
|
this._blob = blob;
|
||||||
this._buffer = buffer;
|
this._buffer = buffer;
|
||||||
this._url = null;
|
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) {
|
static fromBuffer(buffer, mimetype) {
|
||||||
mimetype = mimetype ? mimetype.split(";")[0].trim() : '';
|
mimetype = mimetype ? mimetype.split(";")[0].trim() : '';
|
||||||
if (!ALLOWED_BLOB_MIMETYPES[mimetype]) {
|
if (!ALLOWED_BLOB_MIMETYPES[mimetype]) {
|
||||||
|
Loading…
Reference in New Issue
Block a user