Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat: 授权改到后端
gaoSir9b1a594f875b
diff --git a/.env b/.envindex e2339e45..b8d1218f 100644--- a/.env+++ b/.env@@ -1,8 +1,3 @@# baseURL 代理字段NEXT_PUBLIC_API_URL_PROXY="/baseUrlProxy/"-# 快手API代理字段-NEXT_PUBLIC_API_PROXY="/kuaishoApi/"-# 快手API上传代理字段-NEXT_PUBLIC_API_UPLOAD_PROXY="/kuaishoUploadApi/"-diff --git a/.env.development b/.env.developmentindex bad81f21..795d825b 100644--- a/.env.development+++ b/.env.development@@ -1,5 +1,5 @@NEXT_PUBLIC_EVN=dev-# NEXT_PUBLIC_API_URL=http://localhost:7000/api/+NEXT_PUBLIC_API_URL=http://localhost:7000/api/-NEXT_PUBLIC_API_URL=https://apitest.aiearn.ai/api/\ No newline at end of file+#NEXT_PUBLIC_API_URL=https://apitest.aiearn.ai/api/\ No newline at end of filediff --git a/.idea/workspace.xml b/.idea/workspace.xmlindex 372d7ba1..d415a7e4 100644--- a/.idea/workspace.xml+++ b/.idea/workspace.xml@@ -5,16 +5,17 @@</component><component name="ChangeListManager"><list default="true" id="90ed3383-49aa-4e32-95a2-9f070c0da49b" name="更改" comment="feat: 拖动调整完成(目前等待接接口)">- <change afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/RecordCore.tsx" afterDir="false" />- <change afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/useCalendarTiming.ts" afterDir="false" />+ <change afterPath="$PROJECT_DIR$/src/api/plat/kwai.ts" afterDir="false" />+ <change afterPath="$PROJECT_DIR$/src/api/plat/types/kwai.type.ts" afterDir="false" />+ <change beforePath="$PROJECT_DIR$/.env" beforeDir="false" afterPath="$PROJECT_DIR$/.env" afterDir="false" />+ <change beforePath="$PROJECT_DIR$/.env.development" beforeDir="false" afterPath="$PROJECT_DIR$/.env.development" afterDir="false" /><change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />- <change beforePath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/BoxDragPreview.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/BoxDragPreview.tsx" afterDir="false" />- <change beforePath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CalendarRecord.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CalendarRecord.tsx" afterDir="false" />- <change beforePath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CalendarTimingItem.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CalendarTimingItem.tsx" afterDir="false" />- <change beforePath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CustomDragLayer.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CustomDragLayer.tsx" afterDir="false" />- <change beforePath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/calendarTimingItem.module.scss" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/calendarTimingItem.module.scss" afterDir="false" />+ <change beforePath="$PROJECT_DIR$/next.config.mjs" beforeDir="false" afterPath="$PROJECT_DIR$/next.config.mjs" afterDir="false" />+ <change beforePath="$PROJECT_DIR$/src/app/[lng]/accounts/components/AccountSidebar/AccountSidebar.module.scss" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/components/AccountSidebar/AccountSidebar.module.scss" afterDir="false" />+ <change beforePath="$PROJECT_DIR$/src/app/[lng]/accounts/components/AccountSidebar/UserManageModal.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/components/AccountSidebar/UserManageModal.tsx" afterDir="false" /><change beforePath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/index.tsx" afterDir="false" />- <change beforePath="$PROJECT_DIR$/src/app/layout/styles/lyaoutHeader.module.scss" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/layout/styles/lyaoutHeader.module.scss" afterDir="false" />+ <change beforePath="$PROJECT_DIR$/src/app/[lng]/accounts/plat/kwaiLogin.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/plat/kwaiLogin.ts" afterDir="false" />+ <change beforePath="$PROJECT_DIR$/src/constant.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/constant.ts" afterDir="false" /></list><option name="SHOW_DIALOG" value="false" /><option name="HIGHLIGHT_CONFLICTS" value="true" />@@ -117,7 +118,12 @@<workItem from="1751010085244" duration="6172000" /><workItem from="1751023561603" duration="4162000" /><workItem from="1751027862143" duration="5251000" />- <workItem from="1751248094372" duration="6605000" />+ <workItem from="1751248094372" duration="6674000" />+ <workItem from="1751263083581" duration="376000" />+ <workItem from="1751273285905" duration="3882000" />+ <workItem from="1751278214456" duration="955000" />+ <workItem from="1751334170049" duration="2844000" />+ <workItem from="1751351785412" duration="12693000" /></task><task id="LOCAL-00001" summary="feat: 日历完善"><option name="closed" value="true" />@@ -271,7 +277,15 @@<option name="project" value="LOCAL" /><updated>1751032440817</updated></task>- <option name="localTasksCounter" value="20" />+ <task id="LOCAL-00020" summary="feat: 拖动调整完成(目前等待接接口)">+ <option name="closed" value="true" />+ <created>1751256097944</created>+ <option name="number" value="00020" />+ <option name="presentableId" value="LOCAL-00020" />+ <option name="project" value="LOCAL" />+ <updated>1751256097944</updated>+ </task>+ <option name="localTasksCounter" value="21" /><servers /></component><component name="TypeScriptGeneratedFilesManager">diff --git a/next.config.mjs b/next.config.mjsindex 32447398..32c44d40 100644--- a/next.config.mjs+++ b/next.config.mjs@@ -42,14 +42,6 @@ nextConfig.rewrites = async () => {source: `${process.env.NEXT_PUBLIC_API_URL_PROXY}:path*`,destination: `${process.env.NEXT_PUBLIC_API_URL}:path*`,},- {- source: `${process.env.NEXT_PUBLIC_API_PROXY}:path*`,- destination: `https://open.kuaishou.com/:path*`,- },- {- source: `${process.env.NEXT_PUBLIC_API_UPLOAD_PROXY}:path*`,- destination: `https://upload.kuaishouzt.com/:path*`,- },];return {diff --git a/src/api/plat/kwai.ts b/src/api/plat/kwai.tsnew file mode 100644index 00000000..241fd517--- /dev/null+++ b/src/api/plat/kwai.ts@@ -0,0 +1,25 @@+import http from "@/utils/request";++/**+ * 获取快手授权地址+ * @returns+ */+export const getKwaiAuthUrlApi = (+ type: "h5" | "pc",+ redirectUriredirectUri: string,+) => {+ return http.get<string>(`plat/kwai/auth/url`, {+ type,+ redirectUriredirectUri,+ });+};++/**+ * 添加快手账户+ * @param code+ */+export const addKwaiAccountApi = (code: string) => {+ return http.get<string>(`plat/kwai/addAccount`, {+ code,+ });+};diff --git a/src/api/plat/types/kwai.type.ts b/src/api/plat/types/kwai.type.tsnew file mode 100644index 00000000..e69de29bdiff --git a/src/app/[lng]/accounts/components/AccountSidebar/AccountSidebar.module.scss b/src/app/[lng]/accounts/components/AccountSidebar/AccountSidebar.module.scssindex a1bbafb1..7f3a1f64 100644--- a/src/app/[lng]/accounts/components/AccountSidebar/AccountSidebar.module.scss+++ b/src/app/[lng]/accounts/components/AccountSidebar/AccountSidebar.module.scss@@ -369,6 +369,11 @@overflow: hidden;white-space: nowrap;text-overflow: ellipsis;+ display: flex;+ align-items: center;+ &-name {+ margin-left: 15px;+ }&--disable {filter: grayscale(100%);opacity: 0.5;diff --git a/src/app/[lng]/accounts/components/AccountSidebar/UserManageModal.tsx b/src/app/[lng]/accounts/components/AccountSidebar/UserManageModal.tsxindex e98e17e8..59e32b8e 100644--- a/src/app/[lng]/accounts/components/AccountSidebar/UserManageModal.tsx+++ b/src/app/[lng]/accounts/components/AccountSidebar/UserManageModal.tsx@@ -8,7 +8,6 @@ import {useState,} from "react";import {- Avatar,Button,Drawer,message,@@ -106,7 +105,8 @@ const UserManageModal = memo(<divclassName={`userManage-content-user ${am.status === AccountStatus.DISABLE ? "userManage-content-user--disable" : ""}`}>- <Avatar src={am.avatar} />+ {/*<Avatar src={am.avatar} />*/}+ <AvatarPlat account={am} size="large" /><spanclassName="userManage-content-user-name"title={am.nickname}diff --git a/src/app/[lng]/accounts/components/CalendarTiming/index.tsx b/src/app/[lng]/accounts/components/CalendarTiming/index.tsxindex 4de8f69c..0d037b70 100644--- a/src/app/[lng]/accounts/components/CalendarTiming/index.tsx+++ b/src/app/[lng]/accounts/components/CalendarTiming/index.tsx@@ -82,8 +82,9 @@ const CalendarTiming = memo(const style = window.getComputedStyle(el);const paddingLeft = parseFloat(style.paddingLeft);const paddingRight = parseFloat(style.paddingRight);+setCalendarCallWidth(el.clientWidth - (paddingLeft + paddingRight));- }, 1);+ }, 100);};// 动画触发函数diff --git a/src/app/[lng]/accounts/plat/kwaiLogin.ts b/src/app/[lng]/accounts/plat/kwaiLogin.tsindex a1c17bb6..b8e7d14b 100644--- a/src/app/[lng]/accounts/plat/kwaiLogin.ts+++ b/src/app/[lng]/accounts/plat/kwaiLogin.ts@@ -1,53 +1,22 @@-import qs from "qs";import { PlatType } from "@/app/config/platConfig";-import { requestPlatApi } from "@/utils/otherRequest";-import { KwaiPlat } from "@/app/plat/platChildren/kwai/KwaiPlat";-import { createOrUpdateAccountApi } from "@/api/account";+import { addKwaiAccountApi, getKwaiAuthUrlApi } from "@/api/plat/kwai";export const kwaiAppId = "ks715790869885446758";-export const kwaiAppSecret = "cqSvJvBSPJjd-4pBH_4N0Q";-export function kwaiSkip(platType: PlatType) {- const authParams = qs.stringify({- app_id: kwaiAppId,- scope: "user_info,user_video_publish",- response_type: "code",- ua: "pc",- redirect_uri: `https://localhost:6060/accounts/add?platType=${platType}`,- });- window.open(`https://open.kuaishou.com/oauth2/authorize?${authParams}`);+export async function kwaiSkip(platType: PlatType) {+ const res = await getKwaiAuthUrlApi(+ "pc",+ `${location.origin}/accounts/add?platType=${platType}`,+ );+ if (!res?.data) return;+ window.open(res?.data);}export function kwaiLogin(code: string): Promise<boolean> {return new Promise(async (resolve, reject) => {try {- const accessTokenRes = await requestPlatApi({- url: `/kuaishoApi/oauth2/access_token`,- method: "GET",- params: {- app_id: kwaiAppId,- app_secret: kwaiAppSecret,- code,- grant_type: "authorization_code",- },- });- if (accessTokenRes?.result !== 1) {- return reject("accessToken 获取失败!");- }- const kwaiPlat = new KwaiPlat({- access_token: accessTokenRes.access_token,- refresh_token: accessTokenRes.refresh_token,- });- const userInfo = await kwaiPlat.getAccountInfo();- userInfo!.account = accessTokenRes.open_id;- userInfo!.uid = accessTokenRes.open_id;- userInfo!["refresh_token"] = accessTokenRes.refresh_token;- userInfo!["access_token"] = accessTokenRes.access_token;-- const res = await createOrUpdateAccountApi({- ...userInfo,- }).catch(() => false);- resolve(!!res);+ const res = await addKwaiAccountApi(code);+ resolve(!!res?.data);} catch (e) {reject(e);}diff --git a/src/constant.ts b/src/constant.tsindex e326c720..45b9b701 100644--- a/src/constant.ts+++ b/src/constant.ts@@ -1,14 +1,5 @@// api urlexport const APP_HOT_URL = "https://att-contents.yikart.cn/api";-// 快手API代理地址-export const KwaiApiProxyUrl = process.env.NEXT_PUBLIC_API_PROXY;-// 快手API 上传 代理地址-export const KwaiApiUploadProxyUrl = process.env.NEXT_PUBLIC_API_UPLOAD_PROXY;-// 代理地址-export const ProxyUrls = [- process.env.NEXT_PUBLIC_API_URL_PROXY,- KwaiApiProxyUrl,- KwaiApiUploadProxyUrl,-];+export const ProxyUrls = [process.env.NEXT_PUBLIC_API_URL_PROXY];