feat: 增强功能批量入库 - 双色彩引擎/抖动/杂色清理/品牌色板/PDF导出/编辑工具/分享/i18n 等验收代码

This commit is contained in:
Sisyphus (主代理) committed 2026-08-14 00:20:40 +08:00
1 parent 02762400fb
commit f846fabfc6
77 files changed
+11372 -226

No files matched your search

+5 -3
View File
@@ -6,10 +6,9 @@
* AI_IMAGE_API_KEY),未配置接口地址时使用内置 mock 模式生成占位图。
*/
import type Database from "better-sqlite3";
import { randomUUID } from "node:crypto";
import { deflateSync } from "node:zlib";
import type { AccessInfo } from "../types/index.js";
import { consumeCode, CodeError } from "../codes/service.js";
import { consumeCode, CodeError, createDownloadGrant } from "../codes/service.js";
import { buildPrompt, type ChibiCategory, type Composition } from "./prompts.js";
// ---------------------------------------------------------------------------
@@ -275,5 +274,8 @@ export async function generateChibiImage(
// 3. 生成图片
const image = await generateImage(prompt, req);
return { image, downloadGrant: randomUUID(), access };
// 4. 写入一次性下载授权凭证(下载时必须携带,防止绕过生成直接消耗次数)
const downloadGrant = createDownloadGrant(db, req.code);
return { image, downloadGrant, access };
}
+5 -1
View File
@@ -4,6 +4,7 @@ import type Database from "better-sqlite3";
import { getDb } from "../db/index.js";
import { generateChibiImage, ChibiError, type GenerateRequest } from "./generate.js";
import { findTemplate, type ChibiCategory, type Composition } from "./prompts.js";
import { createRateLimiter, RATE_LIMITS } from "../security/rate-limit.js";
const CATEGORIES: readonly ChibiCategory[] = ["landscape", "person", "pet", "object", "food"];
const COMPOSITIONS: readonly Composition[] = ["主体特写", "半幅构图", "完整构图"];
@@ -28,7 +29,10 @@ function resolveDb(injected?: Database.Database): Database.Database {
export function createChibiRouter(injectedDb?: Database.Database): Router {
const router = Router();
router.post("/generate", async (req: Request, res: Response): Promise<void> => {
// 防刷限流:AI 生成 10 次/小时/IP(每路由实例独立计数,测试互不干扰)
const chibiLimiter = createRateLimiter(RATE_LIMITS.chibiGenerate)("chibi_generate");
router.post("/generate", chibiLimiter, async (req: Request, res: Response): Promise<void> => {
try {
const body = (req.body ?? {}) as Record<string, unknown>;