feature/backend-rewrite #2

Open
kamil wants to merge 236 commits from feature/backend-rewrite into main
3 changed files with 28 additions and 2 deletions
Showing only changes of commit c06877069f - Show all commits

View File

@@ -348,7 +348,7 @@ actor APIClient {
/// Delete a comment (and its replies) by ID. Only the owner can delete.
func deleteComment(commentId: String) async throws {
struct Empty: Decodable {}
let _: Empty = try await fetch("/api/comments/\(commentId)", method: "DELETE")
let _: Empty = try await fetch("/api/comment/\(commentId)", method: "DELETE")
}
}

View File

@@ -156,7 +156,7 @@
if (deletingIds.has(commentId)) return;
deletingIds = new Set([...deletingIds, commentId]);
try {
const res = await fetch(`/api/comments/${commentId}`, { method: 'DELETE' });
const res = await fetch(`/api/comment/${commentId}`, { method: 'DELETE' });
if (!res.ok) return;
if (parentId) {
// Remove reply from parent

View File

@@ -0,0 +1,26 @@
import { error } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { deleteComment } from '$lib/server/pocketbase';
import { log } from '$lib/server/logger';
/**
* DELETE /api/comment/[id]
* Deletes a comment and its replies. Only the comment owner may delete.
* Requires authentication.
*/
export const DELETE: RequestHandler = async ({ params, locals }) => {
if (!locals.user) error(401, 'Login required');
const { id } = params;
try {
await deleteComment(id, locals.user.id);
return new Response(null, { status: 204 });
} catch (e) {
const msg = String(e);
if (msg.includes('Not authorized')) error(403, 'Not authorized to delete this comment');
if (msg.includes('not found')) error(404, 'Comment not found');
log.error('api/comment/[id]', 'deleteComment failed', { id, err: msg });
error(500, 'Failed to delete comment');
}
};