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

+7 -3
View File
@@ -10,6 +10,7 @@ import { advanceVideoJob } from "@/lib/server/video-generation-service";
import { recordAppLog } from "@/lib/server/log-manager";
import { requestOrigin } from "@/lib/server/runtime";
import { deliverJobWebhook } from "@/lib/server/webhook";
import { refundGenerationCharge } from "@/lib/server/billing-service";
import type { GenerationJob, GenerationStatus } from "@/lib/types";
export type WorkerTickResult = {
@@ -111,9 +112,12 @@ async function settleAdvancedJob(job: GenerationJob): Promise<{
}
if (TERMINAL_STATUSES.has(current.status)) {
const terminalJob = await clearGenerationJobLock(current.id, {
attempts: current.status === "failed" ? (current.attempts || 0) + 1 : current.attempts,
completedAt: current.completedAt || now.toISOString()
const refunded = current.status === "succeeded"
? current
: await refundGenerationCharge(current, current.error?.message || `任务${current.status}`) || current;
const terminalJob = await clearGenerationJobLock(refunded.id, {
attempts: refunded.status === "failed" ? (refunded.attempts || 0) + 1 : refunded.attempts,
completedAt: refunded.completedAt || now.toISOString()
});
const webhook = await deliverJobWebhook(terminalJob);
if (webhook.lastStatus) {