Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Jul 11, 2024
1 parent 69de42d commit f602e04
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/MatrixClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,7 @@ export class MatrixClient extends EventEmitter {
return this.contentScannerInstance.downloadContent(mxcUrl, allowRemote);
}
const { domain, mediaId } = MXCUrl.parse(mxcUrl);
const path = `/_matrix/media/v3/download/${domain}/${mediaId}`;
const path = `/_matrix/media/v3/download/${encodeURIComponent(domain)}/${encodeURIComponent(mediaId)}`;
const res = await this.doRequest("GET", path, { allow_remote: allowRemote }, null, null, true, null, true);
return {
data: res.body,
Expand Down
4 changes: 3 additions & 1 deletion src/e2ee/CryptoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ export class CryptoClient {
*/
@requiresReady()
public async decryptMedia(file: EncryptedFile): Promise<Buffer> {
const contents = await this.client.contentScannerInstance.downloadEncryptedContent(file);
const contents = this.client.contentScannerInstance ?
await this.client.contentScannerInstance.downloadEncryptedContent(file) :
(await this.client.downloadContent(file.url)).data;
const encrypted = new EncryptedAttachment(
contents,
JSON.stringify(file),
Expand Down
8 changes: 4 additions & 4 deletions src/models/MXCUrl.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
export class MXCUrl {
static parse(mxcUrl: string): MXCUrl {
if (!mxcUrl?.toLowerCase()?.startsWith("mxc://")) {
throw Error("mxcUrl does not begin with mxc://");
throw Error("Not a MXC URI");
}
const [domain, mediaId] = mxcUrl.slice("mxc://".length).split("/", 2);
const [domain, ...mediaId] = mxcUrl.slice("mxc://".length).split("/");
if (!domain) {
throw Error("missing domain component");
}
if (!mediaId) {
if (!mediaId?.length) {
throw Error("missing mediaId component");
}
return new MXCUrl(domain, mediaId);
return new MXCUrl(domain, mediaId.join('/'));
}

constructor(public domain: string, public mediaId: string) { }
Expand Down

0 comments on commit f602e04

Please sign in to comment.