fix:painting support reload (#5886)

* add painting aihubmix provider

* fix: Cannot read properties of undefined (reading 'unshift')

* fix: painting redux data

* feat: customize aihubmix provider request logic

* fix: download error retry

* Update AihubmixProvider.ts

* back

* back

---------

Co-authored-by: zhaochenxue <zhaochenxue@bixin.cn>
Co-authored-by: 亢奋猫 <kangfenmao@qq.com>
This commit is contained in:
chenxue 2025-05-12 09:23:34 +08:00 committed by kangfenmao
parent d680dde0a7
commit 020806c92e
8 changed files with 90 additions and 26 deletions

View File

@ -773,6 +773,8 @@
"proxy_required": "Currently, you need to open a proxy to view the generated images, it will be supported in the future",
"image_file_required": "Please upload an image first",
"image_file_retry": "Please re-upload an image first",
"image_placeholder": "No image available",
"image_retry": "Retry",
"mode": {
"generate": "Draw",
"edit": "Edit",
@ -1386,6 +1388,7 @@
"models.add.group_name.tooltip": "Optional e.g. ChatGPT",
"models.add.model_id": "Model ID",
"models.add.model_id.placeholder": "Required e.g. gpt-3.5-turbo",
"models.add.model_id.select.placeholder": "Select Model",
"models.add.model_id.tooltip": "Example: gpt-3.5-turbo",
"models.add.model_name": "Model Name",
"models.add.model_name.placeholder": "Optional e.g. GPT-4",

View File

@ -773,6 +773,8 @@
"proxy_required": "現在、プロキシを開く必要があります。これは、将来サポートされる予定です",
"image_file_required": "画像を先にアップロードしてください",
"image_file_retry": "画像を先にアップロードしてください",
"image_placeholder": "画像がありません",
"image_retry": "再試行",
"mode": {
"generate": "画像生成",
"edit": "部分編集",
@ -1384,6 +1386,7 @@
"models.add.group_name.tooltip": "例ChatGPT",
"models.add.model_id": "モデルID",
"models.add.model_id.placeholder": "必須 例gpt-3.5-turbo",
"models.add.model_id.select.placeholder": "モデルを選択",
"models.add.model_id.tooltip": "例gpt-3.5-turbo",
"models.add.model_name": "モデル名",
"models.add.model_name.placeholder": "例GPT-3.5",

View File

@ -773,6 +773,8 @@
"proxy_required": "Сейчас необходимо открыть прокси для просмотра сгенерированных изображений, в будущем будет поддерживаться прямое соединение",
"image_file_required": "Пожалуйста, сначала загрузите изображение",
"image_file_retry": "Пожалуйста, сначала загрузите изображение",
"image_placeholder": "Изображение недоступно",
"image_retry": "Попробовать снова",
"mode": {
"generate": "Рисование",
"edit": "Редактирование",
@ -1384,6 +1386,7 @@
"models.add.group_name.tooltip": "Необязательно, например, ChatGPT",
"models.add.model_id": "ID модели",
"models.add.model_id.placeholder": "Обязательно, например, gpt-3.5-turbo",
"models.add.model_id.select.placeholder": "Выберите модель",
"models.add.model_id.tooltip": "Пример: gpt-3.5-turbo",
"models.add.model_name": "Имя модели",
"models.add.model_name.placeholder": "Необязательно, например, GPT-4",

View File

@ -773,6 +773,8 @@
"proxy_required": "目前需要打开代理才能查看生成图片,后续会支持国内直连",
"image_file_required": "请先上传图片",
"image_file_retry": "请重新上传图片",
"image_placeholder": "暂无图片",
"image_retry": "重试",
"mode": {
"generate": "绘图",
"edit": "编辑",
@ -1386,6 +1388,7 @@
"models.add.group_name.tooltip": "例如 ChatGPT",
"models.add.model_id": "模型 ID",
"models.add.model_id.placeholder": "必填 例如 gpt-3.5-turbo",
"models.add.model_id.select.placeholder": "选择模型",
"models.add.model_id.tooltip": "例如 gpt-3.5-turbo",
"models.add.model_name": "模型名称",
"models.add.model_name.placeholder": "例如 GPT-3.5",

View File

@ -773,6 +773,8 @@
"proxy_required": "目前需要打開代理才能查看生成圖片,後續會支持國內直連",
"image_file_required": "請先上傳圖片",
"image_file_retry": "請重新上傳圖片",
"image_placeholder": "無圖片",
"image_retry": "重試",
"mode": {
"generate": "繪圖",
"edit": "編輯",
@ -1385,6 +1387,7 @@
"models.add.group_name.tooltip": "選填,例如 ChatGPT",
"models.add.model_id": "模型 ID",
"models.add.model_id.placeholder": "必填,例如 gpt-3.5-turbo",
"models.add.model_id.select.placeholder": "選擇模型",
"models.add.model_id.tooltip": "例如 gpt-3.5-turbo",
"models.add.model_name": "模型名稱",
"models.add.model_name.placeholder": "選填,例如 GPT-4",
@ -1667,4 +1670,4 @@
"visualization": "視覺化"
}
}
}
}

View File

@ -223,14 +223,6 @@ const AihubmixPage: FC<{ Options: string[] }> = ({ Options }) => {
const validFiles = downloadedFiles.filter((file): file is FileType => file !== null)
// 如果没有成功下载任何文件但有URLs显示代理提示
if (validFiles.length === 0 && urls.length > 0) {
window.modal.error({
content: t('paintings.proxy_required'),
centered: true
})
}
await FileManager.addFiles(validFiles)
updatePaintingState({ files: validFiles, urls })
@ -249,6 +241,28 @@ const AihubmixPage: FC<{ Options: string[] }> = ({ Options }) => {
}
}
const handleRetry = async (painting: PaintingAction) => {
setIsLoading(true)
const downloadedFiles = await Promise.all(
painting.urls.map(async (url) => {
try {
return await window.api.file.download(url)
} catch (error) {
console.error('下载图像失败:', error)
setIsLoading(false)
return null
}
})
)
const validFiles = downloadedFiles.filter((file): file is FileType => file !== null)
await FileManager.addFiles(validFiles)
updatePaintingState({ files: validFiles, urls: painting.urls })
setIsLoading(false)
}
const onCancel = () => {
abortController?.abort()
}
@ -556,6 +570,7 @@ const AihubmixPage: FC<{ Options: string[] }> = ({ Options }) => {
onPrevImage={prevImage}
onNextImage={nextImage}
onCancel={onCancel}
retry={handleRetry}
/>
<InputContainer>
<Textarea

View File

@ -16,6 +16,7 @@ interface ArtboardProps {
onPrevImage: () => void
onNextImage: () => void
onCancel: () => void
retry?: (painting: Painting) => void
}
const Artboard: FC<ArtboardProps> = ({
@ -24,7 +25,8 @@ const Artboard: FC<ArtboardProps> = ({
currentImageIndex,
onPrevImage,
onNextImage,
onCancel
onCancel,
retry
}) => {
const { t } = useTranslation()
@ -90,7 +92,25 @@ const Artboard: FC<ArtboardProps> = ({
</ImageCounter>
</ImageContainer>
) : (
<ImagePlaceholder />
<ImagePlaceholder>
{painting.urls.length > 0 && retry ? (
<div>
<ImageList>
{painting.urls.map((url) => (
<ImageListItem key={url}>{url}</ImageListItem>
))}
</ImageList>
<div>
{t('paintings.proxy_required')}
<Button type="link" onClick={() => retry?.(painting)}>
{t('paintings.image_retry')}
</Button>
</div>
</div>
) : (
<div>{t('paintings.image_placeholder')}</div>
)}
</ImagePlaceholder>
)}
{isLoading && (
<LoadingOverlay>
@ -118,7 +138,21 @@ const ImagePlaceholder = styled.div`
background-color: var(--color-background-soft);
align-items: center;
justify-content: center;
cursor: pointer;
padding: 24px;
box-sizing: border-box;
`
const ImageList = styled.ul`
list-style: none;
padding: 0;
margin: 0;
word-break: break-all;
user-select: text;
`
const ImageListItem = styled.li`
color: var(--color-text-secondary);
margin-bottom: 10px;
`
const ImageContainer = styled.div`

View File

@ -41,12 +41,12 @@ export const createModeConfigs = (): Record<AihubmixMode, ConfigItem[]> => {
type: 'select',
key: 'model',
options: [
{ label: 'V_1', value: 'V_1' },
{ label: 'V_1_TURBO', value: 'V_1_TURBO' },
{ label: 'V_2', value: 'V_2' },
{ label: 'V_2_TURBO', value: 'V_2_TURBO' },
{ label: 'V_2A', value: 'V_2A' },
{ label: 'V_2A_TURBO', value: 'V_2A_TURBO' }
{ label: 'ideogram_V_1', value: 'V_1' },
{ label: 'ideogram_V_1_TURBO', value: 'V_1_TURBO' },
{ label: 'ideogram_V_2', value: 'V_2' },
{ label: 'ideogram_V_2_TURBO', value: 'V_2_TURBO' },
{ label: 'ideogram_V_2A', value: 'V_2A' },
{ label: 'ideogram_V_2A_TURBO', value: 'V_2A_TURBO' }
]
},
{ type: 'title', title: 'paintings.aspect_ratio' },
@ -119,8 +119,8 @@ export const createModeConfigs = (): Record<AihubmixMode, ConfigItem[]> => {
type: 'select',
key: 'model',
options: [
{ label: 'V_2', value: 'V_2' },
{ label: 'V_2_TURBO', value: 'V_2_TURBO' }
{ label: 'ideogram_V_2', value: 'V_2' },
{ label: 'ideogram_V_2_TURBO', value: 'V_2_TURBO' }
]
},
{
@ -174,12 +174,12 @@ export const createModeConfigs = (): Record<AihubmixMode, ConfigItem[]> => {
type: 'select',
key: 'model',
options: [
{ label: 'V_1', value: 'V_1' },
{ label: 'V_1_TURBO', value: 'V_1_TURBO' },
{ label: 'V_2', value: 'V_2' },
{ label: 'V_2_TURBO', value: 'V_2_TURBO' },
{ label: 'V_2A', value: 'V_2A' },
{ label: 'V_2A_TURBO', value: 'V_2A_TURBO' }
{ label: 'ideogram_V_1', value: 'V_1' },
{ label: 'ideogram_V_1_TURBO', value: 'V_1_TURBO' },
{ label: 'ideogram_V_2', value: 'V_2' },
{ label: 'ideogram_V_2_TURBO', value: 'V_2_TURBO' },
{ label: 'ideogram_V_2A', value: 'V_2A' },
{ label: 'ideogram_V_2A_TURBO', value: 'V_2A_TURBO' }
]
},
{ type: 'title', title: 'paintings.aspect_ratio' },