mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-26 09:20:24 -05:00
27 lines
687 B
TypeScript
27 lines
687 B
TypeScript
import * as AdminRepository from "~/features/admin/AdminRepository.server";
|
|
import { databaseTimestampToDate } from "~/utils/dates";
|
|
|
|
let bannedUsers = await AdminRepository.allBannedUsers();
|
|
|
|
export function checkBanStatus(
|
|
banned: number | null | undefined,
|
|
now: Date = new Date(),
|
|
): boolean {
|
|
if (!banned) return false;
|
|
if (banned === 1) return true;
|
|
|
|
const banExpiresAt = databaseTimestampToDate(banned);
|
|
|
|
return banExpiresAt > now;
|
|
}
|
|
|
|
export function userIsBanned(userId: number) {
|
|
const banStatus = bannedUsers.get(userId);
|
|
|
|
return checkBanStatus(banStatus?.banned);
|
|
}
|
|
|
|
export async function refreshBannedCache() {
|
|
bannedUsers = await AdminRepository.allBannedUsers();
|
|
}
|