feat: punkt 6 (backup) — ARQ cron job, backup config in settings, backup-now trigger, backup history, migration 0130
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
* - Delete backup
|
||||
*/
|
||||
|
||||
import { apiGet, apiPost, apiDelete } from './client';
|
||||
import { apiGet, apiPost, apiPut, apiDelete } from './client';
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
// ─── Types ──────────────────────────────────────────────────────────────────
|
||||
@@ -94,3 +94,76 @@ export function useDeleteBackup() {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// ─── Backup Configuration ────────────────────────────────────────────────────
|
||||
|
||||
export interface BackupConfig {
|
||||
backup_enabled: boolean;
|
||||
backup_interval: string;
|
||||
backup_retention_days: number;
|
||||
backup_destination: string;
|
||||
}
|
||||
|
||||
export interface BackupHistoryEntry {
|
||||
id: string;
|
||||
timestamp: string | null;
|
||||
action: string;
|
||||
success: boolean;
|
||||
destination: string;
|
||||
error: string;
|
||||
}
|
||||
|
||||
export interface BackupHistoryResponse {
|
||||
history: BackupHistoryEntry[];
|
||||
}
|
||||
|
||||
export async function fetchBackupConfig(): Promise<BackupConfig> {
|
||||
return apiGet<BackupConfig>('/system-settings/backup-config');
|
||||
}
|
||||
|
||||
export async function updateBackupConfig(config: Partial<BackupConfig>): Promise<BackupConfig> {
|
||||
return apiPut<BackupConfig>('/system-settings/backup-config', config);
|
||||
}
|
||||
|
||||
export async function triggerBackupNow(): Promise<{ message: string; job_id: string }> {
|
||||
return apiPost<{ message: string; job_id: string }>('/system-settings/backup-now');
|
||||
}
|
||||
|
||||
export async function fetchBackupHistory(): Promise<BackupHistoryResponse> {
|
||||
return apiGet<BackupHistoryResponse>('/system-settings/backup-history');
|
||||
}
|
||||
|
||||
export function useBackupConfig() {
|
||||
return useQuery<BackupConfig>({
|
||||
queryKey: ['backup-config'],
|
||||
queryFn: fetchBackupConfig,
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateBackupConfig() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<BackupConfig, Error, Partial<BackupConfig>>({
|
||||
mutationFn: updateBackupConfig,
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['backup-config'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useTriggerBackupNow() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<{ message: string; job_id: string }, Error>({
|
||||
mutationFn: triggerBackupNow,
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['backups'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['backup-history'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useBackupHistory() {
|
||||
return useQuery<BackupHistoryResponse>({
|
||||
queryKey: ['backup-history'],
|
||||
queryFn: fetchBackupHistory,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user