summaryrefslogtreecommitdiff
path: root/src/misc/convert-host.ts
diff options
context:
space:
mode:
authorMeiMei <30769358+mei23@users.noreply.github.com>2019-03-12 23:38:11 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2019-03-12 23:38:11 +0900
commit0a0aa0e2dbaf345a840b57216906ac52292ae3da (patch)
treee7f82c159ca2138e30eb12e6e9e72c36b7f916a9 /src/misc/convert-host.ts
parentAdd type annotation to avoid type error (diff)
downloadsharkey-0a0aa0e2dbaf345a840b57216906ac52292ae3da.tar.gz
sharkey-0a0aa0e2dbaf345a840b57216906ac52292ae3da.tar.bz2
sharkey-0a0aa0e2dbaf345a840b57216906ac52292ae3da.zip
Fix #4484 (#4485)
* Fix #4484 * import order
Diffstat (limited to 'src/misc/convert-host.ts')
-rw-r--r--src/misc/convert-host.ts21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/misc/convert-host.ts b/src/misc/convert-host.ts
new file mode 100644
index 0000000000..d4478bd85b
--- /dev/null
+++ b/src/misc/convert-host.ts
@@ -0,0 +1,21 @@
+import config from '../config';
+import { toUnicode, toASCII } from 'punycode';
+
+export function getFullApAccount(username: string, host: string) {
+ return host ? `${username}@${toApHost(host)}` : `${username}@${toApHost(config.host)}`;
+}
+
+export function isSelfHost(host: string) {
+ if (host == null) return true;
+ return toApHost(config.host) === toApHost(host);
+}
+
+export function toDbHost(host: string) {
+ if (host == null) return null;
+ return toUnicode(host.toLowerCase());
+}
+
+export function toApHost(host: string) {
+ if (host == null) return null;
+ return toASCII(host.toLowerCase());
+}