mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-27 15:05:38 -04:00
29 lines
981 B
TypeScript
29 lines
981 B
TypeScript
import { PermissionAreas } from '#shared/helpers.ts';
|
|
|
|
const byteLength = async (key: string): Promise<number> => {
|
|
const value = await useStorage().getItemRaw(key);
|
|
try {
|
|
return Buffer.byteLength(value);
|
|
} catch (error) {
|
|
return 0;
|
|
}
|
|
};
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const { isGranted } = await useAuthentication(event);
|
|
if (!isGranted(PermissionAreas.Code)) {
|
|
throw createError({
|
|
status: 401,
|
|
statusMessage: 'Unauthorised',
|
|
});
|
|
}
|
|
|
|
const keys = (await useStorage().getKeys())
|
|
.filter((key) => !key.startsWith('build') && !key.startsWith('root') && !key.startsWith('src'))
|
|
.toSorted();
|
|
return Object.fromEntries(await Promise.all(keys.map(async (key): Promise<[string, number]> => {
|
|
const meta = await useStorage().getMeta(key);
|
|
return [key, typeof meta.size === 'number' ? meta.size : await byteLength(key)] as const;
|
|
})));
|
|
});
|