22 lines
722 B
JavaScript
22 lines
722 B
JavaScript
import { URL } from "node:url";
|
|
import config from "../config/index.js";
|
|
import punycode from "punycode/";
|
|
export function getFullApAccount(username, host) {
|
|
return host ? `${username}@${toPuny(host)}` : `${username}@${toPuny(config.domain)}`;
|
|
}
|
|
export function isSelfHost(host) {
|
|
if (host == null) return true;
|
|
return toPuny(config.domain) === toPuny(host) || toPuny(config.host) === toPuny(host);
|
|
}
|
|
export function extractDbHost(uri) {
|
|
const url = new URL(uri);
|
|
return toPuny(url.hostname);
|
|
}
|
|
export function toPuny(host) {
|
|
return punycode.toASCII(host.toLowerCase());
|
|
}
|
|
export function toPunyNullable(host) {
|
|
if (host == null) return null;
|
|
return punycode.toASCII(host.toLowerCase());
|
|
}
|