feat(config): Update encryption fields in configuration form and refactor OAuth callback parameters

This commit is contained in:
web@ppanel 2025-01-20 22:23:04 +07:00
parent d1f5a9b825
commit 652e0323fd
5 changed files with 69 additions and 22 deletions

View File

@ -41,8 +41,8 @@ import { z } from 'zod';
const formSchema = z.object({
app_id: z.number().optional(),
app_key: z.string().optional(),
encryption: z.string().optional(),
encryption_key: z.string().optional(),
encryption_method: z.string().optional(),
startup_picture: z.string().optional(),
startup_picture_skip_time: z.number().optional(),
domains: z.array(z.string()).optional(),
@ -59,8 +59,8 @@ export default function ConfigForm() {
resolver: zodResolver(formSchema),
defaultValues: {
app_id: 0,
app_key: '',
encryption: '',
encryption_key: '',
encryption_method: '',
startup_picture: '',
startup_picture_skip_time: 0,
domains: [],
@ -85,17 +85,17 @@ export default function ConfigForm() {
useEffect(() => {
if (data) {
form.reset({
...data,
domains: data.domains || [],
});
form.reset(data);
}
}, [data, form]);
async function onSubmit(values: FormSchema) {
setLoading(true);
try {
await updateApplicationConfig(values as API.ApplicationConfig);
await updateApplicationConfig({
...values,
domains: values.domains?.filter((domain) => domain),
} as API.ApplicationConfig);
toast.success(t('updateSuccess'));
refetch();
setOpen(false);
@ -147,7 +147,7 @@ export default function ConfigForm() {
/>
<FormField
control={form.control}
name='app_key'
name='encryption_key'
render={({ field }) => (
<FormItem>
<FormLabel>{t('communicationKey')}</FormLabel>
@ -176,7 +176,7 @@ export default function ConfigForm() {
/>
<FormField
control={form.control}
name='encryption'
name='encryption_method'
render={({ field }) => (
<FormItem>
<FormLabel>{t('encryption')}</FormLabel>
@ -252,15 +252,12 @@ export default function ConfigForm() {
<FormDescription>{t('backupDomainsDescription')}</FormDescription>
<FormControl>
<Textarea
className='h-52'
className='h-28'
placeholder='example.com'
value={field.value?.join('\n')}
onChange={(e) =>
form.setValue(
'domains',
e.target.value.split('\n').filter((line) => line.trim()),
)
}
onChange={(e) => {
form.setValue(field.name, e.target.value.split('\n'));
}}
/>
</FormControl>
<FormMessage />

View File

@ -1,5 +1,5 @@
// @ts-ignore
// API 更新时间:
// API 唯一标识:
import * as announcement from './announcement';

View File

@ -1,5 +1,5 @@
// @ts-ignore
// API 更新时间:
// API 唯一标识:
import * as auth from './auth';

View File

@ -3,9 +3,36 @@
import request from '@/utils/request';
/** Apple Login Callback POST /v1/auth/oauth/callback/apple */
export async function appleLoginCallback(options?: { [key: string]: any }) {
export async function appleLoginCallback(
body: {
code: string;
id_token: string;
state: string;
},
options?: { [key: string]: any },
) {
const formData = new FormData();
Object.keys(body).forEach((ele) => {
const item = (body as any)[ele];
if (item !== undefined && item !== null) {
if (typeof item === 'object' && !(item instanceof File)) {
if (item instanceof Array) {
item.forEach((f) => formData.append(ele, f || ''));
} else {
formData.append(ele, JSON.stringify(item));
}
} else {
formData.append(ele, item);
}
}
});
return request<API.Response & { data?: any }>('/v1/auth/oauth/callback/apple', {
method: 'POST',
data: formData,
requestType: 'form',
...(options || {}),
});
}
@ -19,9 +46,16 @@ export async function facebookLoginCallback(options?: { [key: string]: any }) {
}
/** Google Login Callback GET /v1/auth/oauth/callback/google */
export async function googleLoginCallback(options?: { [key: string]: any }) {
export async function googleLoginCallback(
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
params: API.GoogleLoginCallbackParams,
options?: { [key: string]: any },
) {
return request<API.Response & { data?: any }>('/v1/auth/oauth/callback/google', {
method: 'GET',
params: {
...params,
},
...(options || {}),
});
}

View File

@ -10,6 +10,12 @@ declare namespace API {
updated_at: number;
};
type AppleLoginCallbackRequest = {
code: string;
id_token: string;
state: string;
};
type Application = {
id: number;
icon: string;
@ -172,6 +178,16 @@ declare namespace API {
tos_content: string;
};
type GoogleLoginCallbackParams = {
code: string;
state: string;
};
type GoogleLoginCallbackRequest = {
code: string;
state: string;
};
type Hysteria2 = {
port: number;
hop_ports: string;