Skip to content

Commit e31e65b

Browse files
committed
Fix media upload being on the wrong endpoint
1 parent dc8df60 commit e31e65b

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/MatrixClient.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,9 +1595,9 @@ export class MatrixClient extends EventEmitter {
15951595

15961596
private async getMediaEndpointPrefix() {
15971597
if (await this.doesServerSupportVersion('v1.11')) {
1598-
return `${this.homeserverUrl}/_matrix/client/v1/media`;
1598+
return `/_matrix/client/v1/media`;
15991599
}
1600-
return `${this.homeserverUrl}/_matrix/media/v3`;
1600+
return `/_matrix/media/v3`;
16011601
}
16021602

16031603
/**
@@ -1608,7 +1608,7 @@ export class MatrixClient extends EventEmitter {
16081608
public async mxcToHttp(mxc: string): Promise<string> {
16091609
const { domain, mediaId } = MXCUrl.parse(mxc);
16101610
const endpoint = await this.getMediaEndpointPrefix();
1611-
return `${endpoint}/download/${encodeURIComponent(domain)}/${encodeURIComponent(mediaId)}`;
1611+
return `${this.homeserverUrl}${endpoint}/download/${encodeURIComponent(domain)}/${encodeURIComponent(mediaId)}`;
16121612
}
16131613

16141614
/**
@@ -1636,8 +1636,7 @@ export class MatrixClient extends EventEmitter {
16361636
@timedMatrixClientFunctionCall()
16371637
public async uploadContent(data: Buffer, contentType = "application/octet-stream", filename: string = null): Promise<string> {
16381638
// TODO: Make doRequest take an object for options
1639-
const endpoint = await this.getMediaEndpointPrefix();
1640-
return this.doRequest("POST", `${endpoint}/upload`, { filename: filename }, data, 60000, false, contentType)
1639+
return this.doRequest("POST", "/_matrix/media/v3/upload", { filename: filename }, data, 60000, false, contentType)
16411640
.then(response => response["content_uri"]);
16421641
}
16431642

test/MatrixClientTest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5717,7 +5717,7 @@ describe('MatrixClient', () => {
57175717
Buffer.isBuffer = <any>(i => i === data);
57185718

57195719
// noinspection TypeScriptValidateJSTypes
5720-
http.when("POST", "/_matrix/client/v1/media/upload").respond(200, (path, content, req) => {
5720+
http.when("POST", "/_matrix/media/v3/upload").respond(200, (path, content, req) => {
57215721
expect(content).toBeDefined();
57225722
expect(req.queryParams.filename).toEqual(filename);
57235723
expect(req.headers["Content-Type"]).toEqual(contentType);
@@ -5740,7 +5740,7 @@ describe('MatrixClient', () => {
57405740
Buffer.isBuffer = <any>(i => i === data);
57415741

57425742
// noinspection TypeScriptValidateJSTypes
5743-
http.when("POST", "/_matrix/client/v1/media/upload").respond(200, (path, content, req) => {
5743+
http.when("POST", "/_matrix/media/v3/upload").respond(200, (path, content, req) => {
57445744
expect(content).toBeDefined();
57455745
expect(req.queryParams.filename).toEqual(filename);
57465746
expect(req.headers["Content-Type"]).toEqual(contentType);
@@ -5798,7 +5798,7 @@ describe('MatrixClient', () => {
57985798
});
57995799

58005800
// noinspection TypeScriptValidateJSTypes
5801-
http.when("POST", "/_matrix/client/v1/media/upload").respond(200, (path, content, req) => {
5801+
http.when("POST", "/_matrix/media/v3/upload").respond(200, (path, content, req) => {
58025802
expect(content).toBeDefined();
58035803
// HACK: We know the mock library will return JSON
58045804
expect(req.headers["Content-Type"]).toEqual("application/json");

0 commit comments

Comments
 (0)