refactor: simplify snapshot file explorer

This commit is contained in:
Nicolas Meienberger
2025-11-04 14:57:22 +01:00
parent 11ca80a929
commit d1e46918ec
16 changed files with 309 additions and 258 deletions

View File

@@ -23,6 +23,7 @@ import {
deleteRepository,
getRepository,
listSnapshots,
getSnapshotDetails,
listSnapshotFiles,
restoreSnapshot,
listBackupSchedules,
@@ -69,6 +70,7 @@ import type {
DeleteRepositoryResponse,
GetRepositoryData,
ListSnapshotsData,
GetSnapshotDetailsData,
ListSnapshotFilesData,
RestoreSnapshotData,
RestoreSnapshotResponse,
@@ -720,6 +722,27 @@ export const listSnapshotsOptions = (options: Options<ListSnapshotsData>) => {
});
};
export const getSnapshotDetailsQueryKey = (options: Options<GetSnapshotDetailsData>) =>
createQueryKey("getSnapshotDetails", options);
/**
* Get details of a specific snapshot
*/
export const getSnapshotDetailsOptions = (options: Options<GetSnapshotDetailsData>) => {
return queryOptions({
queryFn: async ({ queryKey, signal }) => {
const { data } = await getSnapshotDetails({
...options,
...queryKey[0],
signal,
throwOnError: true,
});
return data;
},
queryKey: getSnapshotDetailsQueryKey(options),
});
};
export const listSnapshotFilesQueryKey = (options: Options<ListSnapshotFilesData>) =>
createQueryKey("listSnapshotFiles", options);

View File

@@ -50,6 +50,8 @@ import type {
GetRepositoryResponses,
ListSnapshotsData,
ListSnapshotsResponses,
GetSnapshotDetailsData,
GetSnapshotDetailsResponses,
ListSnapshotFilesData,
ListSnapshotFilesResponses,
RestoreSnapshotData,
@@ -352,6 +354,18 @@ export const listSnapshots = <ThrowOnError extends boolean = false>(
});
};
/**
* Get details of a specific snapshot
*/
export const getSnapshotDetails = <ThrowOnError extends boolean = false>(
options: Options<GetSnapshotDetailsData, ThrowOnError>,
) => {
return (options.client ?? _heyApiClient).get<GetSnapshotDetailsResponses, unknown, ThrowOnError>({
url: "/api/v1/repositories/{name}/snapshots/{snapshotId}",
...options,
});
};
/**
* List files and directories in a snapshot
*/

View File

@@ -802,6 +802,31 @@ export type ListSnapshotsResponses = {
export type ListSnapshotsResponse = ListSnapshotsResponses[keyof ListSnapshotsResponses];
export type GetSnapshotDetailsData = {
body?: never;
path: {
name: string;
snapshotId: string;
};
query?: never;
url: "/api/v1/repositories/{name}/snapshots/{snapshotId}";
};
export type GetSnapshotDetailsResponses = {
/**
* Snapshot details
*/
200: {
duration: number;
paths: Array<string>;
short_id: string;
size: number;
time: number;
};
};
export type GetSnapshotDetailsResponse = GetSnapshotDetailsResponses[keyof GetSnapshotDetailsResponses];
export type ListSnapshotFilesData = {
body?: never;
path: {