feat(Config): add backup and restore configuration functionality

This commit is contained in:
ShiYu
2025-05-24 00:49:48 +08:00
parent 5c5b63e82f
commit b76d462b12
6 changed files with 270 additions and 5 deletions

View File

@@ -72,3 +72,32 @@ export const hasRole = (userRole: string | undefined, requiredRole: UserRole): b
// 精确匹配角色
return userRole === requiredRole;
};
// 备份所有配置
export const backupConfigs = async (): Promise<BaseResult<Record<string, string>>> => {
try {
return await fetchApi<Record<string, string>>('/config/backup');
} catch (error: any) {
return {
success: false,
message: `备份配置失败: ${error.message}`,
code: 500
};
}
};
// 恢复配置
export const restoreConfigs = async (configBackup: Record<string, string>): Promise<BaseResult<boolean>> => {
try {
return await fetchApi<boolean>('/config/restore', {
method: 'POST',
body: JSON.stringify(configBackup),
});
} catch (error: any) {
return {
success: false,
message: `恢复配置失败: ${error.message}`,
code: 500
};
}
};

View File

@@ -51,6 +51,8 @@ export {
getConfig,
setConfig,
deleteConfig,
hasRole
hasRole,
backupConfigs,
restoreConfigs
} from './configApi';