2023-01-13 04:40:33 +00:00
|
|
|
import { fetchMeta } from "@/misc/fetch-meta.js";
|
|
|
|
import type { Instance } from "@/models/entities/instance.js";
|
|
|
|
import type { Meta } from "@/models/entities/meta.js";
|
2022-12-24 19:39:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether a specific host (punycoded) should be blocked.
|
|
|
|
*
|
|
|
|
* @param host punycoded instance host
|
|
|
|
* @param meta a resolved Meta table
|
|
|
|
* @returns whether the given host should be blocked
|
|
|
|
*/
|
2023-01-13 04:40:33 +00:00
|
|
|
export async function shouldBlockInstance(
|
|
|
|
host: Instance["host"],
|
|
|
|
meta?: Meta,
|
|
|
|
): Promise<boolean> {
|
|
|
|
const { blockedHosts } = meta ?? (await fetchMeta());
|
|
|
|
return blockedHosts.some(
|
|
|
|
(blockedHost) => host === blockedHost || host.endsWith(`.${blockedHost}`),
|
|
|
|
);
|
2022-12-24 19:39:54 +00:00
|
|
|
}
|
2023-04-30 11:27:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether a specific host (punycoded) should be limited.
|
|
|
|
*
|
|
|
|
* @param host punycoded instance host
|
|
|
|
* @param meta a resolved Meta table
|
|
|
|
* @returns whether the given host should be limited
|
|
|
|
*/
|
|
|
|
export async function shouldSilenceInstance(
|
|
|
|
host: Instance["host"],
|
|
|
|
meta?: Meta,
|
|
|
|
): Promise<boolean> {
|
|
|
|
const { silencedHosts } = meta ?? (await fetchMeta());
|
|
|
|
return silencedHosts.some(
|
2023-04-30 12:08:45 +00:00
|
|
|
(silencedHost) =>
|
|
|
|
host === silencedHost || host.endsWith(`.${silencedHost}`),
|
2023-04-30 11:27:55 +00:00
|
|
|
);
|
|
|
|
}
|