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

21 lines
644 B
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
}