feat: 移除图片生成记录中的尺寸字段,调整归档逻辑以支持异步处理
This commit is contained in:
@@ -12,23 +12,23 @@ import { prisma } from "~~/server/utils/prisma";
|
||||
|
||||
const GLOBAL_STATS_ID = "global";
|
||||
const DEFAULT_IMAGE_MODEL = "gpt-image-2";
|
||||
const DEFAULT_IMAGE_SIZE = "1024x1024";
|
||||
|
||||
interface IFinishImageGenerationSuccessInput {
|
||||
/** NewAPI 上游返回的生成图片 URL */
|
||||
imageUrl: string;
|
||||
/** Lsky 图床归档后的图片 URL,归档失败时为空 */
|
||||
hostedImageUrl: string | null;
|
||||
/** 图片 MIME 类型,优先来自图床上传结果 */
|
||||
imageMimeType: string | null;
|
||||
/** 上游返回的修订提示词,流式生图通常为空 */
|
||||
revisedPrompt?: string | null;
|
||||
/** 完整上游响应,当前为 chat completions 流式聚合对象 */
|
||||
upstreamResponse: unknown;
|
||||
/** 完整 Lsky 上传响应,归档失败时为空 */
|
||||
}
|
||||
|
||||
interface IFinishImageGenerationArchiveSuccessInput {
|
||||
/** Lsky 图床归档后的图片 URL */
|
||||
hostedImageUrl: string;
|
||||
/** 图片 MIME 类型,优先来自图床上传结果 */
|
||||
imageMimeType: string | null;
|
||||
/** 完整 Lsky 上传响应 */
|
||||
hostedResponse: unknown;
|
||||
/** 成功状态下的非阻断提示,例如图床归档失败 */
|
||||
errorMessage?: string | null;
|
||||
}
|
||||
|
||||
/** 登录或恢复登录时保存 NewAPI 用户快照 */
|
||||
@@ -97,8 +97,7 @@ export const createRunningImageGeneration = async (
|
||||
userId,
|
||||
prompt,
|
||||
status: ImageGenerationStatus.RUNNING,
|
||||
model: DEFAULT_IMAGE_MODEL,
|
||||
size: DEFAULT_IMAGE_SIZE
|
||||
model: DEFAULT_IMAGE_MODEL
|
||||
}
|
||||
});
|
||||
|
||||
@@ -114,7 +113,7 @@ export const createRunningImageGeneration = async (
|
||||
return record;
|
||||
};
|
||||
|
||||
/** 将生图记录标记为成功,并保存上游 URL、图床 URL、完整响应和耗时 */
|
||||
/** 将生图记录标记为成功,并先写入上游结果;图床字段稍后由后台归档补写 */
|
||||
export const finishImageGenerationSuccess = async (
|
||||
recordId: bigint,
|
||||
startedAt: Date,
|
||||
@@ -131,15 +130,12 @@ export const finishImageGenerationSuccess = async (
|
||||
endedAt,
|
||||
durationMs: getDurationMs(startedAt, endedAt),
|
||||
imageUrl: input.imageUrl,
|
||||
hostedImageUrl: input.hostedImageUrl,
|
||||
imageMimeType: input.imageMimeType,
|
||||
hostedImageUrl: null,
|
||||
imageMimeType: null,
|
||||
revisedPrompt: input.revisedPrompt || null,
|
||||
upstreamResponse: input.upstreamResponse as Prisma.InputJsonValue,
|
||||
hostedResponse:
|
||||
input.hostedResponse === null
|
||||
? Prisma.DbNull
|
||||
: (input.hostedResponse as Prisma.InputJsonValue),
|
||||
errorMessage: input.errorMessage || null
|
||||
hostedResponse: Prisma.DbNull,
|
||||
errorMessage: null
|
||||
}
|
||||
});
|
||||
|
||||
@@ -186,6 +182,39 @@ export const finishImageGenerationFailed = async (
|
||||
});
|
||||
};
|
||||
|
||||
/** 后台归档成功后回写图床地址、MIME 和图床响应 */
|
||||
export const finishImageGenerationArchiveSuccess = async (
|
||||
recordId: bigint,
|
||||
input: IFinishImageGenerationArchiveSuccessInput
|
||||
) => {
|
||||
await prisma.imageGeneration.update({
|
||||
where: {
|
||||
id: recordId
|
||||
},
|
||||
data: {
|
||||
hostedImageUrl: input.hostedImageUrl,
|
||||
imageMimeType: input.imageMimeType,
|
||||
hostedResponse: input.hostedResponse as Prisma.InputJsonValue,
|
||||
errorMessage: null
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/** 后台归档失败时仅补写本地错误文案,不影响已成功的生图状态 */
|
||||
export const finishImageGenerationArchiveFailed = async (
|
||||
recordId: bigint,
|
||||
errorMessage: string = "图片归档失败"
|
||||
) => {
|
||||
await prisma.imageGeneration.update({
|
||||
where: {
|
||||
id: recordId
|
||||
},
|
||||
data: {
|
||||
errorMessage
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/** 查询当前用户未删除的生图历史列表,不返回完整上游/图床响应 */
|
||||
export const listImageGenerationHistory = async ({
|
||||
userId,
|
||||
@@ -221,7 +250,7 @@ export const listImageGenerationHistory = async ({
|
||||
};
|
||||
};
|
||||
|
||||
/** 查询当前用户单条生图历史详情,包含完整上游与图床响应 */
|
||||
/** 查询当前用户单条生图历史详情,内部响应字段固定隐藏为 null */
|
||||
export const getImageGenerationDetail = async (
|
||||
userId: number,
|
||||
recordId: bigint
|
||||
@@ -342,7 +371,6 @@ const mapImageGenerationItem = (record: {
|
||||
prompt: string;
|
||||
status: ImageGenerationStatus;
|
||||
model: string;
|
||||
size: string;
|
||||
startedAt: Date;
|
||||
endedAt: Date | null;
|
||||
durationMs: number | null;
|
||||
@@ -358,7 +386,6 @@ const mapImageGenerationItem = (record: {
|
||||
prompt: record.prompt,
|
||||
status: record.status,
|
||||
model: record.model,
|
||||
size: record.size,
|
||||
startedAt: record.startedAt.toISOString(),
|
||||
endedAt: record.endedAt?.toISOString() ?? null,
|
||||
durationMs: record.durationMs,
|
||||
|
||||
Reference in New Issue
Block a user