Skip to content

Let's use AI to Earn!

11

daoyian103270a1aec0
diff --git a/src/api/youtube.ts b/src/api/youtube.ts
index 791c3218..419e7b56 100644
--- a/src/api/youtube.ts
+++ b/src/api/youtube.ts
@@ -60,4 +60,49 @@ export const getYouTubeChannelSectionsApi = (data: any) => {
method: 'GET',
params: data,
});
+};
+
+
+/**
+ * 获取facebook授权状态
+ * @param taskId 任务ID
+ * @returns
+ */
+export const getFacebookAuthUrlApi = (mail: string) => {
+ return request({
+ url: '/plat/meta/auth/url',
+ method: 'POST',
+ data: {
+ platform: 'facebook',
+ },
+ });
+};
+
+
+export const checkFacebookAuthApi = ( data:any ) => {
+ return request({
+ url: `/plat/meta/auth/info/${data.accountId}`,
+ method: 'GET',
+ });
+};
+
+
+/**
+ * 获取tiktok授权状态
+ * @param taskId 任务ID
+ * @returns
+ */
+export const getTiktokAuthUrlApi = (mail: string) => {
+ return request({
+ url: '/plat/tiktok/auth/url',
+ method: 'POST',
+ data: { type: 'pc' },
+ });
+};
+
+export const checkTiktokAuthApi = ( data:any ) => {
+ return request({
+ url: `/plat/tiktok/auth/status/${data.accountId}`,
+ method: 'GET',
+ });
};
\ No newline at end of file
diff --git a/src/app/[lng]/accounts/components/AddAccountModal/index.tsx b/src/app/[lng]/accounts/components/AddAccountModal/index.tsx
index 4286b712..83aae6bb 100644
--- a/src/app/[lng]/accounts/components/AddAccountModal/index.tsx
+++ b/src/app/[lng]/accounts/components/AddAccountModal/index.tsx
@@ -7,6 +7,9 @@ import { kwaiSkip } from "@/app/[lng]/accounts/plat/kwaiLogin";
import { bilibiliSkip } from "../../plat/BilibiliLogin";
import { youtubeSkip } from "../../plat/YoutubeLogin";
import { twitterSkip } from "../../plat/TwtterLogin";
+import { tiktokSkip } from "../../plat/TiktokLogin";
+import { facebookSkip } from "../../plat/FacebookLogin";
+
export interface IAddAccountModalRef {}
@@ -63,6 +66,12 @@ const AddAccountModal = memo(
case PlatType.Twitter:
await twitterSkip(key);
break;
+ case PlatType.Tiktok:
+ await tiktokSkip(key);
+ break;
+ case PlatType.Facebook:
+ await facebookSkip(key);
+ break;
}
}}
>
diff --git a/src/app/[lng]/accounts/plat/FacebookLogin.ts b/src/app/[lng]/accounts/plat/FacebookLogin.ts
new file mode 100644
index 00000000..2de55c50
--- /dev/null
+++ b/src/app/[lng]/accounts/plat/FacebookLogin.ts
@@ -0,0 +1,67 @@
+import qs from "qs";
+import { PlatType } from "@/app/config/platConfig";
+import { getFacebookAuthUrlApi, checkFacebookAuthApi } from "@/api/youtube";
+import { useAccountStore } from "@/store/account";
+
+
+
+/**
+ * b站被点击
+ * @param platType
+ */
+export async function facebookSkip(platType: PlatType) {
+ if (platType !== PlatType.Facebook) return;
+
+ const res: any = await getFacebookAuthUrlApi('pc');
+ if (res?.code !== 0) return;
+ const url = res.data.url;
+ window.open(`${url}`);
+
+ const facebookLoginRes = await facebookLogin(res.data.taskId);
+
+}
+
+export function facebookLogin(taskId:any): Promise<any> {
+ return new Promise(async (resolve, reject) => {
+ try {
+ // 开始轮询检查授权状态
+ const checkAuthStatus = async () => {
+ try {
+ const authRess:any = await checkFacebookAuthApi(taskId);
+ let authRes = authRess;
+ console.log('authRes', authRes)
+ if (authRes?.code === 0 && authRes?.data.status == 1) {
+ // message.success('授权成功');
+ // useAccountStore
+ const accountStore = useAccountStore.getState();
+ await accountStore.getAccountList();
+ resolve(authRes);
+ return true;
+ }
+ // return false;
+ } catch (error) {
+ console.error('检查授权状态失败:', error);
+ return false;
+ }
+ };
+
+ // 设置轮询间隔
+ const interval = setInterval(async () => {
+ const isSuccess = await checkAuthStatus();
+ if (isSuccess) {
+ clearInterval(interval);
+ }
+ }, 2000);
+
+ // 5分钟后自动停止轮询
+ setTimeout(() => {
+ clearInterval(interval);
+ // message.error('授权超时,请重试');
+ reject(new Error('授权超时'));
+ }, 5 * 60 * 1000);
+
+ } catch (e) {
+ reject(e);
+ }
+ });
+}
diff --git a/src/app/[lng]/accounts/plat/TiktokLogin.ts b/src/app/[lng]/accounts/plat/TiktokLogin.ts
new file mode 100644
index 00000000..46d65057
--- /dev/null
+++ b/src/app/[lng]/accounts/plat/TiktokLogin.ts
@@ -0,0 +1,67 @@
+import qs from "qs";
+import { PlatType } from "@/app/config/platConfig";
+import { checkTiktokAuthApi, getTiktokAuthUrlApi } from "@/api/youtube";
+import { useAccountStore } from "@/store/account";
+
+
+
+/**
+ * b站被点击
+ * @param platType
+ */
+export async function tiktokSkip(platType: PlatType) {
+ if (platType !== PlatType.Tiktok) return;
+
+ const res: any = await getTiktokAuthUrlApi('pc');
+ if (res?.code !== 0) return;
+ const url = res.data.url;
+ window.open(`${url}`);
+
+ const tiktokLoginRes = await tiktokLogin(res.data.taskId);
+
+}
+
+export function tiktokLogin(taskId:any): Promise<any> {
+ return new Promise(async (resolve, reject) => {
+ try {
+ // 开始轮询检查授权状态
+ const checkAuthStatus = async () => {
+ try {
+ const authRess:any = await checkTiktokAuthApi(taskId);
+ let authRes = authRess;
+ console.log('authRes', authRes)
+ if (authRes?.code === 0 && authRes?.data.status == 1) {
+ // message.success('授权成功');
+ // useAccountStore
+ const accountStore = useAccountStore.getState();
+ await accountStore.getAccountList();
+ resolve(authRes);
+ return true;
+ }
+ // return false;
+ } catch (error) {
+ console.error('检查授权状态失败:', error);
+ return false;
+ }
+ };
+
+ // 设置轮询间隔
+ const interval = setInterval(async () => {
+ const isSuccess = await checkAuthStatus();
+ if (isSuccess) {
+ clearInterval(interval);
+ }
+ }, 2000);
+
+ // 5分钟后自动停止轮询
+ setTimeout(() => {
+ clearInterval(interval);
+ // message.error('授权超时,请重试');
+ reject(new Error('授权超时'));
+ }, 5 * 60 * 1000);
+
+ } catch (e) {
+ reject(e);
+ }
+ });
+}
diff --git a/src/app/config/platConfig.ts b/src/app/config/platConfig.ts
index cdf05cda..54ab4e44 100644
--- a/src/app/config/platConfig.ts
+++ b/src/app/config/platConfig.ts
@@ -4,10 +4,11 @@ import bilibiliSvg from "@/assets/svgs/plat/bilibili.svg";
import youtubeSvg from "@/assets/svgs/plat/youtube.svg";
import douyinSvg from "@/assets/svgs/plat/douyin.svg";
import twitterSvg from "@/assets/svgs/plat/twtter.svg";
+import facebookSvg from "@/assets/svgs/plat/facebook.svg";
// 平台类型
export enum PlatType {
- Douyin = "douyin", // 抖音
+ Tiktok = "douyin", // 抖音
Xhs = "xhs", // 小红书
WxSph = "wxSph", // 微信视频号
KWAI = "KWAI", // 快手
@@ -15,6 +16,7 @@ export enum PlatType {
BILIBILI = "bilibili", // B站
Twitter = "twitter", // Twitter
WxGzh = "wxGzh", // 微信公众号
+ Facebook = "facebook", // Facebook
}
export interface IAccountPlatInfo {
@@ -132,7 +134,7 @@ export const AccountPlatInfoMap = new Map<PlatType, IAccountPlatInfo>([
},
],
[
- PlatType.Douyin,
+ PlatType.Tiktok,
{
name: "TikTok",
icon: douyinSvg.src,
@@ -149,5 +151,23 @@ export const AccountPlatInfoMap = new Map<PlatType, IAccountPlatInfo>([
themeColor: "red",
},
],
+ [
+ PlatType.Facebook,
+ {
+ name: "Facebook",
+ icon: facebookSvg.src,
+ url: "https://www.facebook.com/",
+ pubTypes: new Set([PubType.VIDEO]),
+ commonPubParamsConfig: {
+ timingMax: {
+ maxDate: 30,
+ timeOffset: 60,
+ },
+ titleMax: 16,
+ topicMax: 10,
+ },
+ themeColor: "red",
+ },
+ ],
]);
export const AccountPlatInfoArr = Array.from(AccountPlatInfoMap);