Implement download_file in widget driver (#12931)
* Implement download_file in widget driver Signed-off-by: Michael Weimann <michael.weimann@nordeck.net> * Fix test URIs Signed-off-by: Michael Weimann <michael.weimann@nordeck.net> * Use download-file branch as widget-api source Signed-off-by: Michael Weimann <michael.weimann@nordeck.net> * bump matrix-widget-api to 1.9.0 Signed-off-by: Kim Brose <kim.brose@nordeck.net> * prettier Signed-off-by: Kim Brose <kim.brose@nordeck.net> --------- Signed-off-by: Michael Weimann <michael.weimann@nordeck.net> Signed-off-by: Kim Brose <kim.brose@nordeck.net> Co-authored-by: Kim Brose <kim.brose@nordeck.net>
This commit is contained in:
@@ -73,6 +73,7 @@ import { navigateToPermalink } from "../../utils/permalinks/navigator";
|
||||
import { SdkContextClass } from "../../contexts/SDKContext";
|
||||
import { ModuleRunner } from "../../modules/ModuleRunner";
|
||||
import SettingsStore from "../../settings/SettingsStore";
|
||||
import { Media } from "../../customisations/Media";
|
||||
|
||||
// TODO: Purge this from the universe
|
||||
|
||||
@@ -679,4 +680,18 @@ export class StopGapWidgetDriver extends WidgetDriver {
|
||||
|
||||
return { contentUri: uploadResult.content_uri };
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a file from the media repository on the homeserver.
|
||||
*
|
||||
* @param contentUri - the MXC URI of the file to download
|
||||
* @returns an object with: file - response contents as Blob
|
||||
*/
|
||||
public async downloadFile(contentUri: string): Promise<{ file: XMLHttpRequestBodyInit }> {
|
||||
const client = MatrixClientPeg.safeGet();
|
||||
const media = new Media({ mxc: contentUri }, client);
|
||||
const response = await media.downloadSource();
|
||||
const blob = await response.blob();
|
||||
return { file: blob };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user