Skip to content

Let's use AI to Earn!

推特账户添加

daoyian3bb39d677680
diff --git a/src/api/twitter.ts b/src/api/twitter.ts
new file mode 100644
index 00000000..da4317e6
--- /dev/null
+++ b/src/api/twitter.ts
@@ -0,0 +1,26 @@
+import http from "@/utils/request";
+import { request } from "@/utils/request";
+
+// 获取 Twitter 授权 URL
+export const getTwitterAuthUrlApi = (mail: string) => {
+ return request({
+ url: '/plat/twitter/auth/url',
+ method: 'POST',
+ data: {
+ },
+ });
+};
+
+
+/**
+ * 获取youtube授权状态
+ * @param taskId 任务ID
+ * @returns
+ */
+export const apiCheckTwitterAuth = (taskId: string) => {
+ return http.get<{ code: number; data: any }>(
+ `/plat/twitter/auth/info/${taskId}`,
+ );
+};
+
+
diff --git a/src/app/[lng]/accounts/components/AddAccountModal/index.tsx b/src/app/[lng]/accounts/components/AddAccountModal/index.tsx
index 2514dd93..156bdfd9 100644
--- a/src/app/[lng]/accounts/components/AddAccountModal/index.tsx
+++ b/src/app/[lng]/accounts/components/AddAccountModal/index.tsx
@@ -6,6 +6,7 @@ import { SocialAccount } from "@/api/types/account.type";
import { kwaiSkip } from "@/app/[lng]/accounts/plat/kwaiLogin";
import { bilibiliSkip } from "../../plat/BilibiliLogin";
import { youtubeSkip } from "../../plat/YoutubeLogin";
+import { twitterSkip } from "../../plat/TwtterLogin";
export interface IAddAccountModalRef {}
@@ -59,6 +60,9 @@ const AddAccountModal = memo(
case PlatType.YouTube:
console.log('key',key)
youtubeSkip(key);
+
+ case PlatType.Twitter:
+ twitterSkip(key);
}
}}
>
diff --git a/src/app/[lng]/accounts/plat/TwtterLogin.ts b/src/app/[lng]/accounts/plat/TwtterLogin.ts
new file mode 100644
index 00000000..729537ea
--- /dev/null
+++ b/src/app/[lng]/accounts/plat/TwtterLogin.ts
@@ -0,0 +1,67 @@
+import qs from "qs";
+import { PlatType } from "@/app/config/platConfig";
+import { getTwitterAuthUrlApi, apiCheckTwitterAuth } from "@/api/twitter";
+import { useAccountStore } from "@/store/account";
+
+
+
+/**
+ * b站被点击
+ * @param platType
+ */
+export async function twitterSkip(platType: PlatType) {
+ if (platType !== PlatType.Twitter) return;
+
+ const res: any = await getTwitterAuthUrlApi('pc');
+ if (res?.code !== 0) return;
+ const url = res.data.url;
+ window.open(`${url}`);
+
+ const twitterLoginRes = await twitterLogin(res.data.taskId);
+
+}
+
+export function twitterLogin(taskId:any): Promise<any> {
+ return new Promise(async (resolve, reject) => {
+ try {
+ // 开始轮询检查授权状态
+ const checkAuthStatus = async () => {
+ try {
+ const authRess:any = await apiCheckTwitterAuth(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 cdd1ca62..3edd7b34 100644
--- a/src/app/config/platConfig.ts
+++ b/src/app/config/platConfig.ts
@@ -3,6 +3,7 @@ import ksSvg from "@/assets/svgs/plat/ks.svg";
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";
// 平台类型
export enum PlatType {
@@ -12,6 +13,7 @@ export enum PlatType {
KWAI = "KWAI", // 快手
YouTube = "youtube", // YouTube
BILIBILI = "bilibili", // B站
+ Twitter = "twitter", // Twitter
}
export interface IAccountPlatInfo {
@@ -110,6 +112,24 @@ export const AccountPlatInfoMap = new Map<PlatType, IAccountPlatInfo>([
themeColor: "red",
},
],
+ [
+ PlatType.Twitter,
+ {
+ name: "Twitter",
+ icon: twitterSvg.src,
+ url: "https://x.com/",
+ pubTypes: new Set([PubType.VIDEO]),
+ commonPubParamsConfig: {
+ timingMax: {
+ maxDate: 30,
+ timeOffset: 60,
+ },
+ titleMax: 16,
+ topicMax: 10,
+ },
+ themeColor: "red",
+ },
+ ],
[
PlatType.Douyin,
{
diff --git a/src/assets/svgs/plat/twtter.svg b/src/assets/svgs/plat/twtter.svg
new file mode 100644
index 00000000..c4081ad6
--- /dev/null
+++ b/src/assets/svgs/plat/twtter.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50" width="50px" height="50px"><path d="M 11 4 C 7.134 4 4 7.134 4 11 L 4 39 C 4 42.866 7.134 46 11 46 L 39 46 C 42.866 46 46 42.866 46 39 L 46 11 C 46 7.134 42.866 4 39 4 L 11 4 z M 13.085938 13 L 21.023438 13 L 26.660156 21.009766 L 33.5 13 L 36 13 L 27.789062 22.613281 L 37.914062 37 L 29.978516 37 L 23.4375 27.707031 L 15.5 37 L 13 37 L 22.308594 26.103516 L 13.085938 13 z M 16.914062 15 L 31.021484 35 L 34.085938 35 L 19.978516 15 L 16.914062 15 z"/></svg>
\ No newline at end of file