jormungandr-bite/packages/backend/src/misc/should-block-instance.ts

21 lines
644 B
TypeScript
Raw Normal View History

2023-01-12 21:40:33 -07: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 12:39:54 -07: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-12 21:40:33 -07: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 12:39:54 -07:00
}