From af4abb772e53f0a5a8506cc79299fae6e99c84fd Mon Sep 17 00:00:00 2001 From: jonathang4 Date: Sat, 13 Dec 2025 10:08:43 +0800 Subject: [PATCH] 1 --- src/api/controllers/core.ts | 3 + src/api/controllers/images.ts | 156 ++++++++++++++---------- src/lib/services/TaskPollingService.ts | 157 +++++++++++++++---------- 3 files changed, 188 insertions(+), 128 deletions(-) diff --git a/src/api/controllers/core.ts b/src/api/controllers/core.ts index 68ed014..8caece3 100644 --- a/src/api/controllers/core.ts +++ b/src/api/controllers/core.ts @@ -257,6 +257,9 @@ export async function uploadFile( export function checkResult(result: AxiosResponse) { const { ret, errmsg, data } = result.data; if (!_.isFinite(Number(ret))) return result.data; + if (ret !== '0') { + logger.error(`[Jimeng API Error] ret=${ret}, errmsg=${errmsg}, data=${JSON.stringify(data)}`); + } if (ret === '0') return data; if (ret === '5000') throw new APIException(EX.API_IMAGE_GENERATION_INSUFFICIENT_POINTS, `[无法生成图像]: 即梦积分可能不足,${errmsg}`); diff --git a/src/api/controllers/images.ts b/src/api/controllers/images.ts index 5a0f251..df4f305 100644 --- a/src/api/controllers/images.ts +++ b/src/api/controllers/images.ts @@ -59,6 +59,96 @@ export async function generateImages( await receiveCredit(refreshToken); const componentId = util.uuid(); + const draftContent = { + type: "draft", + id: util.uuid(), + min_version: DRAFT_VERSION, + min_features: [], + is_from_tsn: true, + version: currentVersion, + main_component_id: componentId, + component_list: [ + { + type: "image_base_component", + id: componentId, + min_version: DRAFT_VERSION, + gen_type: 1, + generate_type: "generate", + aigc_mode: "workbench", + metadata: { + type: "", + id: util.uuid(), + created_platform: 3, + created_platform_version: "", + created_time_in_ms: Date.now().toString(), + created_did: "" + }, + abilities: { + type: "", + id: util.uuid(), + generate: { + type: "", + id: util.uuid(), + core_param: { + type: "", + id: util.uuid(), + model, + prompt, + negative_prompt: negativePrompt, + seed: Math.floor(Math.random() * 100000000) + 2500000000, + sample_strength: sampleStrength, + image_ratio: 1, + large_image_info: { + type: "", + id: util.uuid(), + height, + width, + resolution_type: resolutionType, + }, + intelligent_ratio: false + }, + history_option: { + type: "", + id: util.uuid(), + }, + }, + gen_option: { + type: "", + id: util.uuid(), + gen_count: 1, + generate_all: false + } + }, + }, + ], + }; + + const payloadData = { + extend: { + root_model: model, + template_id: "", + }, + submit_id: util.uuid(), + metrics_extra: JSON.stringify({ + templateId: "0", + generateCount: 1, + promptSource: "custom", + templateSource: "", + lastRequestId: "", + originRequestId: "", + enterFrom: "use_bgimage_prompt", + isRegenerate: false, + isBoxSelect: false, + isCutout: false + }), + draft_content: JSON.stringify(draftContent), + http_common_info: { + aid: Number(DEFAULT_ASSISTANT_ID), + }, + }; + + logger.info(`Jimeng Request Payload: ${JSON.stringify(payloadData)}`); + const { aigc_data } = await request( "post", "/mweb/v1/aigc_draft/generate", @@ -74,72 +164,10 @@ export async function generateImages( }) ), }, - data: { - extend: { - root_model: model, - template_id: "", - }, - submit_id: util.uuid(), - metrics_extra: JSON.stringify({ - templateId: "", - generateCount: 1, - promptSource: "custom", - templateSource: "", - lastRequestId: "", - originRequestId: "", - }), - draft_content: JSON.stringify({ - type: "draft", - id: util.uuid(), - min_version: DRAFT_VERSION, - is_from_tsn: true, - version: currentVersion, - main_component_id: componentId, - component_list: [ - { - type: "image_base_component", - id: componentId, - min_version: DRAFT_VERSION, - generate_type: "generate", - aigc_mode: "workbench", - abilities: { - type: "", - id: util.uuid(), - generate: { - type: "", - id: util.uuid(), - core_param: { - type: "", - id: util.uuid(), - model, - prompt, - negative_prompt: negativePrompt, - seed: Math.floor(Math.random() * 100000000) + 2500000000, - sample_strength: sampleStrength, - image_ratio: 1, - large_image_info: { - type: "", - id: util.uuid(), - height, - width, - resolution_type: resolutionType, - }, - }, - history_option: { - type: "", - id: util.uuid(), - }, - }, - }, - }, - ], - }), - http_common_info: { - aid: Number(DEFAULT_ASSISTANT_ID), - }, - }, + data: payloadData, } ); + logger.info(`Jimeng Response Data: ${JSON.stringify(aigc_data)}`); const historyId = aigc_data.history_record_id; if (!historyId) throw new APIException(EX.API_IMAGE_GENERATION_FAILED, "记录ID不存在"); diff --git a/src/lib/services/TaskPollingService.ts b/src/lib/services/TaskPollingService.ts index fee59c3..02be06d 100644 --- a/src/lib/services/TaskPollingService.ts +++ b/src/lib/services/TaskPollingService.ts @@ -791,6 +791,96 @@ export class TaskPollingService { const componentId = this.generateUUID(); const submitId = this.generateUUID(); + + const draftContent = { + type: "draft", + id: this.generateUUID(), + min_version: "3.0.2", + min_features: [], + is_from_tsn: true, + version: currentVersion, + main_component_id: componentId, + component_list: [ + { + type: "image_base_component", + id: componentId, + min_version: "3.0.2", + gen_type: 1, + generate_type: "generate", + aigc_mode: "workbench", + metadata: { + type: "", + id: this.generateUUID(), + created_platform: 3, + created_platform_version: "", + created_time_in_ms: Date.now().toString(), + created_did: "" + }, + abilities: { + type: "", + id: this.generateUUID(), + generate: { + type: "", + id: this.generateUUID(), + core_param: { + type: "", + id: this.generateUUID(), + model: mappedModel, + prompt, + negative_prompt, + seed: Math.floor(Math.random() * 100000000) + 2500000000, + sample_strength, + image_ratio: 1, + large_image_info: { + type: "", + id: this.generateUUID(), + height, + width, + resolution_type: resolutionType, + }, + intelligent_ratio: false + }, + history_option: { + type: "", + id: this.generateUUID(), + }, + }, + gen_option: { + type: "", + id: this.generateUUID(), + gen_count: 1, + generate_all: false + } + }, + }, + ], + }; + + const payloadData = { + extend: { + root_model: mappedModel, + template_id: "", + }, + submit_id: submitId, + metrics_extra: JSON.stringify({ + templateId: "0", + generateCount: 1, + promptSource: "custom", + templateSource: "", + lastRequestId: "", + originRequestId: "", + enterFrom: "use_bgimage_prompt", + isRegenerate: false, + isBoxSelect: false, + isCutout: false + }), + draft_content: JSON.stringify(draftContent), + http_common_info: { + aid: Number(process.env.DEFAULT_ASSISTANT_ID || "513695"), + }, + }; + + taskLog(`Jimeng Request Payload: ${JSON.stringify(payloadData)}`); const { aigc_data } = await request( "post", @@ -807,72 +897,11 @@ export class TaskPollingService { }) ), }, - data: { - extend: { - root_model: mappedModel, - template_id: "", - }, - submit_id: submitId, - metrics_extra: JSON.stringify({ - templateId: "", - generateCount: 1, - promptSource: "custom", - templateSource: "", - lastRequestId: "", - originRequestId: "", - }), - draft_content: JSON.stringify({ - type: "draft", - id: this.generateUUID(), - min_version: "3.0.2", - is_from_tsn: true, - version: currentVersion, - main_component_id: componentId, - component_list: [ - { - type: "image_base_component", - id: componentId, - min_version: "3.0.2", - generate_type: "generate", - aigc_mode: "workbench", - abilities: { - type: "", - id: this.generateUUID(), - generate: { - type: "", - id: this.generateUUID(), - core_param: { - type: "", - id: this.generateUUID(), - model: mappedModel, - prompt, - negative_prompt, - seed: Math.floor(Math.random() * 100000000) + 2500000000, - sample_strength, - image_ratio: 1, - large_image_info: { - type: "", - id: this.generateUUID(), - height, - width, - resolution_type: resolutionType, - }, - }, - history_option: { - type: "", - id: this.generateUUID(), - }, - }, - }, - }, - ], - }), - http_common_info: { - aid: Number(process.env.DEFAULT_ASSISTANT_ID || "513695"), - }, - }, + data: payloadData, } ); + + taskLog(`Jimeng Response Data: ${JSON.stringify(aigc_data)}`); const historyId = aigc_data.history_record_id; if (!historyId) {