feat(snapshots): list files in snapshots api

This commit is contained in:
Nicolas Meienberger
2025-10-30 18:58:57 +01:00
parent ed73ca73fb
commit b80a187108
8 changed files with 251 additions and 2 deletions

View File

@@ -23,6 +23,7 @@ import {
deleteRepository,
getRepository,
listSnapshots,
listSnapshotFiles,
listBackupSchedules,
createBackupSchedule,
deleteBackupSchedule,
@@ -67,6 +68,7 @@ import type {
DeleteRepositoryResponse,
GetRepositoryData,
ListSnapshotsData,
ListSnapshotFilesData,
ListBackupSchedulesData,
CreateBackupScheduleData,
CreateBackupScheduleResponse,
@@ -715,6 +717,27 @@ export const listSnapshotsOptions = (options: Options<ListSnapshotsData>) => {
});
};
export const listSnapshotFilesQueryKey = (options: Options<ListSnapshotFilesData>) =>
createQueryKey("listSnapshotFiles", options);
/**
* List files and directories in a snapshot
*/
export const listSnapshotFilesOptions = (options: Options<ListSnapshotFilesData>) => {
return queryOptions({
queryFn: async ({ queryKey, signal }) => {
const { data } = await listSnapshotFiles({
...options,
...queryKey[0],
signal,
throwOnError: true,
});
return data;
},
queryKey: listSnapshotFilesQueryKey(options),
});
};
export const listBackupSchedulesQueryKey = (options?: Options<ListBackupSchedulesData>) =>
createQueryKey("listBackupSchedules", options);

View File

@@ -50,6 +50,8 @@ import type {
GetRepositoryResponses,
ListSnapshotsData,
ListSnapshotsResponses,
ListSnapshotFilesData,
ListSnapshotFilesResponses,
ListBackupSchedulesData,
ListBackupSchedulesResponses,
CreateBackupScheduleData,
@@ -348,6 +350,18 @@ export const listSnapshots = <ThrowOnError extends boolean = false>(
});
};
/**
* List files and directories in a snapshot
*/
export const listSnapshotFiles = <ThrowOnError extends boolean = false>(
options: Options<ListSnapshotFilesData, ThrowOnError>,
) => {
return (options.client ?? _heyApiClient).get<ListSnapshotFilesResponses, unknown, ThrowOnError>({
url: "/api/v1/repositories/{name}/snapshots/{snapshotId}/files",
...options,
});
};
/**
* List all backup schedules
*/

View File

@@ -788,7 +788,7 @@ export type ListSnapshotsData = {
name: string;
};
query?: {
volumeId?: number;
volumeId?: string;
};
url: "/api/v1/repositories/{name}/snapshots";
};
@@ -810,6 +810,47 @@ export type ListSnapshotsResponses = {
export type ListSnapshotsResponse = ListSnapshotsResponses[keyof ListSnapshotsResponses];
export type ListSnapshotFilesData = {
body?: never;
path: {
name: string;
snapshotId: string;
};
query?: {
path?: string;
};
url: "/api/v1/repositories/{name}/snapshots/{snapshotId}/files";
};
export type ListSnapshotFilesResponses = {
/**
* List of files and directories in the snapshot
*/
200: {
files: Array<{
name: string;
path: string;
type: string;
atime?: string;
ctime?: string;
gid?: number;
mode?: number;
mtime?: string;
size?: number;
uid?: number;
}>;
snapshot: {
hostname: string;
id: string;
paths: Array<string>;
short_id: string;
time: string;
};
};
};
export type ListSnapshotFilesResponse = ListSnapshotFilesResponses[keyof ListSnapshotFilesResponses];
export type ListBackupSchedulesData = {
body?: never;
path?: never;

View File

@@ -23,7 +23,7 @@ export const ScheduleSummary = (props: Props) => {
const { data: snapshots, isLoading: loadingSnapshots } = useQuery({
...listSnapshotsOptions({
path: { name: repository.name },
query: { volumeId: volume.id },
query: { volumeId: volume.id.toString() },
}),
refetchInterval: 10000,
refetchOnWindowFocus: true,