iceshrimp-legacy/packages/backend/src/misc/convert-host.ts

29 lines
735 B
TypeScript
Raw Normal View History

2023-01-13 05:40:33 +01:00
import { URL } from "node:url";
import config from "@/config/index.js";
import { toASCII } from "punycode";
export function getFullApAccount(username: string, host: string | null) {
2023-01-13 05:40:33 +01:00
return host
? `${username}@${toPuny(host)}`
: `${username}@${toPuny(config.host)}`;
}
export function isSelfHost(host: string) {
if (host == null) return true;
return toPuny(config.host) === toPuny(host);
}
2019-03-13 03:21:16 +01:00
export function extractDbHost(uri: string) {
const url = new URL(uri);
return toPuny(url.hostname);
2019-03-13 03:21:16 +01:00
}
export function toPuny(host: string) {
return toASCII(host.toLowerCase());
}
2019-04-13 09:54:21 +02:00
export function toPunyNullable(host: string | null | undefined): string | null {
if (host == null) return null;
return toASCII(host.toLowerCase());
}