All checks were successful
Deploy production / deploy (push) Successful in 1m14s
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { requireOwner } from '#lib/server/owner.js';
|
|
import { addUsage, deleteUsage, loadUsage } from '#lib/server/ai-tracker.js';
|
|
import { fail } from '@sveltejs/kit';
|
|
import type { Actions, PageServerLoad } from './$types';
|
|
|
|
// Owner only: dated usage numbers per provider. Actions don't run the load, so each
|
|
// action checks the owner again (hooks.server.ts also 404s this path for everyone else).
|
|
export const load: PageServerLoad = async (event) => {
|
|
// cache-control comes from the ai layout (owner) and hooks.server.ts; setting it here too threw
|
|
// header_already_set (500) for the owner.
|
|
requireOwner(event);
|
|
return {
|
|
entries: await loadUsage(),
|
|
seo: { title: 'AI tracker · usage', description: 'My AI usage.', index: false }
|
|
};
|
|
};
|
|
|
|
export const actions: Actions = {
|
|
add: async (event) => {
|
|
requireOwner(event);
|
|
const r = await addUsage(await event.request.formData());
|
|
return r.ok ? { saved: true } : fail(400, { message: r.message });
|
|
},
|
|
delete: async (event) => {
|
|
requireOwner(event);
|
|
const r = await deleteUsage(await event.request.formData());
|
|
return r.ok ? { deleted: true } : fail(400, { message: r.message });
|
|
}
|
|
};
|