mirror of
https://github.com/bretzel-app/crumbs.git
synced 2026-10-12 20:06:57 +02:00
- POST/DELETE /api/notes/[id]/share for creating/revoking public links - GET /api/shared/[token] for fetching shared note data (no auth) - GET /api/shared/[token]/attachment/[attachmentId] for public images - Add /s/ and /api/shared to PUBLIC_PATHS in auth middleware - Add IP-based rate limiter (60 req/min) for public endpoints Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
21 lines
626 B
TypeScript
21 lines
626 B
TypeScript
import { json, error } from '@sveltejs/kit';
|
|
import type { RequestHandler } from './$types.js';
|
|
import { getSharedNote } from '$lib/server/shares-service.js';
|
|
import { checkIpRateLimit } from '$lib/server/ip-rate-limit.js';
|
|
import { db } from '$lib/server/db/index.js';
|
|
|
|
export const GET: RequestHandler = async ({ params, getClientAddress }) => {
|
|
const ip = getClientAddress();
|
|
if (!checkIpRateLimit(ip)) {
|
|
throw error(429, 'Too many requests');
|
|
}
|
|
|
|
const data = getSharedNote(db, params.token);
|
|
if (!data) {
|
|
throw error(404, 'Not found');
|
|
}
|
|
|
|
const { noteId: _, ...publicData } = data;
|
|
return json(publicData);
|
|
};
|