2019-03-12 15:38:11 +01:00
|
|
|
import config from '../config';
|
|
|
|
import { toUnicode, toASCII } from 'punycode';
|
2019-03-13 03:21:16 +01:00
|
|
|
import { URL } from 'url';
|
2019-03-12 15:38:11 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-03-13 03:21:16 +01:00
|
|
|
export function extractDbHost(uri: string) {
|
|
|
|
const url = new URL(uri);
|
|
|
|
return toDbHost(url.hostname);
|
|
|
|
}
|
|
|
|
|
2019-03-12 15:38:11 +01:00
|
|
|
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());
|
|
|
|
}
|