v3: added site-wide categories, added admin category management, various visual fixes
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 2m52s
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 2m52s
This commit is contained in:
@@ -33,6 +33,19 @@ import { getRelatedDumps } from "../services/backlink-service.ts";
|
||||
|
||||
const router = new Router({ prefix: "/api/dumps" });
|
||||
|
||||
// Categories arrive on the multipart create path as a JSON-encoded string field.
|
||||
function parseCategoryIds(value: FormDataEntryValue | null): string[] {
|
||||
if (typeof value !== "string" || !value) return [];
|
||||
try {
|
||||
const parsed = JSON.parse(value);
|
||||
return Array.isArray(parsed)
|
||||
? parsed.filter((v): v is string => typeof v === "string")
|
||||
: [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
router.post(
|
||||
"/",
|
||||
authMiddleware,
|
||||
@@ -63,6 +76,7 @@ router.post(
|
||||
userId,
|
||||
isPrivate,
|
||||
typeof title === "string" && title ? title : undefined,
|
||||
parseCategoryIds(formData.get("categoryIds")),
|
||||
);
|
||||
} else {
|
||||
const body = await ctx.request.body.json();
|
||||
@@ -156,6 +170,9 @@ router.put("/:dumpId/file", authMiddleware, async (ctx) => {
|
||||
file,
|
||||
typeof comment === "string" && comment ? comment : undefined,
|
||||
typeof title === "string" && title ? title : undefined,
|
||||
formData.has("categoryIds")
|
||||
? parseCategoryIds(formData.get("categoryIds"))
|
||||
: undefined,
|
||||
);
|
||||
const responseBody: APIResponse<Dump> = { success: true, data: updatedDump };
|
||||
ctx.response.body = responseBody;
|
||||
|
||||
Reference in New Issue
Block a user