Skip to content

Commit

Permalink
Add content_scanner.url config option
Browse files Browse the repository at this point in the history
  • Loading branch information
weeman1337 committed Aug 25, 2022
1 parent 0599b51 commit 4588e70
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/content-scanner/ContentScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { IEncryptedFile } from "matrix-react-sdk/src/customisations/models/IMedi
import { PkEncryption } from "@matrix-org/olm";
import { ResizeMethod } from "matrix-js-sdk/src/@types/partials";
import { MatrixClientPeg } from "matrix-react-sdk/src/MatrixClientPeg";
import SdkConfig from "matrix-react-sdk/src/SdkConfig";

export enum ScanErrorReason {
RequestFailed = "MCS_MEDIA_REQUEST_FAILED",
Expand All @@ -38,6 +39,12 @@ export interface ScanResult {
scanned: boolean;
}

interface ContentScannerConfig {
content_scanner?: {
url?: string;
};
}

/**
* Content scanner implementation that interacts with a Matrix Content Scanner.
* @see https://github.com/matrix-org/matrix-content-scanner
Expand Down Expand Up @@ -122,11 +129,24 @@ export class ContentScanner {
this.hasKey = true;
}

/**
* Returns a ContentScanner instance.
* The ContentScanner uses the same URL as the matrix client.
* If content_scanner.url is set in the config, this URL is used instead.
*/
public static get instance(): ContentScanner {
if (!ContentScanner.internalInstance) {
ContentScanner.internalInstance = new ContentScanner(MatrixClientPeg.get().getHomeserverUrl());
if (ContentScanner.contentScannerUrl) {
ContentScanner.internalInstance = new ContentScanner(ContentScanner.contentScannerUrl);
} else {
ContentScanner.internalInstance = new ContentScanner(MatrixClientPeg.get().getHomeserverUrl());
}
}

return ContentScanner.internalInstance;
}

private static get contentScannerUrl(): string {

This comment has been minimized.

Copy link
@estellecomment

estellecomment Aug 25, 2022

Contributor

Optional : It would be less sneaky if this function returns homeserverUrl when it doesn't find any config. That way it would really do what its name implies.
(Alternatively, rename it contentScannerUrlFromConfig or something)

This comment has been minimized.

Copy link
@weeman1337

weeman1337 Aug 25, 2022

Author Contributor

Done

return (SdkConfig.get() as ContentScannerConfig)?.content_scanner?.url;
}
}

0 comments on commit 4588e70

Please sign in to comment.