Skip to content

Let's use AI to Earn!

lingyingshouwquan

bulaienaofutuojiesenzhangf121a715feb7
diff --git a/src/api/platAuth.ts b/src/api/platAuth.ts
index 7a69a632..50b12890 100644
--- a/src/api/platAuth.ts
+++ b/src/api/platAuth.ts
@@ -121,6 +121,20 @@ export const getThreadsAuthUrlApi = (mail: string) => {
});
};
+/**
+ * 获取linkedin授权链接
+ * 逻辑与facebook一致,仅platform传linkedin
+ */
+export const getLinkedInAuthUrlApi = (mail: string) => {
+ return request({
+ url: 'plat/meta/auth/url',
+ method: 'POST',
+ data: {
+ platform: 'linkedin',
+ },
+ });
+};
+
/**
* 获取tiktok授权状态
diff --git a/src/app/[lng]/accounts/components/AddAccountModal/index.tsx b/src/app/[lng]/accounts/components/AddAccountModal/index.tsx
index f012425e..1b05210d 100644
--- a/src/app/[lng]/accounts/components/AddAccountModal/index.tsx
+++ b/src/app/[lng]/accounts/components/AddAccountModal/index.tsx
@@ -14,6 +14,7 @@ import { instagramSkip } from "../../plat/InstagramLogin";
import { threadsSkip } from "../../plat/ThreadsLogin";
import { wxGzhSkip } from "../../plat/WxGzh";
import { pinterestSkip } from "../../plat/PinterestLogin";
+import { linkedinSkip } from "../../plat/LinkedinLogin";
import { useAccountStore } from "@/store/account";
import { useShallow } from "zustand/react/shallow";
import { getIpLocation, IpLocationInfo } from "@/utils/ipLocation";
@@ -254,6 +255,9 @@ const AddAccountModal = memo(
case PlatType.Pinterest:
await pinterestSkip(key);
break;
+ case PlatType.LinkedIn:
+ await linkedinSkip(key);
+ break;
}
// 如果指定了目标空间,等待授权完成后移动新账号
diff --git a/src/app/[lng]/accounts/plat/LinkedinLogin.ts b/src/app/[lng]/accounts/plat/LinkedinLogin.ts
new file mode 100644
index 00000000..4cd110fd
--- /dev/null
+++ b/src/app/[lng]/accounts/plat/LinkedinLogin.ts
@@ -0,0 +1,71 @@
+import { PlatType } from "@/app/config/platConfig";
+import { getLinkedInAuthUrlApi, checkMetaAuthApi } from "@/api/platAuth";
+import { useUserStore } from "@/store/user";
+
+/**
+ * LinkedIn 被点击
+ * @param platType 平台类型
+ */
+export async function linkedinSkip(platType: PlatType) {
+ if (platType !== PlatType.LinkedIn) return;
+
+ const res: any = await getLinkedInAuthUrlApi('pc');
+ if (res?.code == 1) {
+ useUserStore.getState().logout();
+ return;
+ }
+ if (res?.code !== 0) return;
+ const url = res.data.url;
+ window.open(`${url}`);
+
+ await linkedinLogin(res.data.taskId);
+}
+
+/**
+ * LinkedIn 轮询登录结果
+ * @param taskId 任务ID
+ */
+export function linkedinLogin(taskId: any): Promise<any> {
+ return new Promise(async (resolve, reject) => {
+ try {
+ let pollCount = 0;
+ const maxPollCount = 30;
+
+ const checkAuthStatus = async () => {
+ try {
+ pollCount++;
+ const authRess: any = await checkMetaAuthApi(taskId);
+ const authRes = authRess;
+ if (authRes?.code === 0 && authRes?.data.status == 1) {
+ resolve(authRes);
+ return true;
+ }
+ if (pollCount >= maxPollCount) {
+ return true;
+ }
+ } catch (error) {
+ return false;
+ }
+ };
+
+ const interval = setInterval(async () => {
+ const isSuccess = await checkAuthStatus();
+ if (isSuccess) {
+ clearInterval(interval);
+ if (pollCount >= maxPollCount) {
+ reject(new Error('授权超时,已达到最大轮询次数'));
+ }
+ }
+ }, 2000);
+
+ setTimeout(() => {
+ clearInterval(interval);
+ reject(new Error('授权超时'));
+ }, 5 * 60 * 1000);
+ } catch (e) {
+ reject(e);
+ }
+ });
+}
+
+