mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-27 06:52:35 -04:00
32 lines
921 B
TypeScript
32 lines
921 B
TypeScript
import { PermissionAreas } from '#shared/helpers.ts';
|
|
import type { LocaleCode } from '#shared/helpers.ts';
|
|
import { fetchStats } from '~~/server/admin.ts';
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const { isGranted } = await useAuthentication(event);
|
|
if (!isGranted(PermissionAreas.Panel)) {
|
|
throw createError({
|
|
status: 401,
|
|
statusMessage: 'Unauthorised',
|
|
});
|
|
}
|
|
|
|
const db = useDatabase();
|
|
const stats = await fetchStats(db);
|
|
if (stats === null) {
|
|
throw createError({
|
|
status: 404,
|
|
statusMessage: 'Not Found',
|
|
});
|
|
}
|
|
|
|
for (const locale of Object.keys(stats.locales)) {
|
|
if (!isGranted(PermissionAreas.Panel, locale as LocaleCode)) {
|
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
delete stats.locales[locale];
|
|
}
|
|
}
|
|
|
|
return stats;
|
|
});
|