2026-09-01 17:46:11 +08:00
|
|
|
import { adminForbidden, isAdminRequest } from "../../../lib/admin-auth";
|
|
|
|
|
import { buildTaskReportCsv } from "../../../lib/task-report-csv";
|
|
|
|
|
import {
|
|
|
|
|
ensureSchema,
|
|
|
|
|
getRawDb,
|
|
|
|
|
getTaskReportData,
|
|
|
|
|
} from "../../../lib/mvp-db";
|
2026-09-04 18:03:46 +08:00
|
|
|
import { getOwnerScope, ownerScopeUserid } from "../../../lib/owner-scope";
|
2026-09-01 17:46:11 +08:00
|
|
|
|
|
|
|
|
export async function GET(request: Request) {
|
|
|
|
|
try {
|
|
|
|
|
if (!(await isAdminRequest(request))) return adminForbidden();
|
|
|
|
|
await ensureSchema();
|
2026-09-04 18:03:46 +08:00
|
|
|
const rows = await getTaskReportData(
|
|
|
|
|
getRawDb(),
|
|
|
|
|
ownerScopeUserid(await getOwnerScope(request)),
|
|
|
|
|
);
|
2026-09-01 17:46:11 +08:00
|
|
|
const fileName = `任务复盘报表.csv`;
|
|
|
|
|
return new Response(buildTaskReportCsv(rows), {
|
|
|
|
|
headers: {
|
|
|
|
|
"Cache-Control": "private, no-store",
|
|
|
|
|
"Content-Type": "text/csv; charset=utf-8",
|
|
|
|
|
"Content-Disposition": `attachment; filename="koc-task-report.csv"; filename*=UTF-8''${encodeURIComponent(fileName)}`,
|
|
|
|
|
"X-Content-Type-Options": "nosniff",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return Response.json(
|
|
|
|
|
{ error: error instanceof Error ? error.message : "导出失败" },
|
|
|
|
|
{ status: 500 },
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|