✨ feat(config): Update encryption fields in configuration form and refactor OAuth callback parameters
This commit is contained in:
parent
d1f5a9b825
commit
652e0323fd
@ -41,8 +41,8 @@ import { z } from 'zod';
|
|||||||
|
|
||||||
const formSchema = z.object({
|
const formSchema = z.object({
|
||||||
app_id: z.number().optional(),
|
app_id: z.number().optional(),
|
||||||
app_key: z.string().optional(),
|
encryption_key: z.string().optional(),
|
||||||
encryption: z.string().optional(),
|
encryption_method: z.string().optional(),
|
||||||
startup_picture: z.string().optional(),
|
startup_picture: z.string().optional(),
|
||||||
startup_picture_skip_time: z.number().optional(),
|
startup_picture_skip_time: z.number().optional(),
|
||||||
domains: z.array(z.string()).optional(),
|
domains: z.array(z.string()).optional(),
|
||||||
@ -59,8 +59,8 @@ export default function ConfigForm() {
|
|||||||
resolver: zodResolver(formSchema),
|
resolver: zodResolver(formSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
app_id: 0,
|
app_id: 0,
|
||||||
app_key: '',
|
encryption_key: '',
|
||||||
encryption: '',
|
encryption_method: '',
|
||||||
startup_picture: '',
|
startup_picture: '',
|
||||||
startup_picture_skip_time: 0,
|
startup_picture_skip_time: 0,
|
||||||
domains: [],
|
domains: [],
|
||||||
@ -85,17 +85,17 @@ export default function ConfigForm() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) {
|
if (data) {
|
||||||
form.reset({
|
form.reset(data);
|
||||||
...data,
|
|
||||||
domains: data.domains || [],
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}, [data, form]);
|
}, [data, form]);
|
||||||
|
|
||||||
async function onSubmit(values: FormSchema) {
|
async function onSubmit(values: FormSchema) {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
await updateApplicationConfig(values as API.ApplicationConfig);
|
await updateApplicationConfig({
|
||||||
|
...values,
|
||||||
|
domains: values.domains?.filter((domain) => domain),
|
||||||
|
} as API.ApplicationConfig);
|
||||||
toast.success(t('updateSuccess'));
|
toast.success(t('updateSuccess'));
|
||||||
refetch();
|
refetch();
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
@ -147,7 +147,7 @@ export default function ConfigForm() {
|
|||||||
/>
|
/>
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name='app_key'
|
name='encryption_key'
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>{t('communicationKey')}</FormLabel>
|
<FormLabel>{t('communicationKey')}</FormLabel>
|
||||||
@ -176,7 +176,7 @@ export default function ConfigForm() {
|
|||||||
/>
|
/>
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name='encryption'
|
name='encryption_method'
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>{t('encryption')}</FormLabel>
|
<FormLabel>{t('encryption')}</FormLabel>
|
||||||
@ -252,15 +252,12 @@ export default function ConfigForm() {
|
|||||||
<FormDescription>{t('backupDomainsDescription')}</FormDescription>
|
<FormDescription>{t('backupDomainsDescription')}</FormDescription>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Textarea
|
<Textarea
|
||||||
className='h-52'
|
className='h-28'
|
||||||
placeholder='example.com'
|
placeholder='example.com'
|
||||||
value={field.value?.join('\n')}
|
value={field.value?.join('\n')}
|
||||||
onChange={(e) =>
|
onChange={(e) => {
|
||||||
form.setValue(
|
form.setValue(field.name, e.target.value.split('\n'));
|
||||||
'domains',
|
}}
|
||||||
e.target.value.split('\n').filter((line) => line.trim()),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|||||||
@ -3,9 +3,36 @@
|
|||||||
import request from '@/utils/request';
|
import request from '@/utils/request';
|
||||||
|
|
||||||
/** Apple Login Callback POST /v1/auth/oauth/callback/apple */
|
/** 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', {
|
return request<API.Response & { data?: any }>('/v1/auth/oauth/callback/apple', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
data: formData,
|
||||||
|
requestType: 'form',
|
||||||
...(options || {}),
|
...(options || {}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -19,9 +46,16 @@ export async function facebookLoginCallback(options?: { [key: string]: any }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Google Login Callback GET /v1/auth/oauth/callback/google */
|
/** 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', {
|
return request<API.Response & { data?: any }>('/v1/auth/oauth/callback/google', {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
...params,
|
||||||
|
},
|
||||||
...(options || {}),
|
...(options || {}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
16
apps/admin/services/common/typings.d.ts
vendored
16
apps/admin/services/common/typings.d.ts
vendored
@ -10,6 +10,12 @@ declare namespace API {
|
|||||||
updated_at: number;
|
updated_at: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type AppleLoginCallbackRequest = {
|
||||||
|
code: string;
|
||||||
|
id_token: string;
|
||||||
|
state: string;
|
||||||
|
};
|
||||||
|
|
||||||
type Application = {
|
type Application = {
|
||||||
id: number;
|
id: number;
|
||||||
icon: string;
|
icon: string;
|
||||||
@ -172,6 +178,16 @@ declare namespace API {
|
|||||||
tos_content: string;
|
tos_content: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type GoogleLoginCallbackParams = {
|
||||||
|
code: string;
|
||||||
|
state: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type GoogleLoginCallbackRequest = {
|
||||||
|
code: string;
|
||||||
|
state: string;
|
||||||
|
};
|
||||||
|
|
||||||
type Hysteria2 = {
|
type Hysteria2 = {
|
||||||
port: number;
|
port: number;
|
||||||
hop_ports: string;
|
hop_ports: string;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user