mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
allow downloading plaintext attachments also, with or without cache
This commit is contained in:
parent
4477073d6d
commit
373a42c7a8
@ -35,7 +35,7 @@ export class ImageTile extends MessageTile {
|
||||
}
|
||||
|
||||
async _loadEncryptedFile(file) {
|
||||
const bufferHandle = await this._mediaRepository.downloadEncryptedFile(file);
|
||||
const bufferHandle = await this._mediaRepository.downloadEncryptedFile(file, true);
|
||||
if (this.isDisposed) {
|
||||
bufferHandle.dispose();
|
||||
return;
|
||||
|
@ -52,10 +52,25 @@ export class MediaRepository {
|
||||
}
|
||||
}
|
||||
|
||||
async downloadEncryptedFile(fileEntry) {
|
||||
async downloadEncryptedFile(fileEntry, cache = false) {
|
||||
const url = this.mxcUrl(fileEntry.url);
|
||||
const {body: encryptedBuffer} = await this._platform.request(url, {method: "GET", format: "buffer", cache: true}).response();
|
||||
const {body: encryptedBuffer} = await this._platform.request(url, {method: "GET", format: "buffer", cache}).response();
|
||||
const decryptedBuffer = await decryptAttachment(this._platform.crypto, encryptedBuffer, fileEntry);
|
||||
return this._platform.createBufferHandle(decryptedBuffer, fileEntry.mimetype);
|
||||
}
|
||||
|
||||
async downloadPlaintextFile(mxcUrl, mimetype, cache = false) {
|
||||
const url = this.mxcUrl(mxcUrl);
|
||||
const {body: buffer} = await this._platform.request(url, {method: "GET", format: "buffer", cache}).response();
|
||||
return this._platform.createBufferHandle(buffer, mimetype);
|
||||
}
|
||||
|
||||
async downloadAttachment(content, cache = false) {
|
||||
if (content.file) {
|
||||
return this.downloadEncryptedFile(content.file, cache);
|
||||
} else {
|
||||
return this.downloadPlaintextFile(content.url, content.info?.mimetype, cache);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user