feat(api): expose preview/import/profile/domain endpoints
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
28
src/routes/api/profiles/+server.ts
Normal file
28
src/routes/api/profiles/+server.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import type { RequestHandler } from './$types';
|
||||
import { json, error } from '@sveltejs/kit';
|
||||
import { z } from 'zod';
|
||||
import { getDb } from '$lib/server/db';
|
||||
import { createProfile, listProfiles } from '$lib/server/profiles/repository';
|
||||
|
||||
const CreateSchema = z.object({
|
||||
name: z.string().min(1).max(50),
|
||||
avatar_emoji: z.string().max(16).nullable().optional()
|
||||
});
|
||||
|
||||
export const GET: RequestHandler = async () => {
|
||||
return json(listProfiles(getDb()));
|
||||
};
|
||||
|
||||
export const POST: RequestHandler = async ({ request }) => {
|
||||
const body = await request.json().catch(() => null);
|
||||
const parsed = CreateSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
error(400, { message: 'Invalid body', issues: parsed.error.issues });
|
||||
}
|
||||
try {
|
||||
const p = createProfile(getDb(), parsed.data.name, parsed.data.avatar_emoji ?? null);
|
||||
return json(p, { status: 201 });
|
||||
} catch (e) {
|
||||
error(409, { message: (e as Error).message });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user