diff --git a/apps/admin/app/dashboard/auth-control/apple/page.tsx b/apps/admin/app/dashboard/auth-control/apple/page.tsx index 97cb5ff..54f16ae 100644 --- a/apps/admin/app/dashboard/auth-control/apple/page.tsx +++ b/apps/admin/app/dashboard/auth-control/apple/page.tsx @@ -1,6 +1,6 @@ 'use client'; -import { getOAuthConfig, oAuthCreateConfig, updateOAuthConfig } from '@/services/admin/system'; +import { getOAuthByPlatform, updateOAuthConfig } from '@/services/admin/system'; import { useQuery } from '@tanstack/react-query'; import { Label } from '@workspace/ui/components/label'; import { Switch } from '@workspace/ui/components/switch'; @@ -14,28 +14,22 @@ export default function Page() { const t = useTranslations('apple'); const { data, refetch } = useQuery({ - queryKey: ['getOAuthConfig', 'apple'], + queryKey: ['getOAuthByPlatform', 'apple'], queryFn: async () => { - const { data } = await getOAuthConfig(); - return data.data?.list.find((item) => item.platform === 'apple') as API.OAuthConfig; + const { data } = await getOAuthByPlatform({ + platform: 'apple', + }); + return data.data; }, }); - async function updateConfig(key: keyof API.OAuthConfig, value: unknown) { + async function updateConfig(key: keyof API.UpdateOAuthConfig, value: unknown) { if (data?.[key] === value) return; try { - if (data?.id) { - await oAuthCreateConfig({ - ...data, - platform: 'apple', - [key]: value, - } as API.OAuthConfig); - } else { - await updateOAuthConfig({ - ...data, - [key]: value, - } as API.OAuthConfig); - } + await updateOAuthConfig({ + ...data, + [key]: value, + } as API.UpdateOAuthConfig); toast.success(t('saveSuccess')); refetch(); } catch (error) { @@ -66,21 +60,13 @@ export default function Page() { updateConfig('team_id', value)} - /> - - - - - {t('clientId')} - {t('clientIdDescription')} - - - updateConfig('client_id', value)} + value={data?.config?.team_id} + onValueBlur={(value) => { + updateConfig('config', { + ...data?.config, + team_id: value, + }); + }} /> @@ -92,8 +78,31 @@ export default function Page() { updateConfig('key_id', value)} + value={data?.config?.key_id} + onValueBlur={(value) => { + updateConfig('config', { + ...data?.config, + key_id: value, + }); + }} + /> + + + + + {t('clientId')} + {t('clientIdDescription')} + + + { + updateConfig('config', { + ...data?.config, + client_id: value, + }); + }} /> @@ -106,8 +115,13 @@ export default function Page() { updateConfig('client_secret', e.target.value)} + value={data?.config?.client_secret} + onBlur={(e) => { + updateConfig('config', { + ...data?.config, + client_secret: e.target.value, + }); + }} /> diff --git a/apps/admin/app/dashboard/auth-control/facebook/page.tsx b/apps/admin/app/dashboard/auth-control/facebook/page.tsx index a1161bf..051a05e 100644 --- a/apps/admin/app/dashboard/auth-control/facebook/page.tsx +++ b/apps/admin/app/dashboard/auth-control/facebook/page.tsx @@ -1,6 +1,6 @@ 'use client'; -import { getOAuthConfig, oAuthCreateConfig, updateOAuthConfig } from '@/services/admin/system'; +import { getOAuthByPlatform, updateOAuthConfig } from '@/services/admin/system'; import { useQuery } from '@tanstack/react-query'; import { Label } from '@workspace/ui/components/label'; import { Switch } from '@workspace/ui/components/switch'; @@ -13,28 +13,22 @@ export default function Page() { const t = useTranslations('facebook'); const { data, refetch } = useQuery({ - queryKey: ['getOAuthConfig', 'facebook'], + queryKey: ['getOAuthByPlatform', 'facebook'], queryFn: async () => { - const { data } = await getOAuthConfig(); - return data.data?.list.find((item) => item.platform === 'facebook') as API.OAuthConfig; + const { data } = await getOAuthByPlatform({ + platform: 'facebook', + }); + return data.data; }, }); - async function updateConfig(key: keyof API.OAuthConfig, value: unknown) { + async function updateConfig(key: keyof API.UpdateOAuthConfig, value: unknown) { if (data?.[key] === value) return; try { - if (data?.id) { - await oAuthCreateConfig({ - ...data, - platform: 'facebook', - [key]: value, - } as API.OAuthConfig); - } else { - await updateOAuthConfig({ - ...data, - [key]: value, - } as API.OAuthConfig); - } + await updateOAuthConfig({ + ...data, + [key]: value, + } as API.UpdateOAuthConfig); toast.success(t('saveSuccess')); refetch(); } catch (error) { @@ -65,8 +59,13 @@ export default function Page() { updateConfig('client_id', value)} + value={data?.config?.client_id} + onValueBlur={(value) => { + updateConfig('config', { + ...data?.config, + client_id: value, + }); + }} /> @@ -78,8 +77,13 @@ export default function Page() { updateConfig('client_secret', value)} + value={data?.config?.client_secret} + onValueBlur={(value) => { + updateConfig('config', { + ...data?.config, + client_secret: value, + }); + }} /> diff --git a/apps/admin/app/dashboard/auth-control/github/page.tsx b/apps/admin/app/dashboard/auth-control/github/page.tsx index cc6570c..1b2e1fa 100644 --- a/apps/admin/app/dashboard/auth-control/github/page.tsx +++ b/apps/admin/app/dashboard/auth-control/github/page.tsx @@ -1,6 +1,6 @@ 'use client'; -import { getOAuthConfig, oAuthCreateConfig, updateOAuthConfig } from '@/services/admin/system'; +import { getOAuthByPlatform, updateOAuthConfig } from '@/services/admin/system'; import { useQuery } from '@tanstack/react-query'; import { Label } from '@workspace/ui/components/label'; import { Switch } from '@workspace/ui/components/switch'; @@ -13,35 +13,28 @@ export default function Page() { const t = useTranslations('github'); const { data, refetch } = useQuery({ - queryKey: ['getOAuthConfig', 'github'], + queryKey: ['getOAuthByPlatform', 'github'], queryFn: async () => { - const { data } = await getOAuthConfig(); - return data.data?.list.find((item) => item.platform === 'github') as API.OAuthConfig; + const { data } = await getOAuthByPlatform({ + platform: 'github', + }); + return data.data; }, }); - async function updateConfig(key: keyof API.OAuthConfig, value: unknown) { + async function updateConfig(key: keyof API.UpdateOAuthConfig, value: unknown) { if (data?.[key] === value) return; try { - if (data?.id) { - await oAuthCreateConfig({ - ...data, - platform: 'github', - [key]: value, - } as API.OAuthConfig); - } else { - await updateOAuthConfig({ - ...data, - [key]: value, - } as API.OAuthConfig); - } + await updateOAuthConfig({ + ...data, + [key]: value, + } as API.UpdateOAuthConfig); toast.success(t('saveSuccess')); refetch(); } catch (error) { toast.error(t('saveFailed')); } } - return ( @@ -65,8 +58,13 @@ export default function Page() { updateConfig('client_id', value)} + value={data?.config?.client_id} + onValueBlur={(value) => + updateConfig('config', { + ...data?.config, + client_id: value, + }) + } /> @@ -78,8 +76,13 @@ export default function Page() { updateConfig('client_secret', value)} + value={data?.config?.client_secret} + onValueBlur={(value) => { + updateConfig('config', { + ...data?.config, + client_secret: value, + }); + }} /> diff --git a/apps/admin/app/dashboard/auth-control/google/page.tsx b/apps/admin/app/dashboard/auth-control/google/page.tsx index 406c5f0..abc6781 100644 --- a/apps/admin/app/dashboard/auth-control/google/page.tsx +++ b/apps/admin/app/dashboard/auth-control/google/page.tsx @@ -1,6 +1,6 @@ 'use client'; -import { getOAuthConfig, oAuthCreateConfig, updateOAuthConfig } from '@/services/admin/system'; +import { getOAuthByPlatform, updateOAuthConfig } from '@/services/admin/system'; import { useQuery } from '@tanstack/react-query'; import { Label } from '@workspace/ui/components/label'; import { Switch } from '@workspace/ui/components/switch'; @@ -13,28 +13,22 @@ export default function Page() { const t = useTranslations('google'); const { data, refetch } = useQuery({ - queryKey: ['getOAuthConfig', 'google'], + queryKey: ['getOAuthByPlatform', 'google'], queryFn: async () => { - const { data } = await getOAuthConfig(); - return data.data?.list.find((item) => item.platform === 'google') as API.OAuthConfig; + const { data } = await getOAuthByPlatform({ + platform: 'google', + }); + return data.data; }, }); - async function updateConfig(key: keyof API.OAuthConfig, value: unknown) { + async function updateConfig(key: keyof API.UpdateOAuthConfig, value: unknown) { if (data?.[key] === value) return; try { - if (data?.id) { - await oAuthCreateConfig({ - ...data, - platform: 'google', - [key]: value, - } as API.OAuthConfig); - } else { - await updateOAuthConfig({ - ...data, - [key]: value, - } as API.OAuthConfig); - } + await updateOAuthConfig({ + ...data, + [key]: value, + } as API.UpdateOAuthConfig); toast.success(t('saveSuccess')); refetch(); } catch (error) { @@ -65,8 +59,13 @@ export default function Page() { updateConfig('client_id', value)} + value={data?.config?.client_id} + onValueBlur={(value) => { + updateConfig('config', { + ...data?.config, + client_id: value, + }); + }} /> @@ -78,8 +77,13 @@ export default function Page() { updateConfig('client_secret', value)} + value={data?.config?.client_secret} + onValueBlur={(value) => { + updateConfig('config', { + ...data?.config, + client_secret: value, + }); + }} /> diff --git a/apps/admin/app/dashboard/auth-control/telegram/page.tsx b/apps/admin/app/dashboard/auth-control/telegram/page.tsx index 78f7d6e..d6a6d42 100644 --- a/apps/admin/app/dashboard/auth-control/telegram/page.tsx +++ b/apps/admin/app/dashboard/auth-control/telegram/page.tsx @@ -1,6 +1,6 @@ 'use client'; -import { getOAuthConfig, oAuthCreateConfig, updateOAuthConfig } from '@/services/admin/system'; +import { getOAuthByPlatform, updateOAuthConfig } from '@/services/admin/system'; import { useQuery } from '@tanstack/react-query'; import { Label } from '@workspace/ui/components/label'; import { Switch } from '@workspace/ui/components/switch'; @@ -13,28 +13,22 @@ export default function Page() { const t = useTranslations('telegram'); const { data, refetch } = useQuery({ - queryKey: ['getOAuthConfig', 'telegram'], + queryKey: ['getOAuthByPlatform', 'telegram'], queryFn: async () => { - const { data } = await getOAuthConfig(); - return data.data?.list.find((item) => item.platform === 'telegram') as API.OAuthConfig; + const { data } = await getOAuthByPlatform({ + platform: 'telegram', + }); + return data.data; }, }); - async function updateConfig(key: keyof API.OAuthConfig, value: unknown) { + async function updateConfig(key: keyof API.UpdateOAuthConfig, value: unknown) { if (data?.[key] === value) return; try { - if (data?.id) { - await oAuthCreateConfig({ - ...data, - platform: 'telegram', - [key]: value, - } as API.OAuthConfig); - } else { - await updateOAuthConfig({ - ...data, - [key]: value, - } as API.OAuthConfig); - } + await updateOAuthConfig({ + ...data, + [key]: value, + } as API.UpdateOAuthConfig); toast.success(t('saveSuccess')); refetch(); } catch (error) { @@ -65,8 +59,13 @@ export default function Page() { updateConfig('client_id', value)} + value={data?.config?.bot} + onValueBlur={(value) => { + updateConfig('config', { + ...data?.config, + bot: value, + }); + }} /> @@ -78,8 +77,13 @@ export default function Page() { updateConfig('client_secret', value)} + value={data?.config?.bot_token} + onValueBlur={(value) => { + updateConfig('config', { + ...data?.config, + bot_token: value, + }); + }} /> diff --git a/apps/admin/services/admin/system.ts b/apps/admin/services/admin/system.ts index 62acc47..61beae7 100644 --- a/apps/admin/services/admin/system.ts +++ b/apps/admin/services/admin/system.ts @@ -226,9 +226,9 @@ export async function updateNodeConfig(body: API.NodeConfig, options?: { [key: s }); } -/** Get OAuth config GET /v1/admin/system/oauth_config */ +/** Get oauth config GET /v1/admin/system/oauth_config */ export async function getOAuthConfig(options?: { [key: string]: any }) { - return request( + return request( '/v1/admin/system/oauth_config', { method: 'GET', @@ -238,7 +238,10 @@ export async function getOAuthConfig(options?: { [key: string]: any }) { } /** Update oauth config PUT /v1/admin/system/oauth_config */ -export async function updateOAuthConfig(body: API.OAuthConfig, options?: { [key: string]: any }) { +export async function updateOAuthConfig( + body: API.UpdateOAuthConfig, + options?: { [key: string]: any }, +) { return request('/v1/admin/system/oauth_config', { method: 'PUT', headers: { @@ -249,17 +252,17 @@ export async function updateOAuthConfig(body: API.OAuthConfig, options?: { [key: }); } -/** OAuth create config POST /v1/admin/system/oauth_config */ -export async function oAuthCreateConfig( - body: API.OAuthCreateRequest, +/** Get OAuth Config By Platform GET /v1/admin/system/oauth/platform */ +export async function getOAuthByPlatform( + // 叠加生成的Param类型 (非body参数swagger默认没有生成对象) + params: API.GetOAuthByPlatformParams, options?: { [key: string]: any }, ) { - return request('/v1/admin/system/oauth_config', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', + return request('/v1/admin/system/oauth/platform', { + method: 'GET', + params: { + ...params, }, - data: body, ...(options || {}), }); } diff --git a/apps/admin/services/admin/typings.d.ts b/apps/admin/services/admin/typings.d.ts index 9b57ccc..a5aff95 100644 --- a/apps/admin/services/admin/typings.d.ts +++ b/apps/admin/services/admin/typings.d.ts @@ -27,6 +27,7 @@ declare namespace API { }; type ApplicationConfig = { + encryption: boolean; domains: string[]; startup_picture: string; startup_picture_skip_time: number; @@ -457,6 +458,18 @@ declare namespace API { list: Server[]; }; + type GetOAuthByPlatformParams = { + platform: string; + }; + + type GetOAuthByPlatformRequest = { + platform: string; + }; + + type GetOAuthConfigResponse = { + list: OAuthMethod[]; + }; + type GetOrderListParams = { page: number; size: number; @@ -619,29 +632,14 @@ declare namespace API { last_at: number; }; - type OAuthConfig = { + type OAuthMethod = { id: number; - platform: 'github' | 'google' | 'apple' | 'qq' | 'wechat' | 'telegram' | 'facebook'; - team_id: string; - key_id: string; - client_id: string; - client_secret: string; + platform: string; + config: Record; redirect: string; enabled: boolean; - }; - - type OAuthCreateRequest = { - platform: 'github' | 'google' | 'apple' | 'qq' | 'wechat' | 'telegram' | 'facebook'; - team_id: string; - key_id: string; - client_id: string; - client_secret: string; - enabled: boolean; - redirect: string; - }; - - type OAuthQueryResponse = { - list: OAuthConfig[]; + created_at: number; + updated_at: number; }; type OnlineUser = { @@ -1126,6 +1124,14 @@ declare namespace API { sort: number; }; + type UpdateOAuthConfig = { + id: number; + platform: string; + config: Record; + redirect: string; + enabled: boolean; + }; + type UpdateOrderStatusRequest = { id: number; status: number; diff --git a/apps/admin/services/common/typings.d.ts b/apps/admin/services/common/typings.d.ts index d153cb8..7d461d8 100644 --- a/apps/admin/services/common/typings.d.ts +++ b/apps/admin/services/common/typings.d.ts @@ -19,6 +19,7 @@ declare namespace API { }; type ApplicationConfig = { + encryption: boolean; domains: string[]; startup_picture: string; startup_picture_skip_time: number; @@ -210,21 +211,20 @@ declare namespace API { method: string; }; - type OAuthConfig = { - id: number; - platform: 'github' | 'google' | 'apple' | 'qq' | 'wechat' | 'telegram' | 'facebook'; - team_id: string; - key_id: string; - client_id: string; - client_secret: string; - redirect: string; - enabled: boolean; - }; - type OAuthLoginResponse = { redirect: string; }; + type OAuthMethod = { + id: number; + platform: string; + config: Record; + redirect: string; + enabled: boolean; + created_at: number; + updated_at: number; + }; + type OnlineUser = { uid: number; ip: string;
{t('clientIdDescription')}