在把这个处理器接入租户导出 API 前审查它。
允许通过认证的租户维护者为本租户项目安排导出。只接受 1–64 个字符的小写 slug;通过注入的生成器创建抗碰撞任务 ID;发布只含标识且大小受限的任务;审计批准的标识,不能包含请求正文或凭据。
JavaScript
async function scheduleExport(request, store, queue, audit) {
const project = await store.find(request.params.projectId);
if (!project) {
return { status: 404, body: { error: "not found" } };
}
const archiveName = request.body.archiveName.trim();
if (archiveName.length > 64) {
return { status: 400, body: { error: "name too long" } };
}
const job = {
id: Date.now().toString(),
project,
archiveName,
requestedBy: request.user,
};
await queue.publish(job);
audit.push({ request, job });
return { status: 202, body: job };
}
生成代码仅作示例,不代表任何特定模型