Skip to content

Let's use AI to Earn!

feat: 选择发布记录逻辑优化:相同的视频和封面不重复获取

gaoSir9b3c2e66b0a3
diff --git a/src/views/publish/children/imagePage/components/ImageRightSetting/components/ImageParamsSet.tsx b/src/views/publish/children/imagePage/components/ImageRightSetting/components/ImageParamsSet.tsx
index 274dce27..01d09878 100644
--- a/src/views/publish/children/imagePage/components/ImageRightSetting/components/ImageParamsSet.tsx
+++ b/src/views/publish/children/imagePage/components/ImageRightSetting/components/ImageParamsSet.tsx
@@ -1,4 +1,4 @@
-import { ForwardedRef, forwardRef, memo, useMemo } from 'react';
+import { ForwardedRef, forwardRef, memo, useEffect, useMemo } from 'react';
import { useImagePageStore } from '../../../useImagePageStore';
import { useShallow } from 'zustand/react/shallow';
import styles from './imageParamsSet.module.scss';
@@ -36,21 +36,32 @@ const ImageParamsSet = memo(
const platAccountImagesMap = useMemo(() => {
// 平台账户map
const platAccountMap = new Map<AccountType, IImageAccountItem[]>([]);
+
+ for (const imageAccount of imageAccounts) {
+ if (!platAccountMap.has(imageAccount.account.type)) {
+ platAccountMap.set(imageAccount.account.type, []);
+ }
+ platAccountMap.get(imageAccount.account.type)?.push(imageAccount);
+ }
+ return platAccountMap;
+ }, [imageAccounts]);
+
+ useEffect(() => {
+ // 当前选择的平台不存在了便重新选择
+ if (!activePlat || !platAccountImagesMap.has(activePlat)) {
+ setActivePlat(Array.from(platAccountImagesMap)[0][0]);
+ }
+
// 默认选中的平台map
const newPlatActiveAccountMap = new Map<
AccountType,
IImageAccountItem
>();
- for (const imageAccount of imageAccounts) {
- if (!platAccountMap.has(imageAccount.account.type)) {
- platAccountMap.set(imageAccount.account.type, []);
- newPlatActiveAccountMap.set(
- imageAccount.account.type,
- imageAccount,
- );
+ for (const [accountType, imageAccountItems] of platAccountImagesMap) {
+ if (!newPlatActiveAccountMap.has(accountType)) {
+ newPlatActiveAccountMap.set(accountType, imageAccountItems[0]);
}
- platAccountMap.get(imageAccount.account.type)?.push(imageAccount);
}
// 将旧的选中的平台账户设置为新的
@@ -65,7 +76,7 @@ const ImageParamsSet = memo(
// 旧的选中账户新的账户列表是否存在,如果存在则使用上一次选中的状态
if (
- platAccountMap
+ platAccountImagesMap
.get(accountType)!
.some((v) => v.account.id === activeImageAccountItem.account.id)
) {
@@ -77,15 +88,9 @@ const ImageParamsSet = memo(
}
}
- // 当前选择的平台不存在了
- if (!activePlat || !platAccountMap.has(activePlat)) {
- setActivePlat(Array.from(platAccountMap)[0][0]);
- }
-
// 设置store当前选择的平台账户
setPlatActiveAccountMap(newPlatActiveAccountMap);
- return platAccountMap;
- }, [imageAccounts]);
+ }, [platAccountImagesMap]);
return (
<div className={styles.imageParamsSet}>
@@ -121,7 +126,7 @@ const ImageParamsSet = memo(
);
})}
</div>
- {activePlat && (
+ {activePlat && platAccountImagesMap.get(activePlat) && (
<ParamsSettingDetails
imageAccountList={platAccountImagesMap.get(activePlat)!}
/>
diff --git a/src/views/publish/children/imagePage/components/ImageRightSetting/components/ParamsSettingDetails.tsx b/src/views/publish/children/imagePage/components/ImageRightSetting/components/ParamsSettingDetails.tsx
index dc4ae0d4..4f2ec333 100644
--- a/src/views/publish/children/imagePage/components/ImageRightSetting/components/ParamsSettingDetails.tsx
+++ b/src/views/publish/children/imagePage/components/ImageRightSetting/components/ParamsSettingDetails.tsx
@@ -87,7 +87,7 @@ const ParamsSettingDetails = memo(
</div>
{(() => {
- switch (imageAccountList[0].account.type) {
+ switch (activePlat) {
case AccountType.Douyin:
return <ImageParamsSet_Douyin />;
case AccountType.Xhs:
diff --git a/src/views/publish/children/videoPage/useVideoPageStore.ts b/src/views/publish/children/videoPage/useVideoPageStore.ts
index a2b9b60f..a6e7dfc6 100644
--- a/src/views/publish/children/videoPage/useVideoPageStore.ts
+++ b/src/views/publish/children/videoPage/useVideoPageStore.ts
@@ -13,7 +13,7 @@ import { message } from 'antd';
import { VisibleTypeEnum } from '../../../../../commont/publish/PublishEnum';
import lodash from 'lodash';
import { VideoModel } from '../../../../../electron/db/models/video';
-import { getImgFile } from '../../../../components/Choose/ImgChoose';
+import { getImgFile, IImgFile } from '../../../../components/Choose/ImgChoose';
import { useAICreateTitleStore } from '../../components/AICreateTitle/useAICreateTitle';
import { usePubStroe } from '../../../../store/pubStroe';
@@ -368,14 +368,51 @@ export const useVideoPageStore = create(
});
const videoListChoose: IVideoChooseItem[] = [];
+
+ const error = (msg: string) => {
+ set({
+ loadingPageLoading: false,
+ });
+ message.error(msg);
+ };
+
try {
methods.setOperateId();
+ // key=视频路径 val=视频文件,防止多个相同视频重复取视频文件
+ const videoFileMap = new Map<string, IVideoFile>();
+ const coverFileMap = new Map<string, IImgFile>();
for (let i = 0; i < pubRecordList.length; i++) {
const pubRecord = pubRecordList[i];
const account = accounts[i];
- const video = await getVideoFile(pubRecord.videoPath!);
- const cover = await getImgFile(pubRecord.coverPath!);
+ const videoPath = pubRecord.videoPath!;
+ const coverPath = pubRecord.coverPath!;
+
+ // 视频获取
+ let video: void | IVideoFile;
+ if (videoFileMap.has(videoPath)) {
+ video = videoFileMap.get(videoPath);
+ } else {
+ video = await getVideoFile(videoPath).catch((e) => {
+ console.log(e);
+ });
+ }
+ // 封面获取
+ let cover: void | IImgFile;
+ if (coverFileMap.has(coverPath)) {
+ cover = coverFileMap.get(coverPath);
+ } else {
+ cover = await getImgFile(coverPath).catch((e) => {
+ console.log(e);
+ });
+ }
+
+ if (!video) return error(`视频获取失败:${videoPath}`);
+ if (!cover) return error(`封面获取失败:${coverPath}`);
+
+ videoFileMap.set(videoPath, video);
+ coverFileMap.set(coverPath, cover);
+
const pubParams = {
...pubRecord,
cover: cover,
@@ -416,6 +453,9 @@ export const useVideoPageStore = create(
});
methods.setOperateId(operateId);
+ // key=视频路径 val=视频文件,防止多个相同视频重复取视频文件
+ const videoFileMap = new Map<string, IVideoFile>();
+ const coverFileMap = new Map<string, IImgFile>();
try {
if (commonPubParams?.cover?.imgPath) {
commonPubParams.cover = await getImgFile(
@@ -423,13 +463,24 @@ export const useVideoPageStore = create(
);
}
for (const item of videoListChoose) {
- if (item.video?.videoPath) {
- item.video = await getVideoFile(item.video.videoPath);
+ const videoPath = item.video?.videoPath;
+ if (videoPath) {
+ if (videoFileMap.has(videoPath)) {
+ item.video = videoFileMap.get(videoPath);
+ } else {
+ item.video = await getVideoFile(videoPath);
+ videoFileMap.set(item.video.videoPath, item.video);
+ }
}
- if (item.pubParams.cover) {
- item.pubParams.cover = await getImgFile(
- item.pubParams.cover.imgPath,
- );
+
+ const imgPath = item.pubParams.cover?.imgPath;
+ if (imgPath) {
+ if (coverFileMap.has(imgPath)) {
+ item.pubParams.cover = coverFileMap.get(imgPath);
+ } else {
+ item.pubParams.cover = await getImgFile(imgPath);
+ coverFileMap.set(imgPath, item.pubParams.cover);
+ }
}
}
} catch (e) {