dsh-game-material-master 0.9.2 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/config.js CHANGED
@@ -103,7 +103,7 @@ export async function migrateLegacyDataRoot() {
103
103
  * `custom` = 用户自己的生图服务,协议再分 OpenAI / ComfyUI / Stable Diffusion WebUI。
104
104
  * 换后端只改这一个字段:所有生图调用点都走 `imageprovider.generateImageWithProvider`。
105
105
  */
106
- export const IMAGE_PROVIDERS = ["ark", "custom"];
106
+ export const IMAGE_PROVIDERS = ["ark", "custom", "toapis"];
107
107
  /** 自定义生图服务的协议。 */
108
108
  export const CUSTOM_PROTOCOLS = ["openai", "comfyui", "sdwebui"];
109
109
  /**
@@ -131,6 +131,16 @@ export const CUSTOM_PROTOCOL_DEFAULTS = {
131
131
  }
132
132
  };
133
133
  export const DEFAULT_CONFIG = {
134
+ toapisBaseUrl: "https://toapis.cn/v1",
135
+ toapisApiKey: "",
136
+ toapisImageModel: "gpt-image-2-vip",
137
+ toapisImageSize: "1K",
138
+ toapisImageQuality: "low",
139
+ toapisVideo: false,
140
+ toapisVideoModel: "seedance-2-mini",
141
+ toapisVideoDuration: 4,
142
+ toapisVideoResolution: "480p",
143
+ toapisTimeoutMs: 600000,
134
144
  imageProvider: "ark",
135
145
  customProtocol: "openai",
136
146
  customBaseUrl: CUSTOM_PROTOCOL_DEFAULTS.openai.baseUrl,
@@ -301,7 +311,17 @@ export function normalizeConfig(input) {
301
311
  const comfyWorkflowRaw = asString(raw.comfyWorkflow, DEFAULT_CONFIG.comfyWorkflow);
302
312
  const comfyWorkflow = comfyWorkflowRaw.trim() === "" ? DEFAULT_CONFIG.comfyWorkflow : comfyWorkflowRaw;
303
313
  return {
304
- imageProvider: raw.imageProvider === "custom" ? "custom" : "ark",
314
+ toapisBaseUrl: asString(raw.toapisBaseUrl, DEFAULT_CONFIG.toapisBaseUrl).trim(),
315
+ toapisApiKey: asString(raw.toapisApiKey, DEFAULT_CONFIG.toapisApiKey).trim(),
316
+ toapisImageModel: asString(raw.toapisImageModel, DEFAULT_CONFIG.toapisImageModel).trim(),
317
+ toapisImageSize: asString(raw.toapisImageSize, DEFAULT_CONFIG.toapisImageSize).trim(),
318
+ toapisImageQuality: asString(raw.toapisImageQuality, DEFAULT_CONFIG.toapisImageQuality).trim(),
319
+ toapisVideo: asBool(raw.toapisVideo, DEFAULT_CONFIG.toapisVideo),
320
+ toapisVideoModel: asString(raw.toapisVideoModel, DEFAULT_CONFIG.toapisVideoModel).trim(),
321
+ toapisVideoDuration: asInt(raw.toapisVideoDuration, DEFAULT_CONFIG.toapisVideoDuration, 4, 15),
322
+ toapisVideoResolution: asString(raw.toapisVideoResolution, DEFAULT_CONFIG.toapisVideoResolution).trim(),
323
+ toapisTimeoutMs: asInt(raw.toapisTimeoutMs, DEFAULT_CONFIG.toapisTimeoutMs, 10000, 3600000),
324
+ imageProvider: raw.imageProvider === "toapis" ? "toapis" : raw.imageProvider === "custom" ? "custom" : "ark",
305
325
  customProtocol: CUSTOM_PROTOCOLS.includes(String(raw.customProtocol))
306
326
  ? raw.customProtocol
307
327
  : DEFAULT_CONFIG.customProtocol,
@@ -409,13 +429,15 @@ export async function saveConfig(patch) {
409
429
  return next;
410
430
  }
411
431
  export function maskConfig(config) {
412
- const { arkApiKey, minimaxApiKey, customApiKey, comfyCookies, musicApiKey, sfxApiKey, ...rest } = config;
432
+ const { toapisApiKey, arkApiKey, minimaxApiKey, customApiKey, comfyCookies, musicApiKey, sfxApiKey, ...rest } = config;
413
433
  const cookie = normalizeComfyCookies(comfyCookies);
414
434
  return {
415
435
  ...rest,
416
436
  rowOrder: [...config.rowOrder],
417
437
  // 复制一份再回传:界面改勾选后会把它当草稿改,共享同一个数组会互相写花。
418
438
  hiddenModules: [...config.hiddenModules],
439
+ toapisApiKeySet: toapisApiKey.trim() !== "",
440
+ toapisApiKeyHint: hintOf(toapisApiKey),
419
441
  arkApiKeySet: arkApiKey.trim() !== "",
420
442
  arkApiKeyHint: hintOf(arkApiKey),
421
443
  minimaxApiKeySet: minimaxApiKey.trim() !== "",
package/lib/imagegen.js CHANGED
@@ -16,7 +16,7 @@ import { mkdir, readFile, rm, stat, writeFile } from "node:fs/promises";
16
16
  import { basename, join, resolve, sep } from "node:path";
17
17
  import { randomUUID } from "node:crypto";
18
18
  import { imageJobsRoot, loadConfig } from "./config.js";
19
- import { generateImageWithProvider, imageModelOf, imageSizeOf, imageWatermarkOf, assertImageProviderReady, isCustomProvider } from "./imageprovider.js";
19
+ import { generateImageWithProvider, imageModelOf, imageSizeOf, imageWatermarkOf, assertImageProviderReady, imageUsesConfiguredSize } from "./imageprovider.js";
20
20
  import { decodeToRgba, mimeOf, toDataUri } from "./media.js";
21
21
  import { keyGreen } from "./chroma.js";
22
22
  import { encodePng } from "./png.js";
@@ -213,8 +213,8 @@ export async function generateImageItem(jobId, index) {
213
213
  // 生图模型同样是全局设置(设置 → 游戏素材大师 → 生图后端),任务只跟随、不覆盖。
214
214
  job.settings.model = imageModelOf(config);
215
215
  // 自定义后端的尺寸是全局参数(任务上的 size 是火山方舟时代的遗留),跟着配置走。
216
- if (isCustomProvider(config))
217
- job.settings.size = config.customSize;
216
+ if (imageUsesConfiguredSize(config))
217
+ job.settings.size = imageSizeOf(config);
218
218
  const item = job.items[index] ?? { index, status: "empty", source: "generated" };
219
219
  job.items[index] = { ...item, status: "running", error: undefined };
220
220
  appendJobLog(job.log, "info", `开始生成第 ${index + 1} 张`);
@@ -11,26 +11,41 @@
11
11
  * 这种「每处判一次」的分叉迟早会漏一处,而漏掉的那一处**不报错**,
12
12
  * 只是偷偷还在用另一家模型。
13
13
  */
14
+ import { assertToapisReady, generateToapisImage } from "./toapis.js";
14
15
  import { generateImage } from "./ark.js";
15
16
  import { CUSTOM_PROTOCOL_DEFAULTS, loadConfig } from "./config.js";
16
17
  import { CustomImageError, generateCustomImage } from "./customimage.js";
18
+ /** Non-Ark backends take their size from their own provider settings. */
19
+ export function imageUsesConfiguredSize(config) { return config.imageProvider !== "ark"; }
20
+ /** Only Ark supports a separate redraw model; other backends retain their selected model. */
21
+ export function imageRedrawModelOf(config) {
22
+ return config.imageProvider === "ark" ? config.arkRedrawModel.trim() || config.arkModel : imageModelOf(config);
23
+ }
17
24
  export function isCustomProvider(config) {
18
25
  return config.imageProvider === "custom";
19
26
  }
20
27
  /** 当前生图模型(Ark 是 `arkModel`,自定义是 `customModel`)。 */
21
28
  export function imageModelOf(config) {
29
+ if (config.imageProvider === "toapis")
30
+ return config.toapisImageModel;
22
31
  return isCustomProvider(config) ? config.customModel : config.arkModel;
23
32
  }
24
33
  /** 当前输出尺寸。 */
25
34
  export function imageSizeOf(config) {
35
+ if (config.imageProvider === "toapis")
36
+ return config.toapisImageSize;
26
37
  return isCustomProvider(config) ? config.customSize : config.arkSize;
27
38
  }
28
39
  /** 当前水印开关。水印是火山方舟特有的参数,自定义后端一律不带。 */
29
40
  export function imageWatermarkOf(config) {
41
+ if (config.imageProvider === "toapis")
42
+ return false;
30
43
  return isCustomProvider(config) ? false : config.arkWatermark;
31
44
  }
32
45
  /** 当前请求超时。 */
33
46
  export function imageTimeoutOf(config) {
47
+ if (config.imageProvider === "toapis")
48
+ return config.toapisTimeoutMs;
34
49
  return isCustomProvider(config) ? config.customTimeoutMs : config.arkTimeoutMs;
35
50
  }
36
51
  /** 自定义后端自己的必填项检查(不看 `imageProvider`,供「测试连接」按钮用)。 */
@@ -53,6 +68,15 @@ export function customImageBlocker(config) {
53
68
  * 只说「未配置」会让人在设置页里来回找。
54
69
  */
55
70
  export function imageProviderBlocker(config) {
71
+ if (config.imageProvider === "toapis") {
72
+ try {
73
+ assertToapisReady(config);
74
+ return undefined;
75
+ }
76
+ catch (error) {
77
+ return String(error.message);
78
+ }
79
+ }
56
80
  if (!isCustomProvider(config)) {
57
81
  if (config.arkApiKey.trim() === "") {
58
82
  return "尚未配置火山方舟 API Key(设置 → 游戏素材大师 → 生图后端 → 火山方舟)";
@@ -70,6 +94,8 @@ export function assertImageProviderReady(config) {
70
94
  }
71
95
  /** 一句话摘要(界面角标与工具面共用)。 */
72
96
  export function imageProviderSummary(config) {
97
+ if (config.imageProvider === "toapis")
98
+ return `ToAPIs · ${config.toapisImageModel}`;
73
99
  if (!isCustomProvider(config))
74
100
  return `火山方舟 · ${config.arkModel}`;
75
101
  const label = CUSTOM_PROTOCOL_DEFAULTS[config.customProtocol]?.label ?? config.customProtocol;
@@ -80,6 +106,8 @@ export function imageProviderSummary(config) {
80
106
  export async function generateImageWithProvider(request, signal) {
81
107
  const config = await loadConfig();
82
108
  assertImageProviderReady(config);
109
+ if (config.imageProvider === "toapis")
110
+ return generateToapisImage(config, request, signal);
83
111
  if (isCustomProvider(config)) {
84
112
  return generateCustomImage({
85
113
  protocol: config.customProtocol,