ドメインは常にPunycodeで保存するように

This commit is contained in:
syuilo
2019-04-09 23:59:32 +09:00
parent 4d64fd665e
commit 33a9783ae5
11 changed files with 31 additions and 29 deletions

View File

@ -1,27 +1,22 @@
import config from '../config';
import { toUnicode, toASCII } from 'punycode';
import { toASCII } from 'punycode';
import { URL } from 'url';
export function getFullApAccount(username: string, host: string) {
return host ? `${username}@${toApHost(host)}` : `${username}@${toApHost(config.host)}`;
return host ? `${username}@${toPuny(host)}` : `${username}@${toPuny(config.host)}`;
}
export function isSelfHost(host: string) {
if (host == null) return true;
return toApHost(config.host) === toApHost(host);
return toPuny(config.host) === toPuny(host);
}
export function extractDbHost(uri: string) {
const url = new URL(uri);
return toDbHost(url.hostname);
return toPuny(url.hostname);
}
export function toDbHost(host: string) {
if (host == null) return null;
return toUnicode(host.toLowerCase());
}
export function toApHost(host: string) {
export function toPuny(host: string) {
if (host == null) return null;
return toASCII(host.toLowerCase());
}