Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat: 添加发布完成后的视频预览
gaoSirdba53c597efc
diff --git a/electron/main/account/BrowserWindow/index.ts b/electron/main/account/BrowserWindow/index.tsindex 66aa6031..014baa95 100644--- a/electron/main/account/BrowserWindow/index.ts+++ b/electron/main/account/BrowserWindow/index.ts@@ -20,6 +20,8 @@ class BrowserWindowController {// 销毁 BrowserWindowdestroyBrowserWindow(webViewId: number) {+ // @ts-ignore+ this.browserWindowMap.get(webViewId)?.webview.destroy();this.browserWindowMap.delete(webViewId);}}diff --git a/electron/main/plat/module.ts b/electron/main/plat/module.tsindex 8c695343..73c94215 100644--- a/electron/main/plat/module.ts+++ b/electron/main/plat/module.ts@@ -16,9 +16,8 @@ export class PublishVideoResult {code: number;// 提示信息msg: string;-// 数据ID- dataId: string;+ dataId?: string;constructor({ code, msg, dataId }: IProperty = {diff --git a/electron/main/plat/platforms/douyin/index.ts b/electron/main/plat/platforms/douyin/index.tsindex 1c6f6c4c..47322115 100644--- a/electron/main/plat/platforms/douyin/index.ts+++ b/electron/main/plat/platforms/douyin/index.ts@@ -207,19 +207,17 @@ export class Douyin extends PlatformBase {resolve({code: 0,msg: e,- dataId: '',});});if (!result.publishId)return resolve({code: 0,- msg: '',- dataId: '',+ msg: '网络繁忙,请稍后重试',});return resolve({code: 1,- msg: '',+ msg: '发布成功',dataId: result.publishId,});});diff --git a/electron/main/plat/platforms/wxSph/index.ts b/electron/main/plat/platforms/wxSph/index.tsindex 8c6e16eb..8a1cbc71 100644--- a/electron/main/plat/platforms/wxSph/index.ts+++ b/electron/main/plat/platforms/wxSph/index.ts@@ -186,53 +186,61 @@ export class WxSph extends PlatformBase {params: IVideoPublishParams,callback: VideoCallbackType,): Promise<PublishVideoResult> {- const result = await shipinhaoService.publishVideoWorkApi(- params.cookies,- params.videoPath,- {- cover: params.coverPath,- title: params.desc,- topics: params.topics,- des: params.desc,- timingTime: params.timingTime?.getTime(),- // 位置- ...(params.location- ? {- poiInfo: {- latitude: params.location.latitude,- longitude: params.location.longitude,- poiCity: params.location.city,- poiName: params.location.name,- poiAddress: params.location.simpleAddress,- poiId: params.location.id,- },- }- : {}),- // @用户- mentionedUserInfo: params.mentionedUserInfo- ? params.mentionedUserInfo.map((v) => {- return {- nickName: v.label,- };- })- : undefined,- // 活动- event: params.diffParams![AccountType.WxSph]!.activity,- },- callback,- );- if (!result.publishId)- return {- code: 0,- msg: '',- dataId: '',- };+ return new Promise(async (resolve) => {+ const result = await shipinhaoService+ .publishVideoWorkApi(+ params.cookies,+ params.videoPath,+ {+ cover: params.coverPath,+ title: params.desc,+ topics: params.topics,+ des: params.desc,+ timingTime: params.timingTime?.getTime(),+ // 位置+ ...(params.location+ ? {+ poiInfo: {+ latitude: params.location.latitude,+ longitude: params.location.longitude,+ poiCity: params.location.city,+ poiName: params.location.name,+ poiAddress: params.location.simpleAddress,+ poiId: params.location.id,+ },+ }+ : {}),+ // @用户+ mentionedUserInfo: params.mentionedUserInfo+ ? params.mentionedUserInfo.map((v) => {+ return {+ nickName: v.label,+ };+ })+ : undefined,+ // 活动+ event: params.diffParams![AccountType.WxSph]!.activity,+ },+ callback,+ )+ .catch((e) => {+ resolve({+ code: 0,+ msg: e,+ });+ });+ if (!result || !result.publishId)+ return resolve({+ code: 0,+ msg: '网络繁忙,请稍后重试',+ });- return {- code: 1,- msg: '',- dataId: result.publishId,- };+ return resolve({+ code: 1,+ msg: '成功!',+ dataId: result.publishId,+ });+ });}async getTopics({}: IGetTopicsParams): Promise<IGetTopicsResponse> {diff --git a/electron/main/plat/platforms/xhs/index.ts b/electron/main/plat/platforms/xhs/index.tsindex 54f98945..3dbfd77c 100644--- a/electron/main/plat/platforms/xhs/index.ts+++ b/electron/main/plat/platforms/xhs/index.ts@@ -202,20 +202,18 @@ export class Xhs extends PlatformBase {resolve({code: 0,msg: err,- dataId: '',});});if (result && !result.publishId)return resolve({code: 0,- msg: '',- dataId: '',+ msg: '网络繁忙,请稍后重试!',});return resolve({code: 1,- msg: '',+ msg: '成功!',dataId: result!.publishId,});});diff --git a/electron/main/plat/pub/PubItemVideo.ts b/electron/main/plat/pub/PubItemVideo.tsindex 7aea6ab3..11e473c9 100644--- a/electron/main/plat/pub/PubItemVideo.ts+++ b/electron/main/plat/pub/PubItemVideo.ts@@ -73,6 +73,7 @@ export class PubItemVideo extends PubItemBase {} else {// 发布成功this.videoModel.status = PubStatus.RELEASED;+ this.videoModel.dataId = publishVideoResult.dataId;}await this.uploadRecord();return publishVideoResult;diff --git a/electron/main/publish/video/controller.ts b/electron/main/publish/video/controller.tsindex ca181b4f..c930bab5 100644--- a/electron/main/publish/video/controller.ts+++ b/electron/main/publish/video/controller.ts@@ -90,7 +90,6 @@ export class VideoPubController {pubRecordId,PubStatus.RELEASED,);-return pubRes;}diff --git a/electron/plat/douyin/index.ts b/electron/plat/douyin/index.tsindex a0805ef2..85dcc7f2 100644--- a/electron/plat/douyin/index.ts+++ b/electron/plat/douyin/index.ts@@ -1,4 +1,4 @@-import { screen, BrowserWindow, net, session } from 'electron';+import { BrowserWindow, net, screen, session } from 'electron';import { CommonUtils } from '../../util/common';import path from 'path';import { FileUtils } from '../../util/file';@@ -1696,7 +1696,7 @@ export class DouyinService {console.log('platformSetting:', platformSetting);const parmasDisposeOK = this.getPublishPublicParams(platformSetting);- const params = {+ return {item: {anchor: parmasDisposeOK.hasOwnProperty('poi_id')? {@@ -1777,7 +1777,6 @@ export class DouyinService {},},};- return params;}/**diff --git a/src/components/GetCode.tsx b/src/components/GetCode.tsxindex 46a4568a..3eb63788 100644--- a/src/components/GetCode.tsx+++ b/src/components/GetCode.tsx@@ -4,6 +4,7 @@ import { Statistic } from 'antd';const { Countdown } = Statistic;/**+ * 播放视频* 验证码倒计时触发组件* @param onGetCode*/diff --git a/src/components/WebView/index.tsx b/src/components/WebView/index.tsxindex 2685e6bf..708e5cc6 100644--- a/src/components/WebView/index.tsx+++ b/src/components/WebView/index.tsx@@ -1,65 +1,87 @@-/*- * @Author: nevin- * @Date: 2025-01-17 21:02:44- * @LastEditTime: 2025-02-11 17:43:22- * @LastEditors: nevin- * @Description:- */-import { useEffect, useRef, useState } from 'react';-import { ICookieParams } from '../../../electron/main/account/BrowserWindow/browserWindow';+import {+ ForwardedRef,+ forwardRef,+ memo,+ useEffect,+ useRef,+ useState,+} from 'react';+import { generateUUID } from '../../utils';import styles from './webView.module.scss';import { Spin } from 'antd';-import { generateUUID } from '@/utils';+import { ICookieParams } from '../../../electron/main/account/BrowserWindow/browserWindow';++export interface IWebViewRef {}-interface WebViewProps {+export interface IWebViewProps {url: string;cookieParams?: ICookieParams;+ jsCode?: string;}-const WebView: React.FC<WebViewProps> = ({ url, cookieParams }) => {- const webviewRef = useRef<HTMLWebViewElement>(null);- // webView id- const [webViewId, setWebViewId] = useState(-1);- const [loading, setLoading] = useState(true);- // 隔离ID- const partitionId = useRef(generateUUID());+const WebView = memo(+ forwardRef(+ (+ { url, cookieParams, jsCode }: IWebViewProps,+ ref: ForwardedRef<IWebViewRef>,+ ) => {+ const webviewRef = useRef<HTMLWebViewElement>(null);+ // webView id+ const [webViewId, setWebViewId] = useState(-1);+ const [loading, setLoading] = useState(true);+ // 隔离ID+ const partitionId = useRef(generateUUID());- useEffect(() => {- setLoading(true);- webviewRef.current!.addEventListener('dom-ready', async () => {- // @ts-ignore- const id = webviewRef.current!.getWebContentsId();- setWebViewId(id);+ useEffect(() => {+ setLoading(true);+ webviewRef.current?.addEventListener('dom-ready', async () => {+ if (jsCode) {+ // @ts-ignore+ webviewRef.current!.executeJavaScript(jsCode);+ }- console.log('---- cookieParams', cookieParams);+ // @ts-ignore+ if (webviewRef.current?.getURL() === 'about:blank') {+ // @ts-ignore+ const id = webviewRef.current!.getWebContentsId();+ setWebViewId(id);- await window.ipcRenderer.invoke('ICP_ACCOUNT_CREATE_BROWSER_VIEW', {- webViewId: id,- cookieParams,- });- setLoading(false);- });+ // @ts-ignore+ await window.ipcRenderer.invoke('ICP_ACCOUNT_CREATE_BROWSER_VIEW', {+ webViewId: id,+ cookieParams,+ });+ }+ setLoading(false);+ });- return () => {- window.ipcRenderer.invoke('ICP_ACCOUNT_DESTROY_BROWSER_VIEW', webViewId);- };- }, []);+ return () => {+ window.ipcRenderer.invoke(+ 'ICP_ACCOUNT_DESTROY_BROWSER_VIEW',+ webViewId,+ );+ };+ }, []);- return (- <div className={styles.webview}>- <Spin spinning={loading} tip="加载中...">- <webview- ref={webviewRef}- src={url}- key={loading ? 0 : 1}- webpreferences="sandbox"- style={{ width: '100%', height: '100%' }}- partition={partitionId.current}- useragent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0"- ></webview>- </Spin>- </div>- );-};+ return (+ url && (+ <div className={styles.webview}>+ <Spin spinning={loading} tip="加载中...">+ <webview+ ref={webviewRef}+ webpreferences="sandbox"+ src={!jsCode ? (loading ? 'about:blank' : url) : url}+ style={{ width: '100%', height: '100%' }}+ partition={partitionId.current}+ useragent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0"+ ></webview>+ </Spin>+ </div>+ )+ );+ },+ ),+);+WebView.displayName = 'WebView';export default WebView;diff --git a/src/views/publish/children/pubRecord/page.tsx b/src/views/publish/children/pubRecord/page.tsxindex 25f9e88f..14737c85 100644--- a/src/views/publish/children/pubRecord/page.tsx+++ b/src/views/publish/children/pubRecord/page.tsx@@ -2,7 +2,16 @@ import { useEffect, useRef, useState } from 'react';import { PubRecordModel } from '../../comment';import styles from './pubRecord.module.scss';import { icpGetPubRecordList, icpGetPubVideoRecord } from '@/icp/publish';-import { Avatar, Button, Drawer, Spin, Table, TableProps, Tooltip } from 'antd';+import {+ Avatar,+ Button,+ Drawer,+ Modal,+ Spin,+ Table,+ TableProps,+ Tooltip,+} from 'antd';import { getImgFile, IImgFile } from '@/components/Choose/ImgChoose';import { formatTime, getFilePathName } from '@/utils';import { VideoPul } from '@/views/publish/children/videoPage/comment';@@ -11,6 +20,8 @@ import { AccountInfo, AccountPlatInfoMap } from '@/views/account/comment';import { useVideoPageStore } from '../videoPage/useVideoPageStore';import { useShallow } from 'zustand/react/shallow';import { useNavigate } from 'react-router-dom';+import { AccountType } from '../../../../../commont/AccountEnum';+import WebView from '../../../../components/WebView';const PubCon = ({ prm }: { prm: PubRecordModel }) => {const [imgFile, setImgFile] = useState<IImgFile>();@@ -42,6 +53,17 @@ export default function Page() {// id=账户id,val=账户item数据const accountMap = useRef<Map<number, AccountInfo>>(new Map());const navigate = useNavigate();+ const [examineVideo, setExamineVideo] = useState<{+ account?: AccountInfo;+ url: string;+ open: boolean;+ jsCode: string;+ }>({+ account: undefined,+ url: '',+ open: false,+ jsCode: '',+ });const { restartPub } = useVideoPageStore(useShallow((state) => ({@@ -118,6 +140,38 @@ export default function Page() {return (<div className={styles.pubRecord}>+ <Modal+ zIndex={10000}+ open={examineVideo.open}+ forceRender={true}+ footer={null}+ onCancel={() => {+ setExamineVideo((prevState) => {+ const newState = { ...prevState };+ newState.open = false;+ newState.url = '';+ return newState;+ });+ }}+ title="查看视频"+ width="90%"+ >+ <div style={{ height: '70vh' }}>+ {examineVideo.account && open ? (+ <WebView+ url={examineVideo.url}+ jsCode={examineVideo.jsCode}+ cookieParams={{+ cookies: JSON.parse(examineVideo.account.loginCookie),+ }}+ key={examineVideo.url + examineVideo.open}+ />+ ) : (+ ''+ )}+ </div>+ </Modal>+<Table<PubRecordModel>columns={columns}dataSource={pulRecardList}@@ -184,7 +238,29 @@ export default function Page() {重新发布</Button>) : (- <Button type="link">查看</Button>+ <Button+ type="link"+ onClick={() => {+ if (!v.dataId) return;+ setExamineVideo((prevState) => {+ const newState = { ...prevState };+ newState.open = true;+ newState.account = account;+ if (account?.type === AccountType.Douyin) {+ newState.url = `https://www.douyin.com/user/self?from_tab_name=main&modal_id=${v.dataId}&showTab=post`;+ newState.jsCode = `+ localStorage.setItem('douyin_web_hide_guide', '1');+ localStorage.setItem('user_info', '1');+ localStorage.setItem('user_info_passport', '1');+ localStorage.setItem('useShortcut2', '{"Wed Mar 12 2025":false}');+ `;+ }+ return newState;+ });+ }}+ >+ 查看+ </Button>)}</div></li>