feat: add local auth billing and usage management

This commit is contained in:
inman committed 2026-08-12 12:13:06 +08:00
1 parent f642b5e71f
commit 196fdde83f
119 files changed
+15695 -2650

No files matched your search

+6 -1
View File
@@ -1,7 +1,8 @@
import { deleteAsset, deleteGenerationJob, getAsset, getGenerationJob } from "@/lib/server/data-store";
import { deleteAsset, deleteGenerationJob, getAsset, getGenerationJob, updateGenerationJob } from "@/lib/server/data-store";
import { jsonError, jsonOk } from "@/lib/server/api";
import { requireAppUser } from "@/lib/server/auth/current-user";
import { deleteStoredAsset } from "@/lib/server/storage";
import { refundGenerationCharge } from "@/lib/server/billing-service";
export const runtime = "nodejs";
@@ -31,6 +32,10 @@ export async function DELETE(_request: Request, context: { params: Promise<{ id:
await deleteAsset(asset.id);
deletedAssetIds.push(asset.id);
}
const cancellableJob = ["queued", "running"].includes(job.status)
? await updateGenerationJob(job.id, { status: "cancelled", completedAt: new Date().toISOString() })
: job;
await refundGenerationCharge(cancellableJob, "任务已删除");
await deleteGenerationJob(id);
return jsonOk({ ok: true, deletedJobId: id, deletedAssetIds });
} catch (error) {