Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat: 添加了所有平台话题的参数捕获(这里因为话题是描述中的话题+复选框中的话题,为了防止话题超出平台限制导致发布失败特地添加话题的长度限制错误捕获)
gaoSir9ecaadca7cd6
diff --git a/electron/db/models/video.ts b/electron/db/models/video.tsindex 474d1c5c..c797b8ad 100644--- a/electron/db/models/video.ts+++ b/electron/db/models/video.ts@@ -6,10 +6,16 @@* @Description: 视频发布记录*/import { Entity, Column } from 'typeorm';-import { ILableValue as ILableValueP, WorkData } from './workData';+import {+ ILableValue as ILableValueP,+ WorkData,+ DiffParmasType as DiffParmasTypeP,+} from './workData';export type ILableValue = ILableValueP;+export type DiffParmasType = DiffParmasTypeP;+@Entity({ name: 'video' })export class VideoModel extends WorkData {// 视频路径diff --git a/src/views/account/comment.ts b/src/views/account/comment.tsindex f0df7805..e0a54030 100644--- a/src/views/account/comment.ts+++ b/src/views/account/comment.ts@@ -38,6 +38,8 @@ export interface IAccountPlatInfo {// 同 VideoPubSetModalCommon.timeOffsettimeOffset: number;};+ // 话题数量限制+ topicMax: number;};}@@ -57,6 +59,7 @@ export const AccountPlatInfoMap = new Map<AccountType, IAccountPlatInfo>([maxDate: 13,timeOffset: 60,},+ topicMax: 3,},},],@@ -73,6 +76,7 @@ export const AccountPlatInfoMap = new Map<AccountType, IAccountPlatInfo>([maxDate: 14,timeOffset: 60,},+ topicMax: 20,titleMax: 20,},},@@ -90,6 +94,7 @@ export const AccountPlatInfoMap = new Map<AccountType, IAccountPlatInfo>([timeOffset: 120,},titleMax: 30,+ topicMax: 5,},},],@@ -106,6 +111,7 @@ export const AccountPlatInfoMap = new Map<AccountType, IAccountPlatInfo>([timeOffset: 60,},titleMax: 16,+ topicMax: 10,},},],diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/VideoPubSetModal.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/VideoPubSetModal.tsxindex 76ec6f2c..24d2903c 100644--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/VideoPubSetModal.tsx+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/VideoPubSetModal.tsx@@ -24,7 +24,7 @@ import { useShallow } from 'zustand/react/shallow';import styles from './videoPubSetModal.module.scss';import { AccountPlatInfoMap } from '@/views/account/comment';import VideoCoverSeting from '@/views/publish/children/videoPage/components/VideoCoverSeting';-import { AccountStatus, AccountType } from '@@/AccountEnum';+import { AccountType } from '@@/AccountEnum';import {icpCreatePubRecord,icpCreateVideoPubRecord,@@ -48,6 +48,10 @@ import VideoPubSetModalVideo, {import { usePubStroe } from '../../../../../../store/pubStroe';import { IVideoChooseItem } from '../../videoPage';+import usePubParamsVerify, {+ PubParamsErrStatusEnum,+} from '../../../../hooks/usePubParamsVerify';+import { ExclamationCircleOutlined } from '@ant-design/icons';export interface IVideoPubSetModalRef {}@@ -55,14 +59,6 @@ export interface IVideoPubSetModalProps {onClose: (open: boolean) => void;}-// 错误状态-enum ErrStatusEnum {- // 登录错误- LOGIN = 1,- // 参数错误- PARAMS = 2,-}-const PubSetModalChild = ({currChooseAccount,}: {@@ -127,6 +123,15 @@ const VideoPubSetModal = memo(>(new Map());const [pubProgressModuleOpen, setPubProgressModuleOpen] = useState(false);const videoPubSetModalVideoRef = useRef<IVideoPubSetModalVideoRef>(null);+ const { errVideoMap } = usePubParamsVerify(+ videoListChoose.map((v) => {+ return {+ id: v.id,+ account: v.account,+ pubParams: v.pubParams,+ };+ }),+ );useEffect(() => {// 发布进度监听@@ -157,43 +162,6 @@ const VideoPubSetModal = memo(});}, [pubProgressMap, videoListChoose]);- // 捕获 videoListChoose 的错误- const errVideoMap = useMemo(() => {- const errVideoMapTemp: Map<- string,- {- message: string;- // 同 AlertProps.type- type: 'warning' | 'error';- errType: ErrStatusEnum;- // 参数错误提示消息- parErrMsg?: string;- }- > = new Map();- for (const v of videoListChoose) {- if (v.account && v.account.status === AccountStatus.DISABLE) {- errVideoMapTemp.set(v.id, {- message: '登录失效',- type: 'warning',- errType: ErrStatusEnum.LOGIN,- });- } else if (- v.account?.type === AccountType.KWAI &&- v.pubParams.cover &&- (v.pubParams.cover.width < 400 || v.pubParams.cover.height < 400)- ) {- // 快手要求封面必须大于 400x400- errVideoMapTemp.set(v.id, {- message: '参数错误',- type: 'error',- errType: ErrStatusEnum.PARAMS,- parErrMsg: '封面最小尺寸400*400',- });- }- }- return errVideoMapTemp;- }, [videoListChoose]);-// 当前选择的账户数据const currChooseAccount = useMemo(() => {if (!currChooseAccountId) return videoListChoose[0];@@ -278,8 +246,8 @@ const VideoPubSetModal = memo(// 数据校验for (const [key, errVideoItem] of errVideoMap) {if (errVideoItem) {- setCurrChooseAccountId(key);- message.warning(errVideoItem.message);+ setCurrChooseAccountId(`${key}`);+ message.warning(errVideoItem.parErrMsg);setMoreParamsOpen(true);return;}@@ -368,11 +336,13 @@ const VideoPubSetModal = memo(label: (<div className="videoPubSetModal-tabLabel">{errItem && (- <Alert- message={errItem.message}- type={errItem.type}- showIcon- />+ <Tooltip title={errItem.parErrMsg}>+ <Alert+ message={errItem.message}+ type={errItem.type}+ showIcon+ />+ </Tooltip>)}<Tooltip title={account.nickname}><Avatar src={account?.avatar} size="small" />@@ -404,7 +374,7 @@ const VideoPubSetModal = memo(if (!errItem) return;return (<div className="videoPubSetModal_con_top">- {errItem.errType === ErrStatusEnum.LOGIN && (+ {errItem.errType === PubParamsErrStatusEnum.LOGIN && (<Buttontype="primary"danger@@ -415,7 +385,7 @@ const VideoPubSetModal = memo(重新登录</Button>)}- {errItem.errType === ErrStatusEnum.PARAMS && (+ {errItem.errType === PubParamsErrStatusEnum.PARAMS && (<Alerttype="error"showIcondiff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_DouYin.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_DouYin.tsxindex f8c3759f..6681cdeb 100644--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_DouYin.tsx+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_DouYin.tsx@@ -23,6 +23,7 @@ import {CommonHotspotSelect,} from '../../../../../components/CommonComponents/DouyinCommonComponents';import { ILableValue } from '../../../../../../../../electron/db/models/workData';+import useVideoPubSetModal from './hooks/useVideoPubSetModal';const HotspotSelect = ({ currChooseAccount }: IVideoPubSetModalChildProps) => {const { setOnePubParams } = useVideoPageStore(@@ -51,16 +52,13 @@ const HotspotSelect = ({ currChooseAccount }: IVideoPubSetModalChildProps) => {};const ActivitySelect = ({ currChooseAccount }: IVideoPubSetModalChildProps) => {- const { setOnePubParams } = useVideoPageStore(- useShallow((state) => ({- setOnePubParams: state.setOnePubParams,- })),- );+ const { setOnePubParams, platInfo } = useVideoPubSetModal(currChooseAccount);+ const { topicMax } = platInfo.commonPubParamsConfig;return (<CommonActivitySelectaccount={currChooseAccount.account}- maxCount={5 - currChooseAccount.pubParams!.topics!.length}+ maxCount={topicMax - currChooseAccount.pubParams!.topics!.length}value={currChooseAccount.pubParams!.diffParams![AccountType.Douyin]!.activitys}@@ -88,13 +86,10 @@ const VideoPubSetModal_DouYin = memo(props: IVideoPubSetModalChildProps,ref: ForwardedRef<IVideoPubSetModalChildRef>,) => {- const { setOnePubParams } = useVideoPageStore(- useShallow((state) => ({- setOnePubParams: state.setOnePubParams,- videoListChoose: state.videoListChoose,- })),- );const { currChooseAccount } = props;+ const { setOnePubParams, platInfo } =+ useVideoPubSetModal(currChooseAccount);+ const { topicMax } = platInfo.commonPubParamsConfig;return (<>@@ -111,12 +106,12 @@ const VideoPubSetModal_DouYin = memo(<TopicSelectmaxCount={- 5 -+ topicMax -currChooseAccount.pubParams!.diffParams![AccountType.Douyin]!.activitys!.length}currChooseAccount={currChooseAccount}- tips="最多可添加5个话题(包含活动奖励)"+ tips={`最多可添加${topicMax}个话题(包含活动奖励)`}/><ActivitySelect currChooseAccount={currChooseAccount} />diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_KWAI.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_KWAI.tsxindex 516fad46..0b92a36a 100644--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_KWAI.tsx+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_KWAI.tsx@@ -4,8 +4,6 @@ import {IVideoPubSetModalChildRef,} from '@/views/publish/children/videoPage/components/VideoPubSetModal/videoPubSetModal.type';import { Radio } from 'antd';-import { useVideoPageStore } from '@/views/publish/children/videoPage/useVideoPageStore';-import { useShallow } from 'zustand/react/shallow';import { VisibleTypeEnum } from '@@/publish/PublishEnum';import TopicSelect from '@/views/publish/children/videoPage/components/VideoPubSetModal/components/TopicSelect';import LocationSelect from '../components/LocationSelect';@@ -14,6 +12,7 @@ import {DescTextArea,ScheduledTimeSelect,} from '../components/VideoPubSetModalCommon';+import useVideoPubSetModal from './hooks/useVideoPubSetModal';const VideoPubSetModal_KWAI = memo(forwardRef(@@ -21,13 +20,9 @@ const VideoPubSetModal_KWAI = memo({ currChooseAccount }: IVideoPubSetModalChildProps,ref: ForwardedRef<IVideoPubSetModalChildRef>,) => {- const { setOnePubParams } = useVideoPageStore(- useShallow((state) => ({- setOnePubParams: state.setOnePubParams,- // 导出这个值是为了让组件更新,即使没有用到这个值,也要导出,否则组件不会更新- videoListChoose: state.videoListChoose,- })),- );+ const { setOnePubParams, platInfo } =+ useVideoPubSetModal(currChooseAccount);+ const { topicMax } = platInfo.commonPubParamsConfig;return (<>@@ -38,9 +33,9 @@ const VideoPubSetModal_KWAI = memo(/><TopicSelect- maxCount={3}+ maxCount={topicMax}currChooseAccount={currChooseAccount}- tips="您可以添加3个话题"+ tips={`您可以添加${topicMax}个话题`}/><UserSelectdiff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_WxSph.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_WxSph.tsxindex 45a80de0..933e53d1 100644--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_WxSph.tsx+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_WxSph.tsx@@ -19,6 +19,7 @@ import { getSphActivity } from '@/icp/publish';import { ipcUpdateAccountStatus } from '@/icp/account';import { WxSphEventList } from '../../../../../../../../electron/plat/shipinhao/wxShp.type';import UserSelect from '../components/UserSelect';+import useVideoPubSetModal from './hooks/useVideoPubSetModal';const WXSphActivity = ({ currChooseAccount }: IVideoPubSetModalChildProps) => {const { setOnePubParams, updateAccounts } = useVideoPageStore(@@ -87,12 +88,9 @@ const VideoPubSetModal_WxSph = memo({ currChooseAccount }: IVideoPubSetModalChildProps,ref: ForwardedRef<IVideoPubSetModalChildRef>,) => {- const { setOnePubParams } = useVideoPageStore(- useShallow((state) => ({- setOnePubParams: state.setOnePubParams,- videoListChoose: state.videoListChoose,- })),- );+ const { setOnePubParams, platInfo } =+ useVideoPubSetModal(currChooseAccount);+ const { topicMax } = platInfo.commonPubParamsConfig;const [topicSearch, setTopicSearch] = useState('');return (@@ -115,7 +113,7 @@ const VideoPubSetModal_WxSph = memo(allowClearmode="multiple"style={{ width: '100%' }}- maxCount={10}+ maxCount={topicMax}placeholder="请输入并选择话题"labelInValueonSearch={setTopicSearch}@@ -141,7 +139,7 @@ const VideoPubSetModal_WxSph = memo(}}/><p className="videoPubSetModal_con-tips">- 您可添加10个标签,按回车键确认+ 您可添加{topicMax}个标签,按回车键确认</p><UserSelectdiff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_XSH.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_XSH.tsxindex 1faa22a6..d9e769dc 100644--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_XSH.tsx+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_XSH.tsx@@ -4,8 +4,6 @@ import {IVideoPubSetModalChildRef,} from '@/views/publish/children/videoPage/components/VideoPubSetModal/videoPubSetModal.type';import { Radio } from 'antd';-import { useVideoPageStore } from '@/views/publish/children/videoPage/useVideoPageStore';-import { useShallow } from 'zustand/react/shallow';import { VisibleTypeEnum } from '@@/publish/PublishEnum';import TopicSelect from '@/views/publish/children/videoPage/components/VideoPubSetModal/components/TopicSelect';import LocationSelect from '@/views/publish/children/videoPage/components/VideoPubSetModal/components/LocationSelect';@@ -15,6 +13,7 @@ import {TitleInput,} from '@/views/publish/children/videoPage/components/VideoPubSetModal/components/VideoPubSetModalCommon';import UserSelect from '../components/UserSelect';+import useVideoPubSetModal from './hooks/useVideoPubSetModal';const VideoPubSetModal_WxSph = memo(forwardRef(@@ -22,12 +21,9 @@ const VideoPubSetModal_WxSph = memo({ currChooseAccount }: IVideoPubSetModalChildProps,ref: ForwardedRef<IVideoPubSetModalChildRef>,) => {- const { setOnePubParams } = useVideoPageStore(- useShallow((state) => ({- setOnePubParams: state.setOnePubParams,- videoListChoose: state.videoListChoose,- })),- );+ const { setOnePubParams, platInfo } =+ useVideoPubSetModal(currChooseAccount);+ const { topicMax } = platInfo.commonPubParamsConfig;return (<>@@ -44,9 +40,9 @@ const VideoPubSetModal_WxSph = memo(/><TopicSelect- maxCount={20}+ maxCount={topicMax}currChooseAccount={currChooseAccount}- tips="您可以添加20个话题"+ tips={`您可以添加${topicMax}个话题`}/><UserSelect currChooseAccount={currChooseAccount} title="@用户" />diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/children/hooks/useVideoPubSetModal.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/children/hooks/useVideoPubSetModal.tsxnew file mode 100644index 00000000..9be69557--- /dev/null+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/children/hooks/useVideoPubSetModal.tsx@@ -0,0 +1,20 @@+import { useVideoPageStore } from '../../../../useVideoPageStore';+import { useShallow } from 'zustand/react/shallow';+import { IVideoChooseItem } from '../../../../videoPage';+import { AccountPlatInfoMap } from '../../../../../../../account/comment';++export default function useVideoPubSetModal(+ currChooseAccount: IVideoChooseItem,+) {+ const { setOnePubParams } = useVideoPageStore(+ useShallow((state) => ({+ setOnePubParams: state.setOnePubParams,+ videoListChoose: state.videoListChoose,+ })),+ );++ return {+ setOnePubParams,+ platInfo: AccountPlatInfoMap.get(currChooseAccount.account!.type)!,+ };+}diff --git a/src/views/publish/hooks/usePubParamsVerify.tsx b/src/views/publish/hooks/usePubParamsVerify.tsxnew file mode 100644index 00000000..069acde1--- /dev/null+++ b/src/views/publish/hooks/usePubParamsVerify.tsx@@ -0,0 +1,96 @@+import { AccountInfo, AccountPlatInfoMap } from '../../account/comment';+import { IPubParams } from '../children/videoPage/videoPage';+import { useMemo } from 'react';+import { parseTopicString } from '../../../utils';+import { AccountStatus, AccountType } from '../../../../commont/AccountEnum';++// 错误状态+export enum PubParamsErrStatusEnum {+ // 登录错误+ LOGIN = 1,+ // 参数错误+ PARAMS = 2,+}++/**+ * 发布参数校验是否复合平台规范+ * @param data+ */+export default function (+ data: {+ id: string | number;+ account?: AccountInfo;+ pubParams: IPubParams;+ }[],+) {+ const errVideoMap = useMemo(() => {+ const errVideoMapTemp: Map<+ string | number,+ {+ message: string;+ // 同 AlertProps.type+ type: 'warning' | 'error';+ errType: PubParamsErrStatusEnum;+ // 参数错误提示消息+ parErrMsg?: string;+ }+ > = new Map();+ for (const v of data) {+ const platInfo = AccountPlatInfoMap.get(v.account!.type)!;+ const { topics } = parseTopicString(v.pubParams.describe || '');+ const topicsAll = [...new Set(v.pubParams.topics?.concat(topics))];+ const { topicMax } = platInfo.commonPubParamsConfig;++ if (v.account && v.account.status === AccountStatus.DISABLE) {+ // 登录状态校验+ errVideoMapTemp.set(v.id, {+ message: '登录失效',+ type: 'warning',+ errType: PubParamsErrStatusEnum.LOGIN,+ parErrMsg: '登录失效,请重新登录',+ });+ } else if (+ v.account?.type === AccountType.KWAI &&+ v.pubParams.cover &&+ (v.pubParams.cover.width < 400 || v.pubParams.cover.height < 400)+ ) {+ // 快手要求封面必须大于 400x400+ errVideoMapTemp.set(v.id, {+ message: '参数错误',+ type: 'error',+ errType: PubParamsErrStatusEnum.PARAMS,+ parErrMsg: '封面最小尺寸400*400',+ });+ } else if (topicsAll.length > topicMax) {+ // 话题校验+ errVideoMapTemp.set(v.id, {+ message: '参数错误',+ type: 'error',+ errType: PubParamsErrStatusEnum.PARAMS,+ parErrMsg: `${platInfo.name}话题最多不能超过${topicMax}个`,+ });+ } else if (+ v.account?.type === AccountType.Douyin &&+ topicsAll.length ++ v.pubParams.diffParams![AccountType.Douyin]!.activitys!.length >+ topicMax+ ) {+ /**+ * 抖音的话题和活动奖励校验+ * 抖音规定活动奖励 + 话题不能超过5个+ */+ errVideoMapTemp.set(v.id, {+ message: '参数错误',+ type: 'error',+ errType: PubParamsErrStatusEnum.PARAMS,+ parErrMsg: `话题 + 活动奖励不能超过${topicMax}个`,+ });+ }+ }+ return errVideoMapTemp;+ }, [data]);++ return {+ errVideoMap,+ };+}