公开数据补交闭环(F1): - distributions 新增 public_metrics_screenshot_key(mysql/0022 迁移) - KOC 门户:链接已回填但采集失败时展示补交数据截图入口(kind=public-metrics) - 运营端:回收队列"核对补录"支持公开互动数据(赞/藏/评),按补交截图补录后采集状态置成功 - 企微催办:采集失败纳入待办(公开数据待补交) - task-result-image 支持 kind=publish 输出发布截图 门户文案(F2): - 自动采集数据明确"由系统每天自动采集,无需你填写",仅识别失败时才手动填写曝光/阅读 任务中心分发详情: - 任务中心/数据回收的分发表行可点击,弹窗查看详情 - 详情按任务类型适配:发布阶段/数据回收(自动采集)/创作者数据(第7天)/截图回收四区块三段式布局
65 lines
2.4 KiB
TypeScript
65 lines
2.4 KiB
TypeScript
import { adminForbidden, isAdminRequest } from "../../../lib/admin-auth";
|
|
import { ensureSchema, getRawDb, getUploadBucket } from "../../../lib/mvp-db";
|
|
import { parseResultScreenshotKeys } from "../../../lib/result-screenshots";
|
|
import { getOwnerScope, isDistributionOwner, ownerForbidden } from "../../../lib/owner-scope";
|
|
|
|
export async function GET(request: Request) {
|
|
if (!(await isAdminRequest(request))) return adminForbidden();
|
|
try {
|
|
await ensureSchema();
|
|
const url = new URL(request.url);
|
|
const distributionId = url.searchParams.get("distribution")?.trim();
|
|
const scope = await getOwnerScope(request);
|
|
if (
|
|
scope.kind === "owner" &&
|
|
!(await isDistributionOwner(getRawDb(), distributionId ?? "", scope.wecomUserId))
|
|
) {
|
|
return ownerForbidden();
|
|
}
|
|
// kind=publish 时返回 KOC 上传的发布截图(分发详情页核对用)
|
|
const imageKind = url.searchParams.get("kind") === "publish" ? "publish" : "result";
|
|
const imageIndex = Math.max(
|
|
1,
|
|
Number(url.searchParams.get("index") || 1),
|
|
);
|
|
if (!distributionId) {
|
|
return Response.json({ error: "缺少任务记录" }, { status: 400 });
|
|
}
|
|
const row = await getRawDb()
|
|
.prepare(
|
|
`SELECT result_screenshot_key, publish_screenshot_key FROM distributions
|
|
WHERE id = ?`,
|
|
)
|
|
.bind(distributionId)
|
|
.first<{
|
|
result_screenshot_key: string | null;
|
|
publish_screenshot_key: string | null;
|
|
}>();
|
|
const screenshotKey =
|
|
imageKind === "publish"
|
|
? row?.publish_screenshot_key ?? null
|
|
: row
|
|
? parseResultScreenshotKeys(row.result_screenshot_key)[imageIndex - 1]
|
|
: undefined;
|
|
if (!screenshotKey) {
|
|
return Response.json({ error: "任务截图不存在" }, { status: 404 });
|
|
}
|
|
const object = await getUploadBucket().get(screenshotKey);
|
|
if (!object) {
|
|
return Response.json({ error: "任务截图不存在" }, { status: 404 });
|
|
}
|
|
const headers = new Headers({
|
|
"Cache-Control": "private, no-store",
|
|
"Content-Disposition": 'inline; filename="task-result-screenshot"',
|
|
"X-Content-Type-Options": "nosniff",
|
|
});
|
|
object.writeHttpMetadata(headers);
|
|
return new Response(await object.arrayBuffer(), { headers });
|
|
} catch (error) {
|
|
return Response.json(
|
|
{ error: error instanceof Error ? error.message : "截图读取失败" },
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
}
|