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

-47
View File
@@ -1,47 +0,0 @@
import { getAsset } from "@/lib/server/data-store";
import { jsonError, jsonOk, readJsonBody } from "@/lib/server/api";
import { requireAppUser } from "@/lib/server/auth/current-user";
import { requestOrigin } from "@/lib/server/runtime";
import { saveMaskDataUrl } from "@/lib/server/storage";
import { submitImageJob } from "@/lib/server/generation-service";
export const runtime = "nodejs";
export async function POST(request: Request, context: { params: Promise<{ id: string }> }) {
try {
const user = await requireAppUser();
const { id } = await context.params;
const asset = await getAsset(id);
if (!asset || asset.ownerId !== user.id) return jsonError(new Error("Asset not found."), 404);
const body = await readJsonBody<{
prompt?: string;
maskDataUrl?: string;
maskUrl?: string;
seed?: number;
}>(request);
let maskUrl = body.maskUrl;
let maskAssetId: string | undefined;
if (body.maskDataUrl) {
const mask = await saveMaskDataUrl({
ownerId: asset.ownerId,
dataUrl: body.maskDataUrl,
origin: requestOrigin(request),
jobHint: asset.id
});
maskUrl = mask.url;
maskAssetId = mask.id;
}
if (!maskUrl) throw new Error("maskDataUrl or maskUrl is required for inpainting.");
const job = await submitImageJob({
ownerId: user.id,
capability: "image.inpaint",
prompt: body.prompt || "删除",
imageUrls: [asset.url, maskUrl],
inputAssetIds: [asset.id, ...(maskAssetId ? [maskAssetId] : [])],
seed: typeof body.seed === "number" ? body.seed : undefined
}, requestOrigin(request));
return jsonOk({ job }, { status: 202 });
} catch (error) {
return jsonError(error);
}
}
-31
View File
@@ -1,31 +0,0 @@
import { getAsset } from "@/lib/server/data-store";
import { jsonError, jsonOk, readJsonBody } from "@/lib/server/api";
import { requireAppUser } from "@/lib/server/auth/current-user";
import { requestOrigin } from "@/lib/server/runtime";
import { submitImageJob } from "@/lib/server/generation-service";
export const runtime = "nodejs";
export async function POST(request: Request, context: { params: Promise<{ id: string }> }) {
try {
const user = await requireAppUser();
const { id } = await context.params;
const asset = await getAsset(id);
if (!asset || asset.ownerId !== user.id) return jsonError(new Error("Asset not found."), 404);
const body = await readJsonBody<{
resolution?: "4k" | "8k";
scale?: number;
}>(request);
const job = await submitImageJob({
ownerId: user.id,
capability: "image.upscale",
imageUrls: [asset.url],
inputAssetIds: [asset.id],
resolution: body.resolution === "8k" ? "8k" : "4k",
scale: typeof body.scale === "number" ? body.scale : undefined
}, requestOrigin(request));
return jsonOk({ job }, { status: 202 });
} catch (error) {
return jsonError(error);
}
}
+1 -1
View File
@@ -21,7 +21,7 @@ export async function POST(request: Request) {
name?: string;
kind?: AssetKind;
tags?: string[];
source?: "upload" | "generated" | "edited" | "upscaled" | "external" | "seed";
source?: "upload" | "generated" | "external" | "seed";
}>(request);
const user = await requireAppUser();
if (!body.url) throw new Error("url is required");