mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
apply platform changes to decrypting images
This commit is contained in:
parent
3ed5ea8b0b
commit
ee1e62207c
@ -20,7 +20,6 @@ const MAX_HEIGHT = 300;
|
||||
const MAX_WIDTH = 400;
|
||||
|
||||
export class ImageTile extends MessageTile {
|
||||
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this._decryptedThumbail = null;
|
||||
@ -34,8 +33,7 @@ export class ImageTile extends MessageTile {
|
||||
return;
|
||||
}
|
||||
// TODO: fix XSS bug here by not checking mimetype
|
||||
// const blob = new Blob([buffer], {type: file.mimetype});
|
||||
return this.track(this._platform.createBufferURI(buffer, file.mimetype));
|
||||
return this.track(this.platform.createBufferURL(buffer, file.mimetype));
|
||||
}
|
||||
|
||||
async load() {
|
||||
@ -52,9 +50,9 @@ export class ImageTile extends MessageTile {
|
||||
|
||||
get thumbnailUrl() {
|
||||
if (this._decryptedThumbail) {
|
||||
return this._decryptedThumbail.uri;
|
||||
return this._decryptedThumbail.url;
|
||||
} else if (this._decryptedImage) {
|
||||
return this._decryptedImage.uri;
|
||||
return this._decryptedImage.url;
|
||||
}
|
||||
const mxcUrl = this._getContent()?.url;
|
||||
if (typeof mxcUrl === "string") {
|
||||
@ -70,7 +68,7 @@ export class ImageTile extends MessageTile {
|
||||
this._decryptedImage = await this._loadEncryptedFile(file);
|
||||
}
|
||||
}
|
||||
return this._decryptedImage?.uri || "";
|
||||
return this._decryptedImage?.url || "";
|
||||
}
|
||||
|
||||
_scaleFactor() {
|
||||
|
@ -18,9 +18,9 @@ import {UpdateAction} from "../UpdateAction.js";
|
||||
import {ViewModel} from "../../../../ViewModel.js";
|
||||
|
||||
export class SimpleTile extends ViewModel {
|
||||
constructor({entry}) {
|
||||
super();
|
||||
this._entry = entry;
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this._entry = options.entry;
|
||||
}
|
||||
// view model props for all subclasses
|
||||
// hmmm, could also do instanceof ... ?
|
||||
|
@ -27,6 +27,7 @@ import {OnlineStatus} from "./dom/OnlineStatus.js";
|
||||
import {Crypto} from "./dom/Crypto.js";
|
||||
import {estimateStorageUsage} from "./dom/StorageEstimate.js";
|
||||
import {WorkerPool} from "./dom/WorkerPool.js";
|
||||
import {BufferURL} from "./dom/BufferURL.js";
|
||||
|
||||
function addScript(src) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
@ -127,4 +128,8 @@ export class Platform {
|
||||
setNavigation(navigation) {
|
||||
this._serviceWorkerHandler?.setNavigation(navigation);
|
||||
}
|
||||
|
||||
createBufferURL(buffer, mimetype) {
|
||||
return new BufferURL(buffer, mimetype);
|
||||
}
|
||||
}
|
||||
|
27
src/platform/web/dom/BufferURL.js
Normal file
27
src/platform/web/dom/BufferURL.js
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
export class BufferURL {
|
||||
constructor(buffer, mimetype) {
|
||||
const blob = new Blob([buffer], {type: mimetype});
|
||||
this.url = URL.createObjectURL(blob);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
URL.revokeObjectURL(this.url);
|
||||
this.url = null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user