iceshrimp-legacy/packages/backend/src/misc/should-block-instance.ts

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-01-13 05:40:33 +01: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 20:39:54 +01: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 05:40:33 +01: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 20:39:54 +01:00
}
2023-04-30 13:27:55 +02: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 14:08:45 +02:00
(silencedHost) =>
host === silencedHost || host.endsWith(`.${silencedHost}`),
2023-04-30 13:27:55 +02:00
);
}