修改:去掉重复上传图片
continuous-integration/drone/push Build was killed
continuous-integration/drone/promote/prod Build is passing

This commit is contained in:
Linzm committed 2026-11-04 18:42:25 +08:00
1 parent 4979739521
commit e1da41c2f8
1 file changed
+23 -24
+23 -24
View File
@@ -786,7 +786,8 @@ async function startGenerate(opts: {
userText: string userText: string
userImage?: string userImage?: string
mode: 'generate' | 'edit' mode: 'generate' | 'edit'
file?: File | null /** 导入阶段已拿到的 upload_id;提交只 confirm,不再调 upload/url */
uploadId: string
sceneProp?: string sceneProp?: string
}) { }) {
if (remainCount.value <= 0) { if (remainCount.value <= 0) {
@@ -806,6 +807,14 @@ async function startGenerate(opts: {
return return
} }
const uploadId = String(opts.uploadId || '').trim()
if (!uploadId) {
showToast(
opts.mode === 'edit' ? config.messages.effectPreparing : config.messages.needPhoto,
)
return
}
const now = new Date() const now = new Date()
const time = formatTime(now) const time = formatTime(now)
const startedAt = Date.now() const startedAt = Date.now()
@@ -832,25 +841,10 @@ async function startGenerate(opts: {
isBusy.value = true isBusy.value = true
pendingFinish.value = null pendingFinish.value = null
lastUploadId.value = uploadId
try { try {
if (!opts.file && !pendingUploadId.value) { // 提交阶段:仅 confirm → imagegen/submit(upload/url 已在导入时完成)
throw new Error(opts.mode === 'edit' ? '缺少可编辑的效果图' : '请先上传照片')
}
// 复用导入阶段的 upload_id;若无则兜底:url+PUT(仍不在这里 classify)
let uploadId = String(pendingUploadId.value || '').trim()
if (!uploadId) {
if (!opts.file) throw new Error(opts.mode === 'edit' ? '缺少可编辑的效果图' : '请先上传照片')
const prepared = await jingdongApi.prepareUpload(opts.file, {
session_id: sid,
purpose: 'origin',
})
uploadId = prepared.uploadId
pendingUploadId.value = uploadId
lastUploadId.value = uploadId
}
// 提交阶段:confirm → imagegen/submit
await jingdongApi.confirmUpload({ await jingdongApi.confirmUpload({
session_id: sid, session_id: sid,
upload_id: uploadId, upload_id: uploadId,
@@ -948,14 +942,20 @@ function onSend() {
const text = draft.value.trim() const text = draft.value.trim()
const sceneProp = resolveScenePropFromOrder(orderStat.value, productTitle.value) const sceneProp = resolveScenePropFromOrder(orderStat.value, productTitle.value)
// 必须在 resetComposer 之前取出:reset 会清空 pendingUploadId
const uploadId = String(pendingUploadId.value || '').trim()
if (!uploadId) {
showToast(config.messages.uploadingTip)
return
}
if (isEditing.value) { if (isEditing.value) {
if (!text) { if (!text) {
showToast(config.messages.needEditText) showToast(config.messages.needEditText)
return return
} }
const file = pendingFile.value
const image = pendingPreview.value const image = pendingPreview.value
if (!file || !image) { if (!image) {
showToast(config.messages.effectPreparing) showToast(config.messages.effectPreparing)
return return
} }
@@ -964,15 +964,14 @@ function onSend() {
void startGenerate({ void startGenerate({
userText: text, userText: text,
mode: 'edit', mode: 'edit',
file, uploadId,
sceneProp, sceneProp,
}) })
return return
} }
const image = pendingPreview.value const image = pendingPreview.value
const file = pendingFile.value if (!image) {
if (!file || !image) {
showToast(config.messages.needPhoto) showToast(config.messages.needPhoto)
return return
} }
@@ -992,7 +991,7 @@ function onSend() {
userText: sendText, userText: sendText,
userImage: sendImage, userImage: sendImage,
mode: 'generate', mode: 'generate',
file, uploadId,
sceneProp, sceneProp,
}) })
} }