FoundKey/packages/backend/src/misc/convert-host.ts
Johann150 2ea6daaf7a
Some checks failed
ci/woodpecker/push/lint-backend Pipeline failed
ci/woodpecker/push/lint-client Pipeline failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/lint-sw Pipeline failed
ci/woodpecker/push/test Pipeline failed
rename extractDbHost to extractPunyHost
2023-06-27 22:02:32 +02:00

27 lines
773 B
TypeScript

import { toASCII } from 'punycode';
import { URL } from 'node:url';
import config from '@/config/index.js';
export function getFullApAccount(username: string, host: string | null): string {
return host ? `${username}@${toPuny(host)}` : `${username}@${toPuny(config.host)}`;
}
export function isSelfHost(host: string | null): boolean {
if (host == null) return true;
return toPuny(config.host) === toPuny(host);
}
export function extractPunyHost(uri: string): string {
const url = new URL(uri);
return toPuny(url.hostname);
}
export function toPuny(host: string): string {
return toASCII(host.toLowerCase());
}
export function toPunyNullable(host: string | null | undefined): string | null {
if (host == null) return null;
return toASCII(host.toLowerCase());
}