misskey/src/misc/convert-host.ts

23 lines
590 B
TypeScript
Raw Normal View History

import config from '../config';
import { toASCII } from 'punycode';
2019-03-13 03:21:16 +01:00
import { URL } from 'url';
export function getFullApAccount(username: string, host: string) {
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) {
if (host == null) return null;
return toASCII(host.toLowerCase());
}