mirror of
https://github.com/bretzel-app/crumbs.git
synced 2026-10-12 20:06:57 +02:00
- GET /api/sync now attaches tags to notes (matching GET /api/notes and GET /api/search behavior) - Add trashedAt field to Note schema in OpenAPI spec - Add optional id field to NoteInput schema - Add 400 error response for POST /api/sync - Add response schema for GET attachments list - Regenerate API.md Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
29 lines
860 B
TypeScript
29 lines
860 B
TypeScript
import { json } from '@sveltejs/kit';
|
|
import type { RequestHandler } from './$types.js';
|
|
import { processSyncPush, getChangesSince } from '$lib/sync/server.js';
|
|
import { fetchTagsForNotes } from '$lib/server/tags.js';
|
|
|
|
export const POST: RequestHandler = async ({ request }) => {
|
|
const { changes } = await request.json();
|
|
|
|
if (!Array.isArray(changes)) {
|
|
return json({ error: 'Invalid changes' }, { status: 400 });
|
|
}
|
|
|
|
await processSyncPush(changes);
|
|
return json({ success: true });
|
|
};
|
|
|
|
export const GET: RequestHandler = async ({ url }) => {
|
|
const since = parseInt(url.searchParams.get('since') || '0', 10);
|
|
const changes = await getChangesSince(since);
|
|
|
|
const tagMap = fetchTagsForNotes(changes.map((n) => n.id));
|
|
const changesWithTags = changes.map((note) => ({
|
|
...note,
|
|
tags: tagMap.get(note.id) ?? []
|
|
}));
|
|
|
|
return json(changesWithTags);
|
|
};
|