mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-02 14:56:38 +08:00
[功能] 添加批量更新选项接口,支持一次性更新多个配置项,更新相关逻辑和测试
This commit is contained in:
@@ -12,7 +12,7 @@ import {useAuth} from '@/components/providers/auth-provider';
|
||||
import {AppCard} from '@/components/ui/app-card';
|
||||
import {StatusBadge} from '@/components/ui/status-badge';
|
||||
import {getConfigVersionPreview} from '@/features/config-versions/api/config-versions';
|
||||
import {getOptions, updateOption} from '@/features/settings/api/settings';
|
||||
import {getOptions, updateOptions} from '@/features/settings/api/settings';
|
||||
import type {OptionItem} from '@/features/settings/types';
|
||||
import {
|
||||
CodeBlock,
|
||||
@@ -277,9 +277,7 @@ export function PerformancePage() {
|
||||
entries: Array<[string, string]>,
|
||||
successMessage: string,
|
||||
) => {
|
||||
for (const [key, value] of entries) {
|
||||
await updateOption(key, value);
|
||||
}
|
||||
await updateOptions(entries.map(([key, value]) => ({key, value})));
|
||||
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({queryKey: settingsQueryKey}),
|
||||
|
||||
@@ -5,6 +5,7 @@ import type {
|
||||
DatabaseCleanupPayload,
|
||||
DatabaseCleanupResult,
|
||||
GeoIPLookupResult,
|
||||
OptionBatchPayload,
|
||||
OptionItem,
|
||||
SettingsProfile,
|
||||
UpdateSelfPayload,
|
||||
@@ -21,6 +22,13 @@ export function updateOption(key: string, value: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function updateOptions(options: OptionBatchPayload['options']) {
|
||||
return apiRequest<void>('/option/update-batch', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ options }),
|
||||
});
|
||||
}
|
||||
|
||||
export function lookupGeoIP(provider: string, ip: string) {
|
||||
return apiRequest<GeoIPLookupResult>('/option/geoip/lookup', {
|
||||
method: 'POST',
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
getSettingsProfile,
|
||||
lookupGeoIP,
|
||||
rotateBootstrapToken,
|
||||
updateOption,
|
||||
updateOptions,
|
||||
updateSelf,
|
||||
} from '@/features/settings/api/settings';
|
||||
import type {
|
||||
@@ -558,9 +558,7 @@ export function SettingsPage() {
|
||||
entries: Array<[string, string]>,
|
||||
successMessage: string,
|
||||
) => {
|
||||
for (const [key, value] of entries) {
|
||||
await updateOption(key, value);
|
||||
}
|
||||
await updateOptions(entries.map(([key, value]) => ({ key, value })));
|
||||
|
||||
await queryClient.invalidateQueries({ queryKey: settingsQueryKey });
|
||||
await queryClient.invalidateQueries({ queryKey: ['public-status'] });
|
||||
|
||||
@@ -5,6 +5,10 @@ export interface OptionItem {
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface OptionBatchPayload {
|
||||
options: OptionItem[];
|
||||
}
|
||||
|
||||
export interface BootstrapTokenPayload {
|
||||
discovery_token: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user