mirror of
https://github.com/bretzel-app/crumbs.git
synced 2026-10-12 12:06:57 +02:00
- Add fetchAttachmentsForNotes() batch helper mirroring fetchTagsForNotes pattern - Include attachments in all note API responses (list, single, sync) - Fix ImageUpload.svelte URL bug (path-based → query param) - Add client-side image optimization (resize, compress, WebP conversion) - Add thumbnailPath column to attachments schema with migration - Update saveAttachment/deleteAttachment for thumbnail file handling - Update attachment API: accept thumbnail in POST, serve via &thumb=1 in GET - Add Cache-Control immutable header for served attachments Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
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';
|
|
import { fetchAttachmentsForNotes } from '$lib/server/attachments.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 noteIds = changes.map((n) => n.id);
|
|
const tagMap = fetchTagsForNotes(noteIds);
|
|
const attachmentMap = fetchAttachmentsForNotes(noteIds);
|
|
const changesWithTags = changes.map((note) => ({
|
|
...note,
|
|
tags: tagMap.get(note.id) ?? [],
|
|
attachments: attachmentMap.get(note.id) ?? []
|
|
}));
|
|
|
|
return json(changesWithTags);
|
|
};
|