From 2890a6aff7ad2ec8cf2352011e7019e5c539e509 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 11 Nov 2020 10:45:44 +0100 Subject: [PATCH] implement attachment uploading in hs api rather than media repo as we need the access token --- src/matrix/net/HomeServerApi.js | 4 ++++ src/matrix/net/MediaRepository.js | 7 ------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/matrix/net/HomeServerApi.js b/src/matrix/net/HomeServerApi.js index 81da33d1..1f2acab4 100644 --- a/src/matrix/net/HomeServerApi.js +++ b/src/matrix/net/HomeServerApi.js @@ -220,6 +220,10 @@ export class HomeServerApi { roomKeyForRoomAndSession(version, roomId, sessionId, options = null) { return this._get(`/room_keys/keys/${encodeURIComponent(roomId)}/${encodeURIComponent(sessionId)}`, {version}, null, options); } + + uploadAttachment(blob, filename, options = null) { + return this._post("/upload", {filename}, blob, options); + } } export function tests() { diff --git a/src/matrix/net/MediaRepository.js b/src/matrix/net/MediaRepository.js index 8ab37a87..2e7ec438 100644 --- a/src/matrix/net/MediaRepository.js +++ b/src/matrix/net/MediaRepository.js @@ -72,11 +72,4 @@ export class MediaRepository { return this.downloadPlaintextFile(content.url, content.info?.mimetype, cache); } } - - async upload(bufferHandle, filename) { - const url = `${this._homeServer}/_matrix/media/r0/upload?filename=${encodeURIComponent(filename)}`; - // TODO: body doesn't take a bufferHandle currently - const {content_uri} = await this._platform.request(url, {method: "POST", body: bufferHandle}).response(); - return content_uri; - } }