mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-08 00:26:37 +08:00
数据导出
This commit is contained in:
@@ -6,6 +6,7 @@ import type {
|
||||
CreateSystemConfigRequest,
|
||||
CreateTemplateRequest,
|
||||
CreateUserRequest,
|
||||
DatabaseInfo,
|
||||
DispatchTaskRequest,
|
||||
ListTaskExecutionsRequest,
|
||||
ListTaskExecutionsResponse,
|
||||
@@ -330,6 +331,40 @@ export class AdminService extends BaseService {
|
||||
return this.get<SystemStatus>('/status');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据库信息
|
||||
* @returns 数据库类型、名称、版本信息
|
||||
* @throws {UnauthorizedError} 当未登录时
|
||||
* @throws {ForbiddenError} 当无管理员权限时
|
||||
*/
|
||||
static async getDatabaseInfo(): Promise<DatabaseInfo> {
|
||||
return this.get<DatabaseInfo>('/db-info');
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据库
|
||||
* SQLite 返回 .db 二进制,PostgreSQL 返回 pg_dump .sql 文本
|
||||
* @returns 包含文件 Blob 和建议文件名的对象
|
||||
* @throws {UnauthorizedError} 当未登录时
|
||||
* @throws {ForbiddenError} 当无管理员权限时
|
||||
*/
|
||||
static async exportDatabase(): Promise<{ blob: Blob; filename: string }> {
|
||||
const response = await import('axios').then(({ default: axios }) =>
|
||||
axios.get<Blob>(this.getFullPath('/db-export'), {
|
||||
withCredentials: true,
|
||||
responseType: 'blob',
|
||||
})
|
||||
);
|
||||
// 从 Content-Disposition 提取文件名
|
||||
const disposition = response.headers['content-disposition'] as string | undefined;
|
||||
let filename = 'wavelet_export';
|
||||
if (disposition) {
|
||||
const match = disposition.match(/filename="?([^";]+)"?/);
|
||||
if (match) filename = match[1];
|
||||
}
|
||||
return { blob: response.data, filename };
|
||||
}
|
||||
|
||||
// ==================== 系统日志 ====================
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,4 +39,5 @@ export type {
|
||||
ListUsersResponse,
|
||||
UpdateUserStatusRequest,
|
||||
SystemStatus,
|
||||
DatabaseInfo,
|
||||
} from './types';
|
||||
|
||||
@@ -381,3 +381,15 @@ export interface UpdateTemplateRequest {
|
||||
content: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据库信息
|
||||
*/
|
||||
export interface DatabaseInfo {
|
||||
/** 数据库类型:'sqlite' | 'postgres' */
|
||||
type: 'sqlite' | 'postgres';
|
||||
/** 数据库名称或文件路径 */
|
||||
name: string;
|
||||
/** 数据库版本字符串 */
|
||||
version: string;
|
||||
}
|
||||
|
||||
@@ -106,6 +106,7 @@ export type {
|
||||
ListUsersResponse,
|
||||
UpdateUserStatusRequest,
|
||||
SystemStatus,
|
||||
DatabaseInfo,
|
||||
} from './admin';
|
||||
|
||||
// 用户服务
|
||||
|
||||
Reference in New Issue
Block a user