chore(收尾): mock 数据同步 B2 引用模型-附件 refType 场景引用/page unusedCount/upload scene 白名单

This commit is contained in:
chenxing
2026-09-08 15:14:09 +08:00
parent fc566eed8b
commit 2a077aa917
2 changed files with 16 additions and 4 deletions
+7 -3
View File
@@ -724,12 +724,12 @@ async function handleApi(req: IncomingMessage, res: ServerResponse, path: string
const page = num(q(req, "page"), 1)!;
const pageSize = num(q(req, "pageSize"), 10)!;
let rows = db.attachments.filter(t => t.siteId === siteId);
if (orphanOnly) rows = rows.filter(t => !t.articleId);
if (orphanOnly) rows = rows.filter(t => !t.articleId && !t.refType); // B2 未使用语义
const total = rows.length;
const list = rows
.slice((page - 1) * pageSize, page * pageSize)
.map((t: MockAttachment) => ({ ...t, orphan: !t.articleId }));
sendJson(res, ok({ total, list, orphanCount: db.attachments.filter(t => t.siteId === siteId && !t.articleId).length }));
sendJson(res, ok({ total, list, unusedCount: db.attachments.filter(t => t.siteId === siteId && !t.articleId && !t.refType).length })); // B2:orphanCount→unusedCount
return true;
}
if (method === "POST" && path === "/api/attachment/upload") {
@@ -744,10 +744,14 @@ async function handleApi(req: IncomingMessage, res: ServerResponse, path: string
db.files.set(url, { buffer: file.buffer, mime: file.mime, name: safeName });
const siteId = num(q(req, "siteId"), 0) ?? num(body.toString("latin1").match(/name="siteId"\r\n\r\n(\d+)/)?.[1], 0)!;
const articleId = num(q(req, "articleId")) ?? num(body.toString("latin1").match(/name="articleId"\r\n\r\n(\d+)/)?.[1], undefined);
// B2:scene 初步标记(banner/link/site 白名单,其余忽略)
const sceneRaw = q(req, "scene");
const scene = ["banner", "link", "site"].includes(sceneRaw) ? sceneRaw : undefined;
const row: MockAttachment = {
id: nextId(db.attachments),
siteId,
articleId,
refType: scene,
fileName: safeName,
url,
fileSize: file.buffer.length,
@@ -755,7 +759,7 @@ async function handleApi(req: IncomingMessage, res: ServerResponse, path: string
createTime: now(),
};
db.attachments.push(row);
sendJson(res, ok({ ...row, orphan: !row.articleId }));
sendJson(res, ok({ ...row, orphan: !row.articleId && !row.refType }));
return true;
}
if (method === "POST" && path === "/api/attachment/delete") {