v3: added attachments to resources, allow users to paste images into TextEditor, strengthened WS reliability
This commit is contained in:
@@ -3,6 +3,7 @@ import { db } from "../model/db.ts";
|
||||
import { notifyDumpOwnerUpvote } from "./notification-service.ts";
|
||||
|
||||
export function castVote(dumpId: string, userId: string): number {
|
||||
let voteCount: number;
|
||||
try {
|
||||
db.exec("BEGIN;");
|
||||
db.prepare(
|
||||
@@ -15,10 +16,11 @@ export function castVote(dumpId: string, userId: string): number {
|
||||
`SELECT vote_count FROM dumps WHERE id = ?;`,
|
||||
).get(dumpId) as { vote_count: number } | undefined;
|
||||
db.exec("COMMIT;");
|
||||
notifyDumpOwnerUpvote(userId, dumpId);
|
||||
return row?.vote_count ?? 0;
|
||||
voteCount = row?.vote_count ?? 0;
|
||||
} catch (err) {
|
||||
db.exec("ROLLBACK;");
|
||||
try {
|
||||
db.exec("ROLLBACK;");
|
||||
} catch { /* ignore if no active transaction */ }
|
||||
if (err instanceof Error && err.message.includes("UNIQUE constraint")) {
|
||||
throw new APIException(
|
||||
APIErrorCode.VALIDATION_ERROR,
|
||||
@@ -28,6 +30,11 @@ export function castVote(dumpId: string, userId: string): number {
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
// Notification is best-effort — must not prevent vote_ack from being sent
|
||||
try {
|
||||
notifyDumpOwnerUpvote(userId, dumpId);
|
||||
} catch { /* ignore */ }
|
||||
return voteCount;
|
||||
}
|
||||
|
||||
export function removeVote(dumpId: string, userId: string): number {
|
||||
|
||||
Reference in New Issue
Block a user