Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
188 lines
4.7 KiB
TypeScript
188 lines
4.7 KiB
TypeScript
import { apiClient } from '../client'
|
|
|
|
export interface BackupS3Config {
|
|
endpoint: string
|
|
region: string
|
|
bucket: string
|
|
access_key_id: string
|
|
secret_access_key?: string
|
|
prefix: string
|
|
force_path_style: boolean
|
|
}
|
|
|
|
export interface BackupScheduleConfig {
|
|
enabled: boolean
|
|
cron_expr: string
|
|
retain_days: number
|
|
retain_count: number
|
|
}
|
|
|
|
export interface BackupRecord {
|
|
id: string
|
|
status: 'pending' | 'running' | 'completed' | 'failed'
|
|
backup_type: string
|
|
file_name: string
|
|
s3_key: string
|
|
parts?: BackupPart[]
|
|
size_bytes: number
|
|
triggered_by: string
|
|
error_message?: string
|
|
started_at: string
|
|
finished_at?: string
|
|
expires_at?: string
|
|
progress?: string
|
|
restore_status?: string
|
|
restore_error?: string
|
|
restored_at?: string
|
|
}
|
|
|
|
export interface BackupPart {
|
|
index: number
|
|
s3_key: string
|
|
size_bytes: number
|
|
sha256?: string
|
|
}
|
|
|
|
export interface BackupDownloadPart {
|
|
index: number
|
|
size_bytes: number
|
|
url: string
|
|
}
|
|
|
|
export interface BackupDownloadResponse {
|
|
url?: string
|
|
parts?: BackupDownloadPart[]
|
|
}
|
|
|
|
export interface CreateBackupRequest {
|
|
expire_days?: number
|
|
}
|
|
|
|
export interface TestS3Response {
|
|
ok: boolean
|
|
message: string
|
|
}
|
|
|
|
// S3 Config
|
|
export async function getS3Config(): Promise<BackupS3Config> {
|
|
const { data } = await apiClient.get<BackupS3Config>('/admin/backups/s3-config')
|
|
return data
|
|
}
|
|
|
|
export async function updateS3Config(config: BackupS3Config): Promise<BackupS3Config> {
|
|
const { data } = await apiClient.put<BackupS3Config>('/admin/backups/s3-config', config)
|
|
return data
|
|
}
|
|
|
|
export async function testS3Connection(config: BackupS3Config): Promise<TestS3Response> {
|
|
const { data } = await apiClient.post<TestS3Response>('/admin/backups/s3-config/test', config)
|
|
return data
|
|
}
|
|
|
|
// Async image object storage
|
|
//
|
|
// Shares the S3 client with backups, so `reuse_backup_s3` borrows the endpoint and
|
|
// credentials configured above and only keeps its own bucket/prefix.
|
|
export interface ImageStorageConfig {
|
|
enabled: boolean
|
|
reuse_backup_s3: boolean
|
|
bucket: string
|
|
prefix: string
|
|
public_base_url: string
|
|
presign_expiry_hours: number
|
|
max_download_bytes: number
|
|
endpoint: string
|
|
region: string
|
|
access_key_id: string
|
|
secret_access_key?: string
|
|
force_path_style: boolean
|
|
}
|
|
|
|
export interface ImageStorageConfigResponse {
|
|
config: ImageStorageConfig
|
|
secret_configured: boolean
|
|
}
|
|
|
|
export async function getImageStorageConfig(): Promise<ImageStorageConfigResponse> {
|
|
const { data } = await apiClient.get<ImageStorageConfigResponse>('/admin/backups/image-storage')
|
|
return data
|
|
}
|
|
|
|
export async function updateImageStorageConfig(
|
|
config: ImageStorageConfig,
|
|
): Promise<ImageStorageConfig> {
|
|
const { data } = await apiClient.put<ImageStorageConfig>('/admin/backups/image-storage', config)
|
|
return data
|
|
}
|
|
|
|
export async function testImageStorageConnection(
|
|
config: ImageStorageConfig,
|
|
): Promise<TestS3Response> {
|
|
const { data } = await apiClient.post<TestS3Response>(
|
|
'/admin/backups/image-storage/test',
|
|
config,
|
|
)
|
|
return data
|
|
}
|
|
|
|
// Schedule
|
|
export async function getSchedule(): Promise<BackupScheduleConfig> {
|
|
const { data } = await apiClient.get<BackupScheduleConfig>('/admin/backups/schedule')
|
|
return data
|
|
}
|
|
|
|
export async function updateSchedule(config: BackupScheduleConfig): Promise<BackupScheduleConfig> {
|
|
const { data } = await apiClient.put<BackupScheduleConfig>('/admin/backups/schedule', config)
|
|
return data
|
|
}
|
|
|
|
// Backup operations
|
|
export async function createBackup(req?: CreateBackupRequest): Promise<BackupRecord> {
|
|
const { data } = await apiClient.post<BackupRecord>('/admin/backups', req || {})
|
|
return data
|
|
}
|
|
|
|
export async function listBackups(): Promise<{ items: BackupRecord[] }> {
|
|
const { data } = await apiClient.get<{ items: BackupRecord[] }>('/admin/backups')
|
|
return data
|
|
}
|
|
|
|
export async function getBackup(id: string): Promise<BackupRecord> {
|
|
const { data } = await apiClient.get<BackupRecord>(`/admin/backups/${id}`)
|
|
return data
|
|
}
|
|
|
|
export async function deleteBackup(id: string): Promise<void> {
|
|
await apiClient.delete(`/admin/backups/${id}`)
|
|
}
|
|
|
|
export async function getDownloadURL(id: string): Promise<BackupDownloadResponse> {
|
|
const { data } = await apiClient.get<BackupDownloadResponse>(`/admin/backups/${id}/download-url`)
|
|
return data
|
|
}
|
|
|
|
// Restore
|
|
export async function restoreBackup(id: string, password: string): Promise<BackupRecord> {
|
|
const { data } = await apiClient.post<BackupRecord>(`/admin/backups/${id}/restore`, { password })
|
|
return data
|
|
}
|
|
|
|
export const backupAPI = {
|
|
getS3Config,
|
|
updateS3Config,
|
|
testS3Connection,
|
|
getImageStorageConfig,
|
|
updateImageStorageConfig,
|
|
testImageStorageConnection,
|
|
getSchedule,
|
|
updateSchedule,
|
|
createBackup,
|
|
listBackups,
|
|
getBackup,
|
|
deleteBackup,
|
|
getDownloadURL,
|
|
restoreBackup,
|
|
}
|
|
|
|
export default backupAPI
|