Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
授权账户weti
bulaienaofutuojsonzhangab071fb9f6a3
diff --git a/src/api/plat/kwai.ts b/src/api/plat/kwai.tsindex b4730999..3e233b29 100644--- a/src/api/plat/kwai.ts+++ b/src/api/plat/kwai.ts@@ -3,13 +3,16 @@ import { GetKwaiAuthStatusRes } from "@/api/plat/types/kwai.types";/*** 创建快手授权+ * @param type 授权类型+ * @param spaceId 空间ID(可选)* @returns*/-export const createKwaiAuth = (type: "h5" | "pc") => {+export const createKwaiAuth = (type: "h5" | "pc", spaceId?: string) => {+ const params = spaceId ? { spaceId } : {};return http.get<{url: string;taskId: string;- }>(`plat/kwai/auth/url/${type}`);+ }>(`plat/kwai/auth/url/${type}`, params);};// 获取账号授权状态diff --git a/src/api/platAuth.ts b/src/api/platAuth.tsindex 50b12890..1c0da4ab 100644--- a/src/api/platAuth.ts+++ b/src/api/platAuth.ts@@ -2,11 +2,15 @@ import http from "@/utils/request";import { request } from "@/utils/request";// 获取 YouTube 授权 URL-export const getYouTubeAuthUrlApi = (mail: string) => {+export const getYouTubeAuthUrlApi = (mail: string, spaceId?: string) => {+ const params: any = { type: 'pc' };+ if (spaceId) {+ params.spaceId = spaceId;+ }return request({url: 'plat/youtube/auth/url',method: 'GET',- params: { type: 'pc' },+ params,});};@@ -65,16 +69,21 @@ export const getYouTubeChannelSectionsApi = (data: any) => {/*** 获取facebook授权状态- * @param taskId 任务ID+ * @param mail 邮箱+ * @param spaceId 空间ID(可选)* @returns*/-export const getFacebookAuthUrlApi = (mail: string) => {+export const getFacebookAuthUrlApi = (mail: string, spaceId?: string) => {+ const data: any = {+ platform: 'facebook',+ };+ if (spaceId) {+ data.spaceId = spaceId;+ }return request({url: 'plat/meta/auth/url',method: 'POST',- data: {- platform: 'facebook',- },+ data,});};@@ -91,16 +100,21 @@ export const checkMetaAuthApi = ( taskId:any ) => {/*** 获取instagram授权状态- * @param taskId 任务ID+ * @param mail 邮箱+ * @param spaceId 空间ID(可选)* @returns*/-export const getInstagramAuthUrlApi = (mail: string) => {+export const getInstagramAuthUrlApi = (mail: string, spaceId?: string) => {+ const data: any = {+ platform: 'instagram',+ };+ if (spaceId) {+ data.spaceId = spaceId;+ }return request({url: 'plat/meta/auth/url',method: 'POST',- data: {- platform: 'instagram',- },+ data,});};@@ -108,44 +122,60 @@ export const getInstagramAuthUrlApi = (mail: string) => {/*** 获取threads授权状态- * @param taskId 任务ID+ * @param mail 邮箱+ * @param spaceId 空间ID(可选)* @returns*/-export const getThreadsAuthUrlApi = (mail: string) => {+export const getThreadsAuthUrlApi = (mail: string, spaceId?: string) => {+ const data: any = {+ platform: 'threads',+ };+ if (spaceId) {+ data.spaceId = spaceId;+ }return request({url: 'plat/meta/auth/url',method: 'POST',- data: {- platform: 'threads',- },+ data,});};/*** 获取linkedin授权链接* 逻辑与facebook一致,仅platform传linkedin+ * @param mail 邮箱+ * @param spaceId 空间ID(可选)*/-export const getLinkedInAuthUrlApi = (mail: string) => {+export const getLinkedInAuthUrlApi = (mail: string, spaceId?: string) => {+ const data: any = {+ platform: 'linkedin',+ };+ if (spaceId) {+ data.spaceId = spaceId;+ }return request({url: 'plat/meta/auth/url',method: 'POST',- data: {- platform: 'linkedin',- },+ data,});};/*** 获取tiktok授权状态- * @param taskId 任务ID+ * @param mail 邮箱+ * @param spaceId 空间ID(可选)* @returns*/-export const getTiktokAuthUrlApi = (mail: string) => {+export const getTiktokAuthUrlApi = (mail: string, spaceId?: string) => {+ const data: any = { type: 'pc' };+ if (spaceId) {+ data.spaceId = spaceId;+ }return request({url: 'plat/tiktok/auth/url',method: 'POST',- data: { type: 'pc' },+ data,});};@@ -158,11 +188,15 @@ export const checkTiktokAuthApi = ( taskId:any ) => {// 微信授权-export const getWxGzhAuthUrlApi = (mail: string) => {+export const getWxGzhAuthUrlApi = (mail: string, spaceId?: string) => {+ const params: any = { type: 'pc' };+ if (spaceId) {+ params.spaceId = spaceId;+ }return request({url: 'plat/wxGzh/auth/url/pc',method: 'GET',- params: { type: 'pc' },+ params,});};@@ -175,14 +209,20 @@ export const checkWxGzAuthApi = ( taskId:any ) => {/**- * 获取facebook授权状态- * @param taskId 任务ID+ * 获取pinterest授权状态+ * @param mail 邮箱+ * @param spaceId 空间ID(可选)* @returns*/-export const getPinterestAuthUrlApi = (mail: string) => {+export const getPinterestAuthUrlApi = (mail: string, spaceId?: string) => {+ const params: any = {};+ if (spaceId) {+ params.spaceId = spaceId;+ }return request({url: 'plat/pinterest/getAuth',method: 'GET',+ params,});};diff --git a/src/api/twitter.ts b/src/api/twitter.tsindex 305e6666..ec4eb758 100644--- a/src/api/twitter.ts+++ b/src/api/twitter.ts@@ -2,12 +2,15 @@ import http from "@/utils/request";import { request } from "@/utils/request";// 获取 Twitter 授权 URL-export const getTwitterAuthUrlApi = (mail: string) => {+export const getTwitterAuthUrlApi = (mail: string, spaceId?: string) => {+ const data: any = {};+ if (spaceId) {+ data.spaceId = spaceId;+ }return request({url: 'plat/twitter/auth/url',method: 'POST',- data: {- },+ data,});};diff --git a/src/app/[lng]/accounts/components/AddAccountModal/index.tsx b/src/app/[lng]/accounts/components/AddAccountModal/index.tsxindex 1b05210d..49bbb1d3 100644--- a/src/app/[lng]/accounts/components/AddAccountModal/index.tsx+++ b/src/app/[lng]/accounts/components/AddAccountModal/index.tsx@@ -19,7 +19,6 @@ import { useAccountStore } from "@/store/account";import { useShallow } from "zustand/react/shallow";import { getIpLocation, IpLocationInfo } from "@/utils/ipLocation";import DownloadAppModal from "@/components/common/DownloadAppModal";-import { updateAccountApi } from "@/api/account";const { Text } = Typography;@@ -220,23 +219,23 @@ const AddAccountModal = memo(switch (key) {case PlatType.KWAI:- await kwaiSkip(key);+ await kwaiSkip(key, selectedSpaceId);break;case PlatType.BILIBILI:- await bilibiliSkip(key);+ await bilibiliSkip(key, selectedSpaceId);break;case PlatType.YouTube:- await youtubeSkip(key);+ await youtubeSkip(key, selectedSpaceId);break;case PlatType.Twitter:- await twitterSkip(key);+ await twitterSkip(key, selectedSpaceId);break;case PlatType.Tiktok:- await tiktokSkip(key);+ await tiktokSkip(key, selectedSpaceId);break;case PlatType.Facebook:try {- await facebookSkip(key);+ await facebookSkip(key, selectedSpaceId);// Facebook授权成功后显示页面选择弹窗handleFacebookAuthSuccess();} catch (error) {@@ -244,80 +243,31 @@ const AddAccountModal = memo(}break;case PlatType.Instagram:- await instagramSkip(key);+ await instagramSkip(key, selectedSpaceId);break;case PlatType.Threads:- await threadsSkip(key);+ await threadsSkip(key, selectedSpaceId);break;case PlatType.WxGzh:- await wxGzhSkip(key);+ await wxGzhSkip(key, selectedSpaceId);break;case PlatType.Pinterest:- await pinterestSkip(key);+ await pinterestSkip(key, selectedSpaceId);break;case PlatType.LinkedIn:- await linkedinSkip(key);+ await linkedinSkip(key, selectedSpaceId);break;}- // 如果指定了目标空间,等待授权完成后移动新账号- if (selectedSpaceId) {- // 检查选中的空间是否是默认空间- const targetGroup = accountGroupList.find(group => group.id === selectedSpaceId);- const isDefaultSpace = targetGroup?.isDefault;-- // console.log('移动空间调试信息:', {- // selectedSpaceId,- // targetGroupName: targetGroup?.name,- // isDefaultSpace,- // showSpaceSelector,- // spaceSelectionRequired- // });-- // 只有当选择了非默认空间时才移动账号- if (!isDefaultSpace) {- console.log('准备移动账号到空间:', targetGroup?.name);- setTimeout(async () => {- try {- // 刷新账号列表- await getAccountList();-- // 获取最新的账号组列表- const currentState = useAccountStore.getState();- const defaultGroup = currentState.accountGroupList.find(group => group.isDefault);-- if (defaultGroup) {- // 找到相同平台类型的最后一个账号(最新添加的)- const sameTypeAccounts = defaultGroup.children.filter(account => account.type === key);- const latestAccount = sameTypeAccounts[sameTypeAccounts.length - 1];-- if (latestAccount) {- console.log('找到最新账号:', latestAccount.account, '平台:', key);-- // 将新账号移动到指定空间- console.log('移动账号:', latestAccount.account, '到空间:', targetGroup?.name);- await updateAccountApi({- id: latestAccount.id,- groupId: selectedSpaceId- });- } else {- console.log('未找到相同平台类型的账号');- }-- // 再次刷新账号列表以更新UI- await getAccountList();- console.log('账号移动完成');- }- } catch (error) {- console.error('移动账号到指定空间失败:', error);- }- }, 3000); // 等待3秒让授权完成- } else {- console.log('选择的是默认空间,无需移动账号');+ // 授权完成后刷新账号列表+ setTimeout(async () => {+ try {+ await getAccountList();+ console.log('账号列表已刷新');+ } catch (error) {+ console.error('刷新账号列表失败:', error);}- } else {- console.log('未选择空间,不移动账号');- }+ }, 2000); // 等待3秒让授权完成};return (diff --git a/src/app/[lng]/accounts/plat/BilibiliLogin.ts b/src/app/[lng]/accounts/plat/BilibiliLogin.tsindex 2e8562e1..7727dca2 100644--- a/src/app/[lng]/accounts/plat/BilibiliLogin.ts+++ b/src/app/[lng]/accounts/plat/BilibiliLogin.ts@@ -9,10 +9,10 @@ import { useUserStore } from "@/store/user";* b站被点击* @param platType*/-export async function bilibiliSkip(platType: PlatType) {+export async function bilibiliSkip(platType: PlatType, spaceId?: string) {if (platType !== PlatType.BILIBILI) return;- const res: any = await apiGetBilibiliLoginUrl('pc');+ const res: any = await apiGetBilibiliLoginUrl('pc', spaceId);if (res?.code == 1) {useUserStore.getState().logout();returndiff --git a/src/app/[lng]/accounts/plat/FacebookLogin.ts b/src/app/[lng]/accounts/plat/FacebookLogin.tsindex 586eeeb1..7cd6f037 100644--- a/src/app/[lng]/accounts/plat/FacebookLogin.ts+++ b/src/app/[lng]/accounts/plat/FacebookLogin.ts@@ -11,10 +11,10 @@ import { useUserStore } from "@/store/user";* Facebook被点击* @param platType*/-export async function facebookSkip(platType: PlatType) {+export async function facebookSkip(platType: PlatType, spaceId?: string) {if (platType !== PlatType.Facebook) return;- const res: any = await getFacebookAuthUrlApi('pc');+ const res: any = await getFacebookAuthUrlApi('pc', spaceId);if (res?.code == 1) {useUserStore.getState().logout();returndiff --git a/src/app/[lng]/accounts/plat/InstagramLogin.ts b/src/app/[lng]/accounts/plat/InstagramLogin.tsindex 31f3800d..c230a450 100644--- a/src/app/[lng]/accounts/plat/InstagramLogin.ts+++ b/src/app/[lng]/accounts/plat/InstagramLogin.ts@@ -9,10 +9,10 @@ import { useUserStore } from "@/store/user";* b站被点击* @param platType*/-export async function instagramSkip(platType: PlatType) {+export async function instagramSkip(platType: PlatType, spaceId?: string) {if (platType !== PlatType.Instagram) return;- const res: any = await getInstagramAuthUrlApi('pc');+ const res: any = await getInstagramAuthUrlApi('pc', spaceId);if (res?.code == 1) {useUserStore.getState().logout();returndiff --git a/src/app/[lng]/accounts/plat/LinkedinLogin.ts b/src/app/[lng]/accounts/plat/LinkedinLogin.tsindex 7fdda97b..479917a2 100644--- a/src/app/[lng]/accounts/plat/LinkedinLogin.ts+++ b/src/app/[lng]/accounts/plat/LinkedinLogin.ts@@ -7,10 +7,10 @@ import { useAccountStore } from "@/store/account";* LinkedIn 被点击* @param platType 平台类型*/-export async function linkedinSkip(platType: PlatType) {+export async function linkedinSkip(platType: PlatType, spaceId?: string) {if (platType !== PlatType.LinkedIn) return;- const res: any = await getLinkedInAuthUrlApi('pc');+ const res: any = await getLinkedInAuthUrlApi('pc', spaceId);if (res?.code == 1) {useUserStore.getState().logout();return;diff --git a/src/app/[lng]/accounts/plat/PinterestLogin.ts b/src/app/[lng]/accounts/plat/PinterestLogin.tsindex e1ecfcf1..21b5e110 100644--- a/src/app/[lng]/accounts/plat/PinterestLogin.ts+++ b/src/app/[lng]/accounts/plat/PinterestLogin.ts@@ -9,10 +9,10 @@ import { useUserStore } from "@/store/user";* Pinterest被点击* @param platType*/-export async function pinterestSkip(platType: PlatType) {+export async function pinterestSkip(platType: PlatType, spaceId?: string) {if (platType !== PlatType.Pinterest) return;- const res: any = await getPinterestAuthUrlApi('pc');+ const res: any = await getPinterestAuthUrlApi('pc', spaceId);if (res?.code == 1) {useUserStore.getState().logout();returndiff --git a/src/app/[lng]/accounts/plat/ThreadsLogin.ts b/src/app/[lng]/accounts/plat/ThreadsLogin.tsindex 80b7d6a9..07ee17b4 100644--- a/src/app/[lng]/accounts/plat/ThreadsLogin.ts+++ b/src/app/[lng]/accounts/plat/ThreadsLogin.ts@@ -9,10 +9,10 @@ import { useUserStore } from "@/store/user";* b站被点击* @param platType*/-export async function threadsSkip(platType: PlatType) {+export async function threadsSkip(platType: PlatType, spaceId?: string) {if (platType !== PlatType.Threads) return;- const res: any = await getThreadsAuthUrlApi('pc');+ const res: any = await getThreadsAuthUrlApi('pc', spaceId);if (res?.code == 1) {useUserStore.getState().logout();returndiff --git a/src/app/[lng]/accounts/plat/TiktokLogin.ts b/src/app/[lng]/accounts/plat/TiktokLogin.tsindex 6ec3bb55..dbab29fa 100644--- a/src/app/[lng]/accounts/plat/TiktokLogin.ts+++ b/src/app/[lng]/accounts/plat/TiktokLogin.ts@@ -9,10 +9,10 @@ import { useUserStore } from "@/store/user";* Tiktok被点击* @param platType*/-export async function tiktokSkip(platType: PlatType) {+export async function tiktokSkip(platType: PlatType, spaceId?: string) {if (platType !== PlatType.Tiktok) return;- const res: any = await getTiktokAuthUrlApi('pc');+ const res: any = await getTiktokAuthUrlApi('pc', spaceId);if (res?.code == 1) {useUserStore.getState().logout();returndiff --git a/src/app/[lng]/accounts/plat/TwtterLogin.ts b/src/app/[lng]/accounts/plat/TwtterLogin.tsindex e9b27452..c0b72fe8 100644--- a/src/app/[lng]/accounts/plat/TwtterLogin.ts+++ b/src/app/[lng]/accounts/plat/TwtterLogin.ts@@ -9,10 +9,10 @@ import { useUserStore } from "@/store/user";* b站被点击* @param platType*/-export async function twitterSkip(platType: PlatType) {+export async function twitterSkip(platType: PlatType, spaceId?: string) {if (platType !== PlatType.Twitter) return;- const res: any = await getTwitterAuthUrlApi('pc');+ const res: any = await getTwitterAuthUrlApi('pc', spaceId);if (res?.code == 1) {useUserStore.getState().logout();returndiff --git a/src/app/[lng]/accounts/plat/WxGzh.ts b/src/app/[lng]/accounts/plat/WxGzh.tsindex 8b8554bf..12ce90e9 100644--- a/src/app/[lng]/accounts/plat/WxGzh.ts+++ b/src/app/[lng]/accounts/plat/WxGzh.ts@@ -9,10 +9,10 @@ import { useUserStore } from "@/store/user";* 微信被点击* @param platType*/-export async function wxGzhSkip(platType: PlatType) {+export async function wxGzhSkip(platType: PlatType, spaceId?: string) {if (platType !== PlatType.WxGzh) return;- const res: any = await getWxGzhAuthUrlApi('pc');+ const res: any = await getWxGzhAuthUrlApi('pc', spaceId);if (res?.code == 1) {useUserStore.getState().logout();returndiff --git a/src/app/[lng]/accounts/plat/YoutubeLogin.ts b/src/app/[lng]/accounts/plat/YoutubeLogin.tsindex 0fee7a9a..a3fc113a 100644--- a/src/app/[lng]/accounts/plat/YoutubeLogin.ts+++ b/src/app/[lng]/accounts/plat/YoutubeLogin.ts@@ -9,10 +9,10 @@ import { useUserStore } from "@/store/user";* b站被点击* @param platType*/-export async function youtubeSkip(platType: PlatType) {+export async function youtubeSkip(platType: PlatType, spaceId?: string) {if (platType !== PlatType.YouTube) return;- const res: any = await getYouTubeAuthUrlApi('pc');+ const res: any = await getYouTubeAuthUrlApi('pc', spaceId);if (res?.code == 1) {useUserStore.getState().logout();returndiff --git a/src/app/[lng]/accounts/plat/kwaiLogin.ts b/src/app/[lng]/accounts/plat/kwaiLogin.tsindex bd6f3b4e..6e871b30 100644--- a/src/app/[lng]/accounts/plat/kwaiLogin.ts+++ b/src/app/[lng]/accounts/plat/kwaiLogin.ts@@ -4,8 +4,8 @@ import { sleep } from "@/utils";import { useAccountStore } from "@/store/account";import { useUserStore } from "@/store/user";-export async function kwaiSkip(platType: PlatType) {- const res = await createKwaiAuth("pc");+export async function kwaiSkip(platType: PlatType, spaceId?: string) {+ const res = await createKwaiAuth("pc", spaceId);if (res?.code == 1) {useUserStore.getState().logout();returndiff --git a/src/components/PublishDialog/index.tsx b/src/components/PublishDialog/index.tsxindex bd198620..2b90ed1c 100644--- a/src/components/PublishDialog/index.tsx+++ b/src/components/PublishDialog/index.tsx@@ -58,7 +58,6 @@ import { wxGzhSkip } from "@/app/[lng]/accounts/plat/WxGzh";import { pinterestSkip } from "@/app/[lng]/accounts/plat/PinterestLogin";import { linkedinSkip } from "@/app/[lng]/accounts/plat/LinkedinLogin";import { useAccountStore } from "@/store/account";-import { updateAccountApi } from "@/api/account";export interface IPublishDialogRef {// 设置发布时间@@ -283,6 +282,67 @@ const PublishDialog = memo(},[accountGroupList, getAccountList],);+ // 根据平台类型调用对应的授权函数,传递目标空间ID+ switch (platform) {+ case PlatType.KWAI:+ await kwaiSkip(platform, targetSpaceId);+ break;+ case PlatType.BILIBILI:+ await bilibiliSkip(platform, targetSpaceId);+ break;+ case PlatType.YouTube:+ await youtubeSkip(platform, targetSpaceId);+ break;+ case PlatType.Twitter:+ await twitterSkip(platform, targetSpaceId);+ break;+ case PlatType.Tiktok:+ await tiktokSkip(platform, targetSpaceId);+ break;+ case PlatType.Facebook:+ try {+ await facebookSkip(platform, targetSpaceId);+ // Facebook授权成功后显示页面选择弹窗+ // handleFacebookAuthSuccess(); // 这里可能需要处理Facebook页面选择+ } catch (error) {+ console.error('Facebook授权失败:', error);+ }+ break;+ case PlatType.Instagram:+ await instagramSkip(platform, targetSpaceId);+ break;+ case PlatType.Threads:+ await threadsSkip(platform, targetSpaceId);+ break;+ case PlatType.WxGzh:+ await wxGzhSkip(platform, targetSpaceId);+ break;+ case PlatType.Pinterest:+ await pinterestSkip(platform, targetSpaceId);+ break;+ case PlatType.LinkedIn:+ await linkedinSkip(platform, targetSpaceId);+ break;+ default:+ console.warn(`未支持的平台类型: ${platform}`);+ message.warning(`暂不支持 ${platform} 平台的直接授权`);+ return;+ }++ // 授权完成后刷新账号列表+ setTimeout(async () => {+ try {+ await getAccountList();+ console.log('账号列表已刷新');+ } catch (error) {+ console.error('刷新账号列表失败:', error);+ }+ }, 3000); // 等待3秒让授权完成+ } catch (error) {+ console.error('授权失败:', error);+ message.error('授权失败,请重试');+ }+ }, [accountGroupList, getAccountList]);// 内容安全检测函数const handleContentModeration = useCallback(async () => {diff --git a/src/components/PublishDialog/usePublishDialogData.ts b/src/components/PublishDialog/usePublishDialogData.tsindex 2f58818b..c8b39699 100644--- a/src/components/PublishDialog/usePublishDialogData.ts+++ b/src/components/PublishDialog/usePublishDialogData.ts@@ -55,7 +55,7 @@ export const usePublishDialogData = create(const res = await apiGetBilibiliPartitions(useAccountStore.getState()- .accountList.find((v) => v.type === PlatType.BILIBILI)!.account,+ .accountList.find((v) => v.type === PlatType.BILIBILI)!.id,);set({bilibiliPartitions: res?.data,