You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.5 KiB
42 lines
1.5 KiB
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { listExportTasksByUser, markExportTaskExpired } from "#server/service/export/jobs";
|
|
import { R } from "#server/utils/response";
|
|
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
const user = await event.context.auth.requireUser();
|
|
const tasks = await listExportTasksByUser(user.id);
|
|
const now = Date.now();
|
|
const normalizedTasks = await Promise.all(
|
|
tasks.map(async (task) => {
|
|
if (task.status !== "succeeded") {
|
|
return task;
|
|
}
|
|
if (!task.expiresAt || task.expiresAt.getTime() <= now) {
|
|
return markExportTaskExpired(task.id, "导出结果已过期,请重新导出");
|
|
}
|
|
if (!task.outputDir || !task.outputName) {
|
|
return markExportTaskExpired(task.id, "导出结果缺失,请重新导出");
|
|
}
|
|
const manifestPath = path.resolve(task.outputDir, "manifest.json");
|
|
if (!fs.existsSync(manifestPath)) {
|
|
return markExportTaskExpired(task.id, "导出文件已丢失,请重新导出");
|
|
}
|
|
return task;
|
|
}),
|
|
);
|
|
return R.success({
|
|
items: normalizedTasks.map((task) => ({
|
|
id: task.id,
|
|
status: task.status,
|
|
maskPolicy: task.maskPolicy,
|
|
outputName: task.outputName,
|
|
totalBytes: task.totalBytes,
|
|
errorCode: task.errorCode,
|
|
errorMessage: task.errorMessage,
|
|
createdAt: task.createdAt.toISOString(),
|
|
updatedAt: task.updatedAt.toISOString(),
|
|
expiresAt: task.expiresAt ? task.expiresAt.toISOString() : null,
|
|
})),
|
|
});
|
|
});
|
|
|