Skip to content

Let's use AI to Earn!

youtube独立

daoyian4dc0f21a7876
diff --git a/src/api/plat/publish.ts b/src/api/plat/publish.ts
index 9664fb43..4913be11 100644
--- a/src/api/plat/publish.ts
+++ b/src/api/plat/publish.ts
@@ -26,6 +26,11 @@ const filterOptionByPlatform = (option: any, accountType: PlatType): any => {
filteredOption.facebook = option.facebook;
}
break;
+ case PlatType.YouTube:
+ if (option.youtube) {
+ filteredOption.youtube = option.youtube;
+ }
+ break;
// 可以根据需要添加其他平台的处理
default:
// 对于没有特殊参数要求的平台,返回空对象
diff --git a/src/api/plat/youtube.ts b/src/api/plat/youtube.ts
new file mode 100644
index 00000000..f16a114f
--- /dev/null
+++ b/src/api/plat/youtube.ts
@@ -0,0 +1,13 @@
+import { request } from "@/utils/request";
+import { YouTubeCategoryItem } from "@/components/PublishDialog/publishDialog.type";
+
+// 获取YouTube视频分类
+export const apiGetYouTubeCategories = (account: string) => {
+ return request<YouTubeCategoryItem[]>({
+ url: "/plat/youtube/video/categories",
+ method: "GET",
+ params: {
+ account
+ }
+ });
+};
\ No newline at end of file
diff --git a/src/components/PublishDialog/compoents/PlatParamsSetting/index.tsx b/src/components/PublishDialog/compoents/PlatParamsSetting/index.tsx
index 1d567500..f000a1a5 100644
--- a/src/components/PublishDialog/compoents/PlatParamsSetting/index.tsx
+++ b/src/components/PublishDialog/compoents/PlatParamsSetting/index.tsx
@@ -5,6 +5,7 @@ import { AccountPlatInfoMap, PlatType } from "@/app/config/platConfig";
import BilibParams from "@/components/PublishDialog/compoents/PlatParamsSetting/plats/BilibParams";
import KwaiParams from "@/components/PublishDialog/compoents/PlatParamsSetting/plats/KwaiParams";
import FacebookParams from "@/components/PublishDialog/compoents/PlatParamsSetting/plats/FacebookParams";
+import YouTubeParams from "@/components/PublishDialog/compoents/PlatParamsSetting/plats/YouTubeParams";
import { useShallow } from "zustand/react/shallow";
import { PubItem } from "@/components/PublishDialog/publishDialog.type";
@@ -41,6 +42,8 @@ const PlatParamsSetting = memo(
return <BilibParams pubItem={pubItem} />;
case PlatType.Facebook:
return <FacebookParams pubItem={pubItem} />;
+ case PlatType.YouTube:
+ return <YouTubeParams pubItem={pubItem} />;
default:
return <KwaiParams pubItem={pubItem} />;
}
diff --git a/src/components/PublishDialog/compoents/PlatParamsSetting/plats/YouTubeParams.tsx b/src/components/PublishDialog/compoents/PlatParamsSetting/plats/YouTubeParams.tsx
new file mode 100644
index 00000000..28f3a43a
--- /dev/null
+++ b/src/components/PublishDialog/compoents/PlatParamsSetting/plats/YouTubeParams.tsx
@@ -0,0 +1,106 @@
+import { ForwardedRef, forwardRef, memo, useEffect } from "react";
+import {
+ IPlatsParamsProps,
+ IPlatsParamsRef,
+} from "@/components/PublishDialog/compoents/PlatParamsSetting/plats/plats.type";
+import PubParmasTextarea from "@/components/PublishDialog/compoents/PubParmasTextarea";
+import usePlatParamsCommon from "@/components/PublishDialog/compoents/PlatParamsSetting/hooks/usePlatParamsCoomon";
+import CommonTitleInput from "@/components/PublishDialog/compoents/PlatParamsSetting/common/CommonTitleInput";
+import { usePublishDialogData } from "@/components/PublishDialog/usePublishDialogData";
+import { useShallow } from "zustand/react/shallow";
+import styles from "../platParamsSetting.module.scss";
+import { Radio, Select } from "antd";
+import { YouTubeCategoryItem } from "@/components/PublishDialog/publishDialog.type";
+
+const YouTubeParams = memo(
+ forwardRef(
+ ({ pubItem }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {
+ const { pubParmasTextareaCommonParams, setOnePubParams } =
+ usePlatParamsCommon(pubItem);
+ const { getYouTubeCategories, youTubeCategories } =
+ usePublishDialogData(
+ useShallow((state) => ({
+ getYouTubeCategories: state.getYouTubeCategories,
+ youTubeCategories: state.youTubeCategories,
+ })),
+ );
+
+ useEffect(() => {
+ getYouTubeCategories();
+ }, [getYouTubeCategories]);
+
+ return (
+ <>
+ <PubParmasTextarea
+ {...pubParmasTextareaCommonParams}
+ extend={
+ <>
+ <CommonTitleInput pubItem={pubItem} />
+ <div
+ className={styles.commonTitleInput}
+ style={{ marginTop: "10px" }}
+ >
+ <div className="platParamsSetting-label">隐私状态</div>
+ <Radio.Group
+ value={pubItem.params.option.youtube?.privacyStatus}
+ options={[
+ { value: "public", label: "公开" },
+ { value: "unlisted", label: "不公开" },
+ { value: "private", label: "私人" },
+ ]}
+ onChange={(e) => {
+ const option = pubItem.params.option;
+ if (!option.youtube) {
+ option.youtube = {};
+ }
+ option.youtube.privacyStatus = e.target.value;
+ setOnePubParams(
+ {
+ option,
+ },
+ pubItem.account.id,
+ );
+ }}
+ />
+ </div>
+
+ <div
+ className={styles.commonTitleInput}
+ style={{ marginTop: "10px" }}
+ >
+ <div className="platParamsSetting-label">视频分类</div>
+ <Select
+ style={{ width: "100%" }}
+ options={youTubeCategories}
+ value={pubItem.params.option.youtube?.categoryId}
+ onChange={(value) => {
+ const option = pubItem.params.option;
+ if (!option.youtube) {
+ option.youtube = {};
+ }
+ option.youtube.categoryId = value;
+ setOnePubParams(
+ {
+ option,
+ },
+ pubItem.account.id,
+ );
+ }}
+ showSearch={true}
+ placeholder="请选择视频分类"
+ fieldNames={{
+ label: "name",
+ value: "id",
+ }}
+ />
+ </div>
+ </>
+ }
+ />
+ </>
+ );
+ },
+ ),
+);
+
+export default YouTubeParams;
\ No newline at end of file
diff --git a/src/components/PublishDialog/publishDialog.type.ts b/src/components/PublishDialog/publishDialog.type.ts
index b0d006c8..564674de 100644
--- a/src/components/PublishDialog/publishDialog.type.ts
+++ b/src/components/PublishDialog/publishDialog.type.ts
@@ -49,6 +49,12 @@ export interface IPlatOption {
// 页面ID,由获取Facebook页面信息接口得到
page_id?: string;
};
+ youtube?: {
+ // 隐私状态:public、unlisted、private
+ privacyStatus?: string;
+ // 视频分类ID
+ categoryId?: string;
+ };
}
// 发布参数
@@ -81,3 +87,10 @@ export interface BiblPartItem {
parent: number;
children: BiblPartItem[];
}
+
+// YouTube视频分类 item
+export interface YouTubeCategoryItem {
+ id: string;
+ name: string;
+ description?: string;
+}
diff --git a/src/components/PublishDialog/usePublishDialogData.ts b/src/components/PublishDialog/usePublishDialogData.ts
index dbedc427..f18a7afe 100644
--- a/src/components/PublishDialog/usePublishDialogData.ts
+++ b/src/components/PublishDialog/usePublishDialogData.ts
@@ -1,9 +1,10 @@
import { create } from "zustand";
import { combine } from "zustand/middleware";
import lodash from "lodash";
-import { BiblPartItem } from "@/components/PublishDialog/publishDialog.type";
+import { BiblPartItem, YouTubeCategoryItem } from "@/components/PublishDialog/publishDialog.type";
import { apiGetBilibiliPartitions } from "@/api/plat/bilibili";
import { apiGetFacebookPages, FacebookPageItem } from "@/api/plat/facebook";
+import { apiGetYouTubeCategories } from "@/api/plat/youtube";
import { useAccountStore } from "@/store/account";
import { PlatType } from "@/app/config/platConfig";
@@ -12,11 +13,14 @@ export interface IPublishDialogDataStore {
bilibiliPartitions: BiblPartItem[];
// Facebook页面列表
facebookPages: FacebookPageItem[];
+ // YouTube视频分类列表
+ youTubeCategories: YouTubeCategoryItem[];
}
const store: IPublishDialogDataStore = {
bilibiliPartitions: [],
facebookPages: [],
+ youTubeCategories: [],
};
const getStore = () => {
@@ -65,6 +69,24 @@ export const usePublishDialogData = create(
});
return res?.data;
},
+ // 获取YouTube视频分类
+ async getYouTubeCategories() {
+ if (get().youTubeCategories.length !== 0) return;
+ const youtubeAccount = useAccountStore
+ .getState()
+ .accountList.find((v) => v.type === PlatType.YouTube);
+
+ if (!youtubeAccount) {
+ console.warn('没有找到YouTube账户');
+ return;
+ }
+
+ const res:any = await apiGetYouTubeCategories(youtubeAccount.account);
+ set({
+ youTubeCategories: res?.data || [],
+ });
+ return res?.data;
+ },
};
return methods;