implement attachment uploading in hs api rather than media repo

as we need the access token
This commit is contained in:
Bruno Windels 2020-11-11 10:45:44 +01:00
parent 9f2c7c1e32
commit 2890a6aff7
2 changed files with 4 additions and 7 deletions

View file

@ -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() {

View file

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