feat(snapshot): backend restore api

This commit is contained in:
Nicolas Meienberger
2025-10-31 21:15:43 +01:00
parent 5846c1ff86
commit c7db88fb56
7 changed files with 251 additions and 7 deletions

View File

@@ -24,6 +24,7 @@ import {
getRepository,
listSnapshots,
listSnapshotFiles,
restoreSnapshot,
listBackupSchedules,
createBackupSchedule,
deleteBackupSchedule,
@@ -69,6 +70,8 @@ import type {
GetRepositoryData,
ListSnapshotsData,
ListSnapshotFilesData,
RestoreSnapshotData,
RestoreSnapshotResponse,
ListBackupSchedulesData,
CreateBackupScheduleData,
CreateBackupScheduleResponse,
@@ -738,6 +741,46 @@ export const listSnapshotFilesOptions = (options: Options<ListSnapshotFilesData>
});
};
export const restoreSnapshotQueryKey = (options: Options<RestoreSnapshotData>) =>
createQueryKey("restoreSnapshot", options);
/**
* Restore a snapshot to a target path on the filesystem
*/
export const restoreSnapshotOptions = (options: Options<RestoreSnapshotData>) => {
return queryOptions({
queryFn: async ({ queryKey, signal }) => {
const { data } = await restoreSnapshot({
...options,
...queryKey[0],
signal,
throwOnError: true,
});
return data;
},
queryKey: restoreSnapshotQueryKey(options),
});
};
/**
* Restore a snapshot to a target path on the filesystem
*/
export const restoreSnapshotMutation = (
options?: Partial<Options<RestoreSnapshotData>>,
): UseMutationOptions<RestoreSnapshotResponse, DefaultError, Options<RestoreSnapshotData>> => {
const mutationOptions: UseMutationOptions<RestoreSnapshotResponse, DefaultError, Options<RestoreSnapshotData>> = {
mutationFn: async (localOptions) => {
const { data } = await restoreSnapshot({
...options,
...localOptions,
throwOnError: true,
});
return data;
},
};
return mutationOptions;
};
export const listBackupSchedulesQueryKey = (options?: Options<ListBackupSchedulesData>) =>
createQueryKey("listBackupSchedules", options);