Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
fix(web): denglutanchuang (#358)
布莱恩·奥夫托·杰森张1b6ce93343b3
diff --git a/project/web/src/api/agent.ts b/project/web/src/api/agent.tsindex 9018bbae..d67f3bb4 100644--- a/project/web/src/api/agent.ts+++ b/project/web/src/api/agent.ts@@ -200,7 +200,7 @@ export const agentApi = {* @param taskId 任务ID*/async getTaskDetail(taskId: string) {- const res = await http.get<TaskDetail>(`agent/tasks/${taskId}`)+ const res = await http.get<TaskDetail>(`${'https://pr-211.preview.aitoearn.ai/api/'}agent/tasks/${taskId}`)return res},}diff --git a/project/web/src/app/[lng]/accounts/accountCore.tsx b/project/web/src/app/[lng]/accounts/accountCore.tsxindex 25ccd5e6..a8c3d2a1 100644--- a/project/web/src/app/[lng]/accounts/accountCore.tsx+++ b/project/web/src/app/[lng]/accounts/accountCore.tsx@@ -9,7 +9,8 @@ import AccountSidebar from '@/app/[lng]/accounts/components/AccountSidebar/Accouimport AddAccountModal from '@/app/[lng]/accounts/components/AddAccountModal'import CalendarTiming from '@/app/[lng]/accounts/components/CalendarTiming'import AllPlatIcon from '@/app/[lng]/accounts/components/CalendarTiming/AllPlatIcon'-import { PlatType } from '@/app/config/platConfig'+import { PlatType, AccountPlatInfoMap } from '@/app/config/platConfig'+import { AccountStatus } from '@/app/config/accountConfig'import { useTransClient } from '@/app/i18n/client'import rightArrow from '@/assets/images/jiantou.png'import VipContentModal from '@/components/modals/VipContentModal'@@ -105,8 +106,21 @@ export default function AccountPageCore({setAiGeneratedData(data)- // Set default to first account- if (allAccounts[0]) {+ // 选择第一个在线且PC端支持的账户+ const firstAvailableAccount = allAccounts.find(account => {+ // 检查账户是否在线+ const isOnline = account.status === AccountStatus.USABLE+ // 检查平台是否支持PC端+ const platConfig = AccountPlatInfoMap.get(account.type)+ const isPcSupported = !platConfig?.pcNoThis++ return isOnline && isPcSupported+ })++ if (firstAvailableAccount) {+ setDefaultAccountId(firstAvailableAccount.id)+ } else if (allAccounts[0]) {+ // 如果没有找到符合条件的账户,退而求其次选择第一个账户setDefaultAccountId(allAccounts[0].id)}diff --git a/project/web/src/app/[lng]/components/PromptGallery.tsx b/project/web/src/app/[lng]/components/PromptGallery.tsxindex 1c87079c..c96aef64 100644--- a/project/web/src/app/[lng]/components/PromptGallery.tsx+++ b/project/web/src/app/[lng]/components/PromptGallery.tsx@@ -17,7 +17,7 @@ interface PromptItem {}interface PromptGallerySectionProps {- onApplyPrompt?: (prompt: string, imageUrl?: string) => void+ onApplyPrompt?: (prompt: string) => void}// 使用导入的提示词数据@@ -60,7 +60,7 @@ export default function PromptGallerySection({ onApplyPrompt }: PromptGallerySecconst handleApplyPrompt = (item: PromptItem, e: React.MouseEvent) => {e.stopPropagation()if (onApplyPrompt) {- onApplyPrompt(item.prompt, item.preview)+ onApplyPrompt(item.prompt) // 只应用提示词,不配置图片setApplied(true)setTimeout(() => setApplied(false), 2000)@@ -189,7 +189,7 @@ export default function PromptGallerySection({ onApplyPrompt }: PromptGallerySecclassName={styles.modalCopyBtn}onClick={() => {if (onApplyPrompt) {- onApplyPrompt(selectedPrompt.prompt, selectedPrompt.preview)+ onApplyPrompt(selectedPrompt.prompt) // 只应用提示词,不配置图片setSelectedPrompt(null)setApplied(true)setTimeout(() => setApplied(false), 2000)diff --git a/project/web/src/app/[lng]/page.tsx b/project/web/src/app/[lng]/page.tsxindex 83714f7b..4ab954f7 100644--- a/project/web/src/app/[lng]/page.tsx+++ b/project/web/src/app/[lng]/page.tsx@@ -42,9 +42,17 @@ import { getMainAppDownloadUrlSync } from '../config/appDownloadConfig'import { useTransClient } from '../i18n/client'import { getOssUrl } from '@/utils/oss'-import { message } from 'antd'+import { message, Modal, Form, Input, Button } from 'antd'+import { GoogleLogin } from '@react-oauth/google'+import { useUserStore } from '@/store/user'+import {+ loginWithMailApi,+ mailRegistApi,+ googleLoginApi,+} from '@/api/apiReq'import styles from './styles/difyHome.module.scss'+import loginStyles from './login/login.module.css'import PromptGallerySection from './components/PromptGallery'// External image URL constants@@ -142,8 +150,10 @@ function LazyLoadSection({ children }: { children: ReactNode }) {// Hero main title sectionfunction Hero({ promptToApply }: { promptToApply?: {prompt: string; image?: string} | null }) {const { t } = useTransClient('home')+ const { t: tLogin } = useTransClient('login')const router = useRouter()const { lng } = useParams()+ const { token, setToken, setUserInfo } = useUserStore()// AI generation related statesconst [prompt, setPrompt] = useState('')@@ -153,14 +163,21 @@ function Hero({ promptToApply }: { promptToApply?: {prompt: string; image?: striconst [uploadedImages, setUploadedImages] = useState<string[]>([]) // 上传的图片链接const [isUploading, setIsUploading] = useState(false) // 上传状态const fileInputRef = useRef<HTMLInputElement>(null) // 文件输入框引用++ // Login modal states+ const [loginModalOpen, setLoginModalOpen] = useState(false)+ const [loginEmail, setLoginEmail] = useState('')+ const [loginPassword, setLoginPassword] = useState('')+ const [isModalOpen, setIsModalOpen] = useState(false)+ const [registCode, setRegistCode] = useState('')+ const [loginForm] = Form.useForm()+ const [isActivating, setIsActivating] = useState(false)// 应用提示词(从 PromptGallery 触发)useEffect(() => {if (promptToApply) {setPrompt(promptToApply.prompt)- if (promptToApply.image) {- setUploadedImages(prev => [...prev, promptToApply.image!])- }+ // 不再自动添加图片}}, [promptToApply])@@ -359,11 +376,118 @@ function Hero({ promptToApply }: { promptToApply?: {prompt: string; image?: strisetUploadedImages(prev => prev.filter((_, i) => i !== index))}+ // Login handlers+ const handleLoginSubmit = async (e: React.FormEvent) => {+ e.preventDefault()+ try {+ const response = await loginWithMailApi({ mail: loginEmail, password: loginPassword })+ if (!response) return++ if (response.code === 0) {+ if (response.data.type === 'regist') {+ // User not registered, show registration modal+ setRegistCode(response.data.code || '')+ loginForm.setFieldsValue({ password: loginPassword })+ setIsModalOpen(true)+ } else if (response.data.token) {+ // Login successful+ setToken(response.data.token)+ if (response.data.userInfo) {+ setUserInfo(response.data.userInfo)+ }+ message.success(tLogin('loginSuccess'))+ setLoginModalOpen(false)+ // Continue with task creation+ handleCreateTask()+ }+ } else {+ message.error(response.message || tLogin('loginFailed'))+ }+ } catch (error) {+ message.error(tLogin('loginError'))+ }+ }++ const handleRegistSubmit = async (values: { password: string, code: string, inviteCode?: string }) => {+ try {+ setIsActivating(true)+ const response = await mailRegistApi({+ mail: loginEmail,+ code: values.code,+ password: values.password,+ inviteCode: values.inviteCode || '',+ })++ if (!response) {+ message.error(tLogin('registerError'))+ setIsActivating(false)+ return+ }++ if (response.code === 0 && response.data.token) {+ setIsActivating(false)+ setIsModalOpen(false)+ setLoginModalOpen(false)+ loginForm.resetFields()+ setToken(response.data.token)+ if (response.data.userInfo) {+ setUserInfo(response.data.userInfo)+ }+ message.success(tLogin('registerSuccess'))+ // Continue with task creation+ handleCreateTask()+ } else {+ message.error(response.message || tLogin('registerError'))+ setIsActivating(false)+ }+ } catch (error) {+ message.error(tLogin('registerError'))+ setIsActivating(false)+ }+ }++ const handleGoogleSuccess = async (credentialResponse: any) => {+ try {+ const params: any = {+ platform: 'google',+ clientId: credentialResponse.clientId,+ credential: credentialResponse.credential,+ }++ const response: any = await googleLoginApi(params)+ if (!response) {+ message.error(tLogin('googleLoginFailed'))+ return+ }++ if (response.code === 0 && response.data.type === 'login') {+ setToken(response.data.token)+ if (response.data.userInfo) {+ setUserInfo(response.data.userInfo)+ }+ message.success(tLogin('loginSuccess'))+ setLoginModalOpen(false)+ // Continue with task creation+ handleCreateTask()+ } else {+ message.error(response.message || tLogin('googleLoginFailed'))+ }+ } catch (error) {+ message.error(tLogin('googleLoginFailed'))+ }+ }+// Create AI generation task with SSEconst handleCreateTask = async () => {if (!prompt.trim()) {return}++ // Check if user is logged in+ if (!token) {+ setLoginModalOpen(true)+ return+ }try {setIsGenerating(true)@@ -394,7 +518,7 @@ function Hero({ promptToApply }: { promptToApply?: {prompt: string; image?: stri// 构建完整的提示词(包含图片链接,但不在前端显示)let fullPrompt = promptif (uploadedImages.length > 0) {- fullPrompt = `${prompt}\n\n[参考图片]:\n${uploadedImages.join('\n')}`+ fullPrompt = `${prompt}\n\n[图片]:\n${uploadedImages.join('\n ')}`}// Dynamic import API@@ -404,7 +528,7 @@ function Hero({ promptToApply }: { promptToApply?: {prompt: string; image?: striawait agentApi.createTaskWithSSE({ prompt: fullPrompt },// onMessage callback- (sseMessage) => {+ (sseMessage: any) => {console.log('SSE Message:', sseMessage)// Save sessionId@@ -413,8 +537,8 @@ function Hero({ promptToApply }: { promptToApply?: {prompt: string; image?: stri}// Handle different message types- // 只要有 message 字段就添加(支持 type: 'text', 'message' 等)- if (sseMessage.message) {+ // 只有 type === 'text' 才在 markdown 中显示+ if (sseMessage.type === 'text' && sseMessage.message) {console.log('[UI] Adding markdown message:', sseMessage.message)setMarkdownMessages(prev => {const newMessages = [...prev, sseMessage.message!]@@ -834,7 +958,7 @@ function Hero({ promptToApply }: { promptToApply?: {prompt: string; image?: stri<div className={styles.markdownContent}><ReactMarkdown>{markdownMessages.length > 0- ? markdownMessages.join('\n\n---\n\n')+ ? markdownMessages.join('\n\n'): '等待 AI 响应...'}</ReactMarkdown></div>@@ -889,6 +1013,124 @@ function Hero({ promptToApply }: { promptToApply?: {prompt: string; image?: stri{t('hero.useMobilePhone' as any)}</p></div>++ {/* Login Modal */}+ <Modal+ open={loginModalOpen}+ onCancel={() => setLoginModalOpen(false)}+ footer={null}+ width={460}+ centered+ destroyOnClose+ >+ <div className={loginStyles.loginBox} style={{ boxShadow: 'none', padding: '24px 0' }}>+ <h1 className={loginStyles.title}>{tLogin('welcomeBack')}</h1>+ <form onSubmit={handleLoginSubmit} className={loginStyles.form}>+ <div className={loginStyles.inputGroup}>+ <input+ type="email"+ placeholder={tLogin('emailPlaceholder')}+ value={loginEmail}+ onChange={e => setLoginEmail(e.target.value)}+ className={loginStyles.input}+ required+ />+ </div>+ <div className={loginStyles.inputGroup}>+ <input+ type="password"+ placeholder={tLogin('passwordPlaceholder')}+ value={loginPassword}+ onChange={e => setLoginPassword(e.target.value)}+ className={loginStyles.input}+ required+ />+ </div>+ <Button type="primary" htmlType="submit" block className={loginStyles.submitButton}>+ {tLogin('login')}+ </Button>+ </form>++ <div className={loginStyles.divider}>+ <span>{tLogin('or')}</span>+ </div>++ <div className={loginStyles.googleButtonWrapper}>+ <GoogleLogin+ onSuccess={handleGoogleSuccess}+ onError={() => message.error(tLogin('googleLoginFailed'))}+ useOneTap={false}+ theme="outline"+ shape="rectangular"+ text="signin_with"+ locale={lng === 'zh-CN' ? 'zh_CN' : 'en'}+ width="100%"+ size="large"+ />+ </div>+ </div>+ </Modal>++ {/* Registration Modal */}+ <Modal+ title={tLogin('completeRegistration')}+ open={isModalOpen}+ onCancel={() => {+ setIsModalOpen(false)+ setIsActivating(false)+ loginForm.resetFields()+ }}+ maskClosable={false}+ keyboard={false}+ closable={true}+ footer={null}+ >+ <Form+ form={loginForm}+ onFinish={handleRegistSubmit}+ layout="vertical"+ >+ <Form.Item+ label={tLogin('emailCode')}+ name="code"+ rules={[+ { required: true, message: tLogin('emailCodeRequired') },+ { len: 6, message: tLogin('emailCodeLength') },+ ]}+ >+ <Input placeholder={tLogin('enterEmailCode')} maxLength={6} />+ </Form.Item>++ <Form.Item+ label={tLogin('setPassword')}+ name="password"+ rules={[+ { required: true, message: tLogin('passwordRequired') },+ { min: 6, message: tLogin('passwordMinLength') },+ ]}+ >+ <Input.Password placeholder={tLogin('enterPassword')} />+ </Form.Item>++ <Form.Item+ label={tLogin('inviteCode')}+ name="inviteCode"+ >+ <Input placeholder={tLogin('enterInviteCode')} />+ </Form.Item>++ <Form.Item>+ <Button+ type="primary"+ htmlType="submit"+ block+ loading={isActivating}+ >+ {isActivating ? tLogin('registering') : tLogin('completeRegistration')}+ </Button>+ </Form.Item>+ </Form>+ </Modal></section>)}@@ -2190,8 +2432,8 @@ export default function Home() {<ReleaseBanner /><Hero promptToApply={promptToApply} /><PromptGallerySection- onApplyPrompt={(prompt, imageUrl) => {- setPromptToApply({ prompt, image: imageUrl })+ onApplyPrompt={(prompt) => {+ setPromptToApply({ prompt })}}/><LazyLoadSection>diff --git a/project/web/src/app/[lng]/styles/difyHome.module.scss b/project/web/src/app/[lng]/styles/difyHome.module.scssindex f9c1cbf1..835eab6d 100644--- a/project/web/src/app/[lng]/styles/difyHome.module.scss+++ b/project/web/src/app/[lng]/styles/difyHome.module.scss@@ -3142,6 +3142,15 @@display: flex;flex-direction: column;gap: 0;++ // 限制图片最大宽度+ :global {+ img {+ max-width: 100%;+ height: auto;+ display: block;+ }+ }}.markdownMessage {