summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/UtilityService.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2022-12-04 15:03:09 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2022-12-04 15:03:09 +0900
commitbbb49457f9fb5d46402e913c92ebf77722cad6ff (patch)
tree8ef285bcbab2c3a4a89d0a624a802d76a2864fed /packages/backend/src/core/UtilityService.ts
parent:art: (diff)
downloadsharkey-bbb49457f9fb5d46402e913c92ebf77722cad6ff.tar.gz
sharkey-bbb49457f9fb5d46402e913c92ebf77722cad6ff.tar.bz2
sharkey-bbb49457f9fb5d46402e913c92ebf77722cad6ff.zip
refactor: introduce bindThis decorator to bind this automaticaly
Diffstat (limited to 'packages/backend/src/core/UtilityService.ts')
-rw-r--r--packages/backend/src/core/UtilityService.ts6
1 files changed, 6 insertions, 0 deletions
diff --git a/packages/backend/src/core/UtilityService.ts b/packages/backend/src/core/UtilityService.ts
index 15dd684286..1412e6e9aa 100644
--- a/packages/backend/src/core/UtilityService.ts
+++ b/packages/backend/src/core/UtilityService.ts
@@ -3,6 +3,7 @@ import { toASCII } from 'punycode';
import { Inject, Injectable } from '@nestjs/common';
import { DI } from '@/di-symbols.js';
import type { Config } from '@/config.js';
+import { bindThis } from '@/decorators.js';
@Injectable()
export class UtilityService {
@@ -12,24 +13,29 @@ export class UtilityService {
) {
}
+ @bindThis
public getFullApAccount(username: string, host: string | null): string {
return host ? `${username}@${this.toPuny(host)}` : `${username}@${this.toPuny(this.config.host)}`;
}
+ @bindThis
public isSelfHost(host: string | null): boolean {
if (host == null) return true;
return this.toPuny(this.config.host) === this.toPuny(host);
}
+ @bindThis
public extractDbHost(uri: string): string {
const url = new URL(uri);
return this.toPuny(url.hostname);
}
+ @bindThis
public toPuny(host: string): string {
return toASCII(host.toLowerCase());
}
+ @bindThis
public toPunyNullable(host: string | null | undefined): string | null {
if (host == null) return null;
return toASCII(host.toLowerCase());