2019-03-12 14:38:11 +00:00
|
|
|
import config from '../config';
|
2019-04-09 14:59:32 +00:00
|
|
|
import { toASCII } from 'punycode';
|
2019-03-13 02:21:16 +00:00
|
|
|
import { URL } from 'url';
|
2019-03-12 14:38:11 +00:00
|
|
|
|
|
|
|
export function getFullApAccount(username: string, host: string) {
|
2019-04-09 14:59:32 +00:00
|
|
|
return host ? `${username}@${toPuny(host)}` : `${username}@${toPuny(config.host)}`;
|
2019-03-12 14:38:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function isSelfHost(host: string) {
|
|
|
|
if (host == null) return true;
|
2019-04-09 14:59:32 +00:00
|
|
|
return toPuny(config.host) === toPuny(host);
|
2019-03-12 14:38:11 +00:00
|
|
|
}
|
|
|
|
|
2019-03-13 02:21:16 +00:00
|
|
|
export function extractDbHost(uri: string) {
|
|
|
|
const url = new URL(uri);
|
2019-04-09 14:59:32 +00:00
|
|
|
return toPuny(url.hostname);
|
2019-03-13 02:21:16 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 14:59:32 +00:00
|
|
|
export function toPuny(host: string) {
|
2019-03-12 14:38:11 +00:00
|
|
|
if (host == null) return null;
|
|
|
|
return toASCII(host.toLowerCase());
|
|
|
|
}
|