Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat(web): Image-to-Image AI Generation (#293)
布莱恩·奥夫托·杰森张313d038b7e99
diff --git a/project/web/src/app/i18n/locales/en/publish.json b/project/web/src/app/i18n/locales/en/publish.jsonindex 37a1d75b..a5e370bd 100644--- a/project/web/src/app/i18n/locales/en/publish.json+++ b/project/web/src/app/i18n/locales/en/publish.json@@ -82,6 +82,7 @@"polish": "Polish","translate": "Translate","generateImage": "Image",+ "imageToImage": "Image to Image","generateVideo": "Video","generateHashtags": "Hashtags","syncToEditor": "Sync to Editor",@@ -95,6 +96,7 @@"polish": "Please polish the following text to make it more fluent and professional:","translate": "You are a translator. If the content below is in Chinese, translate it to English. If it's in English, translate it to Chinese. Only output the translation result without other explanations.","generateImage": "Please generate an image based on the content provided below. The image must be relevant to the content, small, and generated quickly.",+ "imageToImage": "Generate a new image based on the image I provided and the user's requirements.","generateVideo": "Generate video creation prompts based on the content I provide below. Ensure the content is suitable for publishing and contains no violations.","generateHashtags": "Generate 3-6 hashtags with # based on the content provided below. If it's Chinese content, reply with Chinese hashtags; if English content, reply with English hashtags. If indistinguishable, prefer English hashtags. Only reply with hashtags, no other text."},@@ -140,6 +142,14 @@"videoProcessingFailed": "Video processing failed, please retry","imageProcessingFailed": "Image {{index}} processing failed: {{error}}","videoReady": "✅ Video ready!",+ "uploadImage": "Upload Image",+ "removeImage": "Remove Image",+ "uploadImageFirst": "Please upload an image first",+ "imageUploading": "Image uploading, please wait...",+ "imageUploadFailed": "Image upload failed, please retry",+ "imageUploadSuccess": "Image uploaded successfully",+ "uploading": "Uploading...",+ "uploadSuccess": "Upload successful","customPrompts": {"title": "Custom Prompts","description": "Configure custom prompts for each feature. Leave empty to use default behavior (no additional prompts).",diff --git a/project/web/src/app/i18n/locales/zh-CN/publish.json b/project/web/src/app/i18n/locales/zh-CN/publish.jsonindex fc8263e7..4fed7cb8 100644--- a/project/web/src/app/i18n/locales/zh-CN/publish.json+++ b/project/web/src/app/i18n/locales/zh-CN/publish.json@@ -83,6 +83,7 @@"polish": "润色","translate": "翻译","generateImage": "制图",+ "imageToImage": "图生图","generateVideo": "创作视频","generateHashtags": "生成话题","syncToEditor": "同步到编辑器",@@ -96,6 +97,7 @@"polish": "请润色以下文本,使其更加流畅和专业:","translate": "你现在是个翻译。如果下面内容是中文,请翻译成英文。如果下面内容是英文,请翻译成中文。只输出翻译结果,不要有其他解释。","generateImage": "根据我下面提供的内容生成图片,必须生成一张与内容相关的图片。",+ "imageToImage": "根据用户给出的图片和用户要求生成新的图片。","generateVideo": "根据我下面提供的内容生成视频创作提示词,确保内容适合发布且不含违规内容。","generateHashtags": "请按照下面给的内容生成带#的话题生成3-6个,如果是中文内容回复中文话题如果是英文内容回复英文话题,无法区分的优先英文话题,只要回复话题不要其他任何回复"},@@ -141,6 +143,14 @@"videoProcessingFailed": "视频处理失败,请重试","imageProcessingFailed": "图片 {{index}} 处理失败: {{error}}","videoReady": "✅ 视频生成完成!",+ "uploadImage": "上传图片",+ "removeImage": "移除图片",+ "uploadImageFirst": "请先上传图片",+ "imageUploading": "图片上传中,请稍候...",+ "imageUploadFailed": "图片上传失败,请重试",+ "imageUploadSuccess": "图片上传成功",+ "uploading": "上传中...",+ "uploadSuccess": "上传成功","customPrompts": {"title": "自定义提示词","description": "为每个功能配置自定义提示词。留空则使用默认行为(不添加额外提示词)。",diff --git a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/hooks/usePlatParamsCoomon.tsx b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/hooks/usePlatParamsCoomon.tsxindex 62b841d7..da21f5b1 100644--- a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/hooks/usePlatParamsCoomon.tsx+++ b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/hooks/usePlatParamsCoomon.tsx@@ -2,14 +2,14 @@ import type {IChangeParams,IPubParmasTextareaProps,} from '@/components/PublishDialog/compoents/PubParmasTextarea'-import type { PubItem } from '@/components/PublishDialog/publishDialog.type'+import type { IImgFile, PubItem } from '@/components/PublishDialog/publishDialog.type'import { Alert } from 'antd'import { useCallback, useMemo } from 'react'import { useShallow } from 'zustand/react/shallow'import { PubParamsVerifyInfo } from '@/components/PublishDialog/hooks/usePubParamsVerify'import { usePublishDialog } from '@/components/PublishDialog/usePublishDialog'-export default function usePlatParamsCommon(pubItem: PubItem) {+export default function usePlatParamsCommon(pubItem: PubItem, onImageToImage?: (imageFile: IImgFile) => void) {const { setOnePubParams, errParamsMap, pubListChoosed, warningParamsMap }= usePublishDialog(useShallow(state => ({@@ -52,6 +52,7 @@ export default function usePlatParamsCommon(pubItem: PubItem) {desValue: pubItem.params.des,imageFileListValue: pubItem.params.images,videoFileValue: pubItem.params.video,+ onImageToImage,beforeExtend: (<><PubParamsVerifyInfo errItem={currErrItem} />@@ -73,7 +74,7 @@ export default function usePlatParamsCommon(pubItem: PubItem) {),}return props- }, [currErrItem, onChange, pubItem, currWarningItem])+ }, [currErrItem, onChange, pubItem, currWarningItem, onImageToImage])return { pubParmasTextareaCommonParams, setOnePubParams }}diff --git a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/index.tsx b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/index.tsxindex 89395516..7a48449a 100644--- a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/index.tsx+++ b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/index.tsx@@ -1,5 +1,5 @@import type { CSSProperties, ForwardedRef } from 'react'-import type { PubItem } from '@/components/PublishDialog/publishDialog.type'+import type { IImgFile, PubItem } from '@/components/PublishDialog/publishDialog.type'import { forwardRef, memo, useMemo } from 'react'import { useShallow } from 'zustand/react/shallow'import { AccountPlatInfoMap, PlatType } from '@/app/config/platConfig'@@ -21,12 +21,13 @@ export interface IPlatParamsSettingRef {}export interface IPlatParamsSettingProps {pubItem: PubItemstyle?: CSSProperties+ onImageToImage?: (imageFile: IImgFile) => void}const PlatParamsSetting = memo(forwardRef((- { pubItem, style }: IPlatParamsSettingProps,+ { pubItem, style, onImageToImage }: IPlatParamsSettingProps,ref: ForwardedRef<IPlatParamsSettingRef>,) => {const { expandedPubItem, step, setExpandedPubItem } = usePublishDialog(@@ -45,27 +46,27 @@ const PlatParamsSetting = memo(const PlatItemComp = useMemo(() => {switch (pubItem.account.type) {case PlatType.KWAI:- return <KwaiParams pubItem={pubItem} />+ return <KwaiParams pubItem={pubItem} onImageToImage={onImageToImage} />case PlatType.BILIBILI:- return <BilibParams pubItem={pubItem} />+ return <BilibParams pubItem={pubItem} onImageToImage={onImageToImage} />case PlatType.WxGzh:- return <WxGzhParams pubItem={pubItem} />+ return <WxGzhParams pubItem={pubItem} onImageToImage={onImageToImage} />case PlatType.Facebook:- return <FacebookParams pubItem={pubItem} />+ return <FacebookParams pubItem={pubItem} onImageToImage={onImageToImage} />case PlatType.Instagram:- return <InstagramParams pubItem={pubItem} />+ return <InstagramParams pubItem={pubItem} onImageToImage={onImageToImage} />case PlatType.YouTube:- return <YouTubeParams pubItem={pubItem} />+ return <YouTubeParams pubItem={pubItem} onImageToImage={onImageToImage} />case PlatType.Pinterest:- return <PinterestParams pubItem={pubItem} />+ return <PinterestParams pubItem={pubItem} onImageToImage={onImageToImage} />case PlatType.Tiktok:- return <TikTokParams pubItem={pubItem} />+ return <TikTokParams pubItem={pubItem} onImageToImage={onImageToImage} />case PlatType.Threads:- return <ThreadsParams pubItem={pubItem} />+ return <ThreadsParams pubItem={pubItem} onImageToImage={onImageToImage} />default:- return <KwaiParams pubItem={pubItem} />+ return <KwaiParams pubItem={pubItem} onImageToImage={onImageToImage} />}- }, [pubItem])+ }, [pubItem, onImageToImage])// true=展开当前账号的参数设置 false=不展开const isExpand = useMemo(() => {diff --git a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/BilibParams.tsx b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/BilibParams.tsxindex daa1553b..830218c7 100644--- a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/BilibParams.tsx+++ b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/BilibParams.tsx@@ -15,10 +15,10 @@ import styles from '../platParamsSetting.module.scss'const BilibParams = memo(forwardRef(- ({ pubItem }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {+ ({ pubItem, onImageToImage }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {const { t } = useTransClient('publish')const { pubParmasTextareaCommonParams, setOnePubParams }- = usePlatParamsCommon(pubItem)+ = usePlatParamsCommon(pubItem, onImageToImage)const { getBilibiliPartitions, bilibiliPartitions }= usePublishDialogData(useShallow(state => ({diff --git a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/FacebookParams.tsx b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/FacebookParams.tsxindex f09e6ba4..09b3fab8 100644--- a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/FacebookParams.tsx+++ b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/FacebookParams.tsx@@ -12,10 +12,10 @@ import styles from '../platParamsSetting.module.scss'const FacebookParams = memo(forwardRef(- ({ pubItem }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {+ ({ pubItem, onImageToImage }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {const { t } = useTransClient('publish')const { pubParmasTextareaCommonParams, setOnePubParams }- = usePlatParamsCommon(pubItem)+ = usePlatParamsCommon(pubItem, onImageToImage)// 初始化Facebook参数useEffect(() => {diff --git a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/InstagramParams.tsx b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/InstagramParams.tsxindex 92a286e7..58baf3ff 100644--- a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/InstagramParams.tsx+++ b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/InstagramParams.tsx@@ -13,10 +13,10 @@ import styles from '../platParamsSetting.module.scss'const InstagramParams = memo(forwardRef(- ({ pubItem }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {+ ({ pubItem, onImageToImage }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {const { t } = useTransClient('publish')const { pubParmasTextareaCommonParams, setOnePubParams }- = usePlatParamsCommon(pubItem)+ = usePlatParamsCommon(pubItem, onImageToImage)// 初始化Instagram参数useEffect(() => {diff --git a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/KwaiParams.tsx b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/KwaiParams.tsxindex d61cce4f..0cace382 100644--- a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/KwaiParams.tsx+++ b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/KwaiParams.tsx@@ -9,8 +9,8 @@ import PubParmasTextarea from '@/components/PublishDialog/compoents/PubParmasTexconst KwaiParams = memo(forwardRef(- ({ pubItem }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {- const { pubParmasTextareaCommonParams } = usePlatParamsCommon(pubItem)+ ({ pubItem, onImageToImage }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {+ const { pubParmasTextareaCommonParams } = usePlatParamsCommon(pubItem, onImageToImage)return (<>diff --git a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/PinterestParams.tsx b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/PinterestParams.tsxindex 4c2a142a..5cd4896c 100644--- a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/PinterestParams.tsx+++ b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/PinterestParams.tsx@@ -32,10 +32,10 @@ const tooltipStyles = `const PinterestParams = memo(forwardRef(- ({ pubItem }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {+ ({ pubItem, onImageToImage }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {const { t } = useTransClient('pinterest')const { pubParmasTextareaCommonParams, setOnePubParams }- = usePlatParamsCommon(pubItem)+ = usePlatParamsCommon(pubItem, onImageToImage)const { getPinterestBoards, pinterestBoards }= usePublishDialogData(useShallow(state => ({diff --git a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/ThreadsParams.tsx b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/ThreadsParams.tsxindex 5d64c74f..4bcd1d61 100644--- a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/ThreadsParams.tsx+++ b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/ThreadsParams.tsx@@ -18,10 +18,10 @@ const { Search } = Inputconst ThreadsParams = memo(forwardRef(- ({ pubItem }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {+ ({ pubItem, onImageToImage }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {const { t } = useTransClient('publish')const { pubParmasTextareaCommonParams, setOnePubParams }- = usePlatParamsCommon(pubItem)+ = usePlatParamsCommon(pubItem, onImageToImage)const [locations, setLocations] = useState<ThreadsLocationItem[]>([])const [loading, setLoading] = useState(false)diff --git a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/TikTokParams.tsx b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/TikTokParams.tsxindex bcc6f183..6398f854 100644--- a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/TikTokParams.tsx+++ b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/TikTokParams.tsx@@ -26,10 +26,10 @@ interface TikTokCreatorInfo {const TikTokParams = memo(forwardRef(- ({ pubItem }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {+ ({ pubItem, onImageToImage }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {const { t } = useTransClient('publish')const { pubParmasTextareaCommonParams, setOnePubParams }- = usePlatParamsCommon(pubItem)+ = usePlatParamsCommon(pubItem, onImageToImage)const [creatorInfo, setCreatorInfo] = useState<TikTokCreatorInfo | null>(null)const [loading, setLoading] = useState(false)diff --git a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/WxGzhParams.tsx b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/WxGzhParams.tsxindex 14b97e75..e3310514 100644--- a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/WxGzhParams.tsx+++ b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/WxGzhParams.tsx@@ -12,9 +12,9 @@ import styles from '../platParamsSetting.module.scss'* - 独立参数:title(与通用 title 区分,使用 option.wxGzh.title 保存)*/const WxGzhParams = memo(- forwardRef(({ pubItem }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {+ forwardRef(({ pubItem, onImageToImage }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {const { t } = useTransClient('publish')- const { pubParmasTextareaCommonParams, setOnePubParams } = usePlatParamsCommon(pubItem)+ const { pubParmasTextareaCommonParams, setOnePubParams } = usePlatParamsCommon(pubItem, onImageToImage)// 初始化 wxGzh 参数对象// useEffect(() => {diff --git a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/YouTubeParams.tsx b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/YouTubeParams.tsxindex a2006bf8..28d5a7ce 100644--- a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/YouTubeParams.tsx+++ b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/YouTubeParams.tsx@@ -16,10 +16,10 @@ import styles from '../platParamsSetting.module.scss'const YouTubeParams = memo(forwardRef(- ({ pubItem }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {+ ({ pubItem, onImageToImage }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {const { t } = useTransClient('publish')const { pubParmasTextareaCommonParams, setOnePubParams }- = usePlatParamsCommon(pubItem)+ = usePlatParamsCommon(pubItem, onImageToImage)const {getYouTubeCategories,youTubeCategories,diff --git a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/plats.type.ts b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/plats.type.tsindex 787f0f7c..79b63f2c 100644--- a/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/plats.type.ts+++ b/project/web/src/components/PublishDialog/compoents/PlatParamsSetting/plats/plats.type.ts@@ -1,7 +1,8 @@-import type { PubItem } from '@/components/PublishDialog/publishDialog.type'+import type { IImgFile, PubItem } from '@/components/PublishDialog/publishDialog.type'export interface IPlatsParamsRef {}export interface IPlatsParamsProps {pubItem: PubItem+ onImageToImage?: (imageFile: IImgFile) => void}diff --git a/project/web/src/components/PublishDialog/compoents/PubParmasTextarea/PubParmasTextuploadImage.tsx b/project/web/src/components/PublishDialog/compoents/PubParmasTextarea/PubParmasTextuploadImage.tsxindex 14646c66..154aed2c 100644--- a/project/web/src/components/PublishDialog/compoents/PubParmasTextarea/PubParmasTextuploadImage.tsx+++ b/project/web/src/components/PublishDialog/compoents/PubParmasTextarea/PubParmasTextuploadImage.tsx@@ -1,6 +1,6 @@import type { ForwardedRef } from 'react'import type { IImgFile } from '@/components/PublishDialog/publishDialog.type'-import { CloseOutlined, EditOutlined } from '@ant-design/icons'+import { CloseOutlined, EditOutlined, PictureOutlined } from '@ant-design/icons'import { Button, Tooltip } from 'antd'import React, { forwardRef, memo } from 'react'import { useTranslation } from 'react-i18next'@@ -13,6 +13,7 @@ export interface IPubParmasTextuploadImageProps {onClick: () => voidimageFile: IImgFileonEditClick: () => void+ onImageToImageClick?: () => void}const PubParmasTextuploadImage = memo(@@ -23,6 +24,7 @@ const PubParmasTextuploadImage = memo(onClose,imageFile,onEditClick,+ onImageToImageClick,}: IPubParmasTextuploadImageProps,ref: ForwardedRef<IPubParmasTextuploadImageRef>,) => {@@ -44,17 +46,46 @@ const PubParmasTextuploadImage = memo(<img src={imageFile.imgUrl} alt="preview" /></Tooltip>- <Tooltip title="Edit">- <Button- className="pubParmasTextarea-uploads-item-edit"- icon={<EditOutlined />}- size="small"- onClick={(e) => {- e.stopPropagation()- onEditClick()- }}- />- </Tooltip>+ <div style={{+ position: 'absolute',+ bottom: 8,+ right: 8,+ display: 'flex',+ gap: 4,+ zIndex: 1+ }}>+ <Tooltip title="Edit">+ <Button+ icon={<EditOutlined />}+ size="small"+ onClick={(e) => {+ e.stopPropagation()+ onEditClick()+ }}+ style={{+ minWidth: 'auto',+ padding: '4px 8px'+ }}+ />+ </Tooltip>++ {onImageToImageClick && (+ <Tooltip title={t('aiFeatures.imageToImage' as any)}>+ <Button+ icon={<PictureOutlined />}+ size="small"+ onClick={(e) => {+ e.stopPropagation()+ onImageToImageClick()+ }}+ style={{+ minWidth: 'auto',+ padding: '4px 8px'+ }}+ />+ </Tooltip>+ )}+ </div>{imageFile.uploadTaskId && (<PublishUploadProgress taskId={imageFile.uploadTaskId} />diff --git a/project/web/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsx b/project/web/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsxindex d540cf41..f727efd6 100644--- a/project/web/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsx+++ b/project/web/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsx@@ -68,6 +68,8 @@ export interface IPubParmasTextareaProps {imageFileListValue?: IImgFile[]videoFileValue?: IVideoFiledesValue?: string+ // 图生图回调+ onImageToImage?: (imageFile: IImgFile) => void}const ImageEditorModal = dynamic(@@ -90,6 +92,7 @@ const PubParmasTextarea = memo(desValue = '',beforeExtend,platType,+ onImageToImage,}: IPubParmasTextareaProps,ref: ForwardedRef<IPubParmasTextareaRef>,) => {@@ -397,6 +400,9 @@ const PubParmasTextarea = memo(return newState})}}+ onImageToImageClick={onImageToImage ? () => {+ onImageToImage(v)+ } : undefined}/></CSSTransition>))}diff --git a/project/web/src/components/PublishDialog/compoents/PublishDialogAi.tsx b/project/web/src/components/PublishDialog/compoents/PublishDialogAi.tsxindex 47bdb0ad..8e928135 100644--- a/project/web/src/components/PublishDialog/compoents/PublishDialogAi.tsx+++ b/project/web/src/components/PublishDialog/compoents/PublishDialogAi.tsx@@ -18,6 +18,7 @@ import { forwardRef, memo, useCallback, useImperativeHandle, useRef, useEffect,import ReactMarkdown from 'react-markdown'import { useTransClient } from '@/app/i18n/client'import { aiChatStream, getVideoGenerationModels, generateVideo, getVideoTaskStatus } from '@/api/ai'+import { uploadToOss } from '@/api/oss'import { formatImg, VideoGrabFrame } from '@/components/PublishDialog/PublishDialog.util'import type { IImgFile, IVideoFile } from '@/components/PublishDialog/publishDialog.type'import { getOssUrl } from '@/utils/oss'@@ -48,6 +49,8 @@ const { Option } = Selectexport interface IPublishDialogAiRef {// AI text processingprocessText: (text: string, action: AIAction) => void+ // Image to image processing+ processImageToImage: (imageFile: File, prompt?: string) => void}export interface IPublishDialogAiProps {@@ -59,7 +62,7 @@ export interface IPublishDialogAiProps {chatModels?: any[]}-export type AIAction = 'shorten' | 'expand' | 'polish' | 'translate' | 'generateImage' | 'generateVideo' | 'generateHashtags'+export type AIAction = 'shorten' | 'expand' | 'polish' | 'translate' | 'generateImage' | 'generateVideo' | 'generateHashtags' | 'imageToImage'interface Message {role: 'user' | 'assistant'@@ -346,6 +349,9 @@ const PublishDialogAi = memo(const [videoStatus, setVideoStatus] = useState<string>('')const [videoProgress, setVideoProgress] = useState(0)const [videoResult, setVideoResult] = useState<string | null>(null)++ // Image to image state+ const [uploadedImage, setUploadedImage] = useState<{ file: File; preview: string; ossUrl?: string; uploading?: boolean } | null>(null)// Auto-scroll to bottomuseEffect(() => {@@ -620,7 +626,7 @@ const PublishDialogAi = memo(// Handle AI responseconst handleAIResponse = useCallback(async (action: AIAction,- apiMessages: Array<{ role: string, content: string }>,+ apiMessages: Array<{ role: string, content: string | Array<any> }>,) => {try {setIsProcessing(true)@@ -629,11 +635,11 @@ const PublishDialogAi = memo(const placeholderMsg: Message = { role: 'assistant', content: '', action }setMessages(prev => [...prev, placeholderMsg])- // Select model based on action- const modelToUse = action === 'generateImage' ? selectedImageModel : selectedChatModel+ // Select model based on action (use image model for both generateImage and imageToImage)+ const modelToUse = (action === 'generateImage' || action === 'imageToImage') ? selectedImageModel : selectedChatModelconst response = await aiChatStream({- messages: apiMessages,+ messages: apiMessages as any,model: modelToUse})@@ -725,7 +731,41 @@ const PublishDialogAi = memo(// Handle action button clickconst handleActionClick = useCallback((action: AIAction) => {setActiveAction(action)+ // Clear uploaded image when switching to non-imageToImage actions+ if (action !== 'imageToImage') {+ setUploadedImage(null)+ }}, [])++ // Handle image upload for image-to-image+ const handleImageUpload = useCallback(async (file: File) => {+ try {+ // First create preview for display+ const reader = new FileReader()+ reader.onload = async (e) => {+ const preview = e.target?.result as string+ setUploadedImage({ file, preview, uploading: true })++ try {+ // Upload to OSS+ const ossKey = await uploadToOss(file)+ const ossUrl = `${OSS_URL}${ossKey}`++ // Update with OSS URL+ setUploadedImage({ file, preview, ossUrl, uploading: false })+ message.success(t('aiFeatures.imageUploadSuccess' as any))+ } catch (error) {+ console.error('Upload to OSS failed:', error)+ message.error(t('aiFeatures.imageUploadFailed' as any))+ setUploadedImage(null)+ }+ }+ reader.readAsDataURL(file)+ } catch (error) {+ console.error('Failed to read image:', error)+ message.error(t('aiFeatures.imageUploadFailed' as any))+ }+ }, [t])// 发送消息const sendMessage = useCallback(async (content?: string, forceAction?: AIAction) => {@@ -738,10 +778,31 @@ const PublishDialogAi = memo(// Use passed action or current state actionconst currentAction = forceAction || activeAction+ // Check if image is required for imageToImage action+ if (currentAction === 'imageToImage' && !uploadedImage) {+ message.warning(t('aiFeatures.uploadImageFirst' as any))+ return+ }++ // Check if image is still uploading+ if (currentAction === 'imageToImage' && uploadedImage?.uploading) {+ message.warning(t('aiFeatures.imageUploading' as any))+ return+ }++ // Check if image has OSS URL+ if (currentAction === 'imageToImage' && uploadedImage && !uploadedImage.ossUrl) {+ message.error(t('aiFeatures.imageUploadFailed' as any))+ return+ }+// Add user messageconst userMessage: Message = { role: 'user', content: messageContent, action: currentAction || undefined }setMessages(prev => [...prev, userMessage])+ // Save uploaded image reference before clearing+ const savedUploadedImage = uploadedImage+// Call video generation directly if it's video generationif (currentAction === 'generateVideo') {await handleVideoGeneration(messageContent)@@ -769,6 +830,9 @@ const PublishDialogAi = memo(case 'generateImage':systemPrompt = t('aiFeatures.defaultPrompts.generateImage' as any)break+ case 'imageToImage':+ systemPrompt = t('aiFeatures.defaultPrompts.imageToImage' as any)+ breakcase 'generateHashtags':systemPrompt = t('aiFeatures.defaultPrompts.generateHashtags' as any)break@@ -776,7 +840,7 @@ const PublishDialogAi = memo(}// Prepare API messages- const apiMessages: Array<{ role: string, content: string }> = []+ const apiMessages: Array<{ role: string, content: string | Array<any> }> = []// Add default system prompt if existsif (systemPrompt) {@@ -789,14 +853,37 @@ const PublishDialogAi = memo(apiMessages.push({ role: 'system', content: userCustomPrompt })}- apiMessages.push({ role: 'user', content: messageContent })+ // For imageToImage, add image data to user message (use saved reference)+ if (currentAction === 'imageToImage' && savedUploadedImage && savedUploadedImage.ossUrl) {+ apiMessages.push({+ role: 'user',+ content: [+ {+ type: 'image_url',+ image_url: {+ url: savedUploadedImage.ossUrl+ }+ },+ {+ type: 'text',+ text: messageContent+ }+ ]+ })+ } else {+ apiMessages.push({ role: 'user', content: messageContent })+ }++ // Clear input and uploaded image immediately+ setInputValue('')+ if (currentAction === 'imageToImage') {+ setUploadedImage(null)+ setActiveAction(null) // Clear active action after sending imageToImage+ }// Call AI interfaceawait handleAIResponse(currentAction || 'polish', apiMessages)-- // Clear input- setInputValue('')- }, [activeAction, inputValue, customPrompts, handleAIResponse, handleVideoGeneration, t])+ }, [activeAction, inputValue, customPrompts, uploadedImage, handleAIResponse, handleVideoGeneration, t])// Download image from URL and convert to IImgFile objectconst downloadImageAsImgFile = async (url: string, index: number): Promise<IImgFile | null> => {@@ -1010,7 +1097,14 @@ const PublishDialogAi = memo(sendMessage(text, action) // Pass action parameter}, 50)},- }), [sendMessage])+ processImageToImage: (imageFile: File, prompt?: string) => {+ setActiveAction('imageToImage')+ handleImageUpload(imageFile)+ if (prompt) {+ setInputValue(prompt)+ }+ },+ }), [sendMessage, handleImageUpload])const actionButtons = [{ action: 'shorten', icon: <CompressOutlined />, label: t('aiFeatures.shorten' as any) },@@ -1018,6 +1112,7 @@ const PublishDialogAi = memo({ action: 'polish', icon: <EditOutlined />, label: t('aiFeatures.polish' as any) },{ action: 'translate', icon: <TranslationOutlined />, label: t('aiFeatures.translate' as any) },{ action: 'generateImage', icon: <PictureOutlined />, label: t('aiFeatures.generateImage' as any) },+ { action: 'imageToImage', icon: <PictureOutlined />, label: t('aiFeatures.imageToImage' as any) },{ action: 'generateVideo', icon: <VideoCameraOutlined />, label: t('aiFeatures.generateVideo' as any) },{ action: 'generateHashtags', icon: <TagsOutlined />, label: t('aiFeatures.generateHashtags' as any) },]@@ -1129,35 +1224,159 @@ const PublishDialogAi = memo(</div>{/* Action buttons area */}- <div style={{- display: 'flex',- gap: 8,- marginBottom: 8,- padding: '8px',- background: '#fafafa',- borderRadius: '8px',- justifyContent: 'space-between',- alignItems: 'center',- }}>- <div style={{ display: 'flex', gap: 8, flex: 1, flexWrap: 'wrap' }}>- {actionButtons.map(({ action, icon, label }) => (- <Tooltip key={action} title={label}>- <Button- type={activeAction === action ? 'primary' : 'default'}- icon={icon}- onClick={() => handleActionClick(action as AIAction)}- size="small"- />- </Tooltip>- ))}+ <div style={{ position: 'relative' }}>+ {/* Image upload area for imageToImage - positioned above buttons */}+ {activeAction === 'imageToImage' && (+ <div style={{+ position: 'absolute',+ bottom: '100%',+ left: '120px',+ right: 0,+ marginBottom: 10,+ display: 'flex',+ gap: 8,+ flexWrap: 'wrap'+ }}>+ {/* Uploaded image preview */}+ {uploadedImage && (+ <div style={{+ position: 'relative',+ display: 'inline-block',+ borderRadius: '8px',+ overflow: 'hidden'+ }}>+ <img+ src={uploadedImage.preview}+ alt="Uploaded"+ style={{+ width: '120px',+ height: '80px',+ borderRadius: '8px',+ display: 'block',+ objectFit: 'cover',+ opacity: uploadedImage.uploading ? 0.5 : 1+ }}+ />+ {uploadedImage.uploading && (+ <div style={{+ position: 'absolute',+ top: '50%',+ left: '50%',+ transform: 'translate(-50%, -50%)'+ }}>+ <Spin />+ </div>+ )}+ {/* Close button */}+ <Button+ type="text"+ danger+ size="small"+ icon={<CloseCircleFilled />}+ onClick={() => setUploadedImage(null)}+ disabled={uploadedImage.uploading}+ style={{+ position: 'absolute',+ top: 4,+ right: 4,+ minWidth: 'auto',+ padding: 0,+ width: 20,+ height: 20,+ display: 'flex',+ alignItems: 'center',+ justifyContent: 'center',+ background: 'rgba(0, 0, 0, 0.5)',+ color: '#fff',+ border: 'none'+ }}+ />+ </div>+ )}++ {/* Upload box - show when no image */}+ {!uploadedImage && (+ <>+ <input+ type="file"+ accept="image/*"+ onChange={(e) => {+ const file = e.target.files?.[0]+ if (file) {+ handleImageUpload(file)+ }+ }}+ style={{ display: 'none' }}+ id="imageToImageUpload"+ />+ <label+ htmlFor="imageToImageUpload"+ style={{+ margin: 0,+ cursor: 'pointer'+ }}+ >+ <div style={{+ width: '120px',+ height: '80px',+ border: '2px dashed #d9d9d9',+ borderRadius: '8px',+ display: 'flex',+ flexDirection: 'column',+ alignItems: 'center',+ justifyContent: 'center',+ background: '#fafafa',+ transition: 'all 0.3s',+ color: '#999'+ }}+ onMouseEnter={(e) => {+ e.currentTarget.style.borderColor = '#1890ff'+ e.currentTarget.style.color = '#1890ff'+ }}+ onMouseLeave={(e) => {+ e.currentTarget.style.borderColor = '#d9d9d9'+ e.currentTarget.style.color = '#999'+ }}+ >+ <PictureOutlined style={{ fontSize: '24px', marginBottom: '4px' }} />+ <span style={{ fontSize: '12px' }}>{t('aiFeatures.uploadImage' as any)}</span>+ </div>+ </label>+ </>+ )}+ </div>+ )}++ <div style={{+ display: 'flex',+ gap: 8,+ marginBottom: 8,+ padding: '8px',+ background: '#fafafa',+ borderRadius: '8px',+ justifyContent: 'space-between',+ alignItems: 'center',+ }}>+ <div style={{ display: 'flex', gap: 8, flex: 1, flexWrap: 'wrap' }}>+ {actionButtons.map(({ action, icon, label }) => (+ <Tooltip key={action} title={label}>+ <Button+ type={activeAction === action ? 'primary' : 'default'}+ icon={icon}+ onClick={() => handleActionClick(action as AIAction)}+ size="small"+ />+ </Tooltip>+ ))}+ </div>+ <Tooltip title={t('aiFeatures.settings' as any)}>+ <Button+ icon={<SettingOutlined />}+ onClick={() => setSettingsVisible(true)}+ size="small"+ />+ </Tooltip></div>- <Tooltip title={t('aiFeatures.settings' as any)}>- <Button- icon={<SettingOutlined />}- onClick={() => setSettingsVisible(true)}- size="small"- />- </Tooltip></div>{/* Input area */}@@ -1443,6 +1662,25 @@ const PublishDialogAi = memo(/></div>+ {/* Image to Image */}+ <div style={{ marginBottom: 16 }}>+ <div style={{ marginBottom: 4, fontWeight: 500, fontSize: '13px' }}>+ <PictureOutlined style={{ marginRight: 4 }} />+ {t('aiFeatures.imageToImage' as any)}+ </div>+ <Input.TextArea+ value={customPrompts.imageToImage || ''}+ onChange={(e) => {+ const newPrompts = { ...customPrompts, imageToImage: e.target.value }+ setCustomPrompts(newPrompts)+ localStorage.setItem('ai_custom_prompts', JSON.stringify(newPrompts))+ }}+ placeholder={t('aiFeatures.customPrompts.placeholder' as any)}+ rows={2}+ style={{ fontSize: '12px' }}+ />+ </div>+{/* Generate Video */}<div style={{ marginBottom: 16 }}><div style={{ marginBottom: 4, fontWeight: 500, fontSize: '13px' }}>diff --git a/project/web/src/components/PublishDialog/index.tsx b/project/web/src/components/PublishDialog/index.tsxindex 81c4dac7..4b717fa2 100644--- a/project/web/src/components/PublishDialog/index.tsx+++ b/project/web/src/components/PublishDialog/index.tsx@@ -601,6 +601,18 @@ const PublishDialog = memo(aiAssistantRef.current?.processText(selectedText, action)}, openLeft ? 100 : 500) // 如果已打开,减少延迟}, [openLeft, setOpenLeft])++ // 处理图生图+ const handleImageToImage = useCallback((imageFile: IImgFile) => {+ // 打开AI面板+ if (!openLeft) {+ setOpenLeft(true)+ }+ // 等待面板打开动画完成后调用图生图功能+ setTimeout(() => {+ aiAssistantRef.current?.processImageToImage(imageFile.file, '')+ }, openLeft ? 100 : 500)+ }, [openLeft, setOpenLeft])// AI内容同步到编辑器const handleSyncToEditor = useCallback(async (content: string, images?: IImgFile[], video?: IVideoFile, append?: boolean) => {@@ -980,7 +992,7 @@ const PublishDialog = memo(? (<>{pubListChoosed.length == 1 && (- <PlatParamsSetting pubItem={pubListChoosed[0]} />+ <PlatParamsSetting pubItem={pubListChoosed[0]} onImageToImage={handleImageToImage} />)}{pubListChoosed.length >= 2 && (<PubParmasTextarea@@ -997,6 +1009,7 @@ const PublishDialog = memo(video: values.video,})}}+ onImageToImage={handleImageToImage}/>)}</>@@ -1009,6 +1022,7 @@ const PublishDialog = memo(pubItem={v}key={v.account.id}style={{ marginBottom: '12px' }}+ onImageToImage={handleImageToImage}/>)})}