allow downloading plaintext attachments also, with or without cache

This commit is contained in:
Bruno Windels 2020-11-10 17:49:48 +01:00
parent 4477073d6d
commit 373a42c7a8
2 changed files with 18 additions and 3 deletions

View File

@ -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;

View File

@ -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);
}
}
}