mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
feat(repositories): list snapshots api
This commit is contained in:
@@ -22,6 +22,7 @@ import {
|
||||
createRepository,
|
||||
deleteRepository,
|
||||
getRepository,
|
||||
listSnapshots,
|
||||
} from "../sdk.gen";
|
||||
import { queryOptions, type UseMutationOptions, type DefaultError } from "@tanstack/react-query";
|
||||
import type {
|
||||
@@ -57,6 +58,7 @@ import type {
|
||||
DeleteRepositoryData,
|
||||
DeleteRepositoryResponse,
|
||||
GetRepositoryData,
|
||||
ListSnapshotsData,
|
||||
} from "../types.gen";
|
||||
import { client as _heyApiClient } from "../client.gen";
|
||||
|
||||
@@ -671,3 +673,23 @@ export const getRepositoryOptions = (options: Options<GetRepositoryData>) => {
|
||||
queryKey: getRepositoryQueryKey(options),
|
||||
});
|
||||
};
|
||||
|
||||
export const listSnapshotsQueryKey = (options: Options<ListSnapshotsData>) => createQueryKey("listSnapshots", options);
|
||||
|
||||
/**
|
||||
* List all snapshots in a repository
|
||||
*/
|
||||
export const listSnapshotsOptions = (options: Options<ListSnapshotsData>) => {
|
||||
return queryOptions({
|
||||
queryFn: async ({ queryKey, signal }) => {
|
||||
const { data } = await listSnapshots({
|
||||
...options,
|
||||
...queryKey[0],
|
||||
signal,
|
||||
throwOnError: true,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
queryKey: listSnapshotsQueryKey(options),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -52,6 +52,8 @@ import type {
|
||||
DeleteRepositoryResponses,
|
||||
GetRepositoryData,
|
||||
GetRepositoryResponses,
|
||||
ListSnapshotsData,
|
||||
ListSnapshotsResponses,
|
||||
} from "./types.gen";
|
||||
import { client as _heyApiClient } from "./client.gen";
|
||||
|
||||
@@ -321,3 +323,15 @@ export const getRepository = <ThrowOnError extends boolean = false>(
|
||||
...options,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* List all snapshots in a repository
|
||||
*/
|
||||
export const listSnapshots = <ThrowOnError extends boolean = false>(
|
||||
options: Options<ListSnapshotsData, ThrowOnError>,
|
||||
) => {
|
||||
return (options.client ?? _heyApiClient).get<ListSnapshotsResponses, unknown, ThrowOnError>({
|
||||
url: "/api/v1/repositories/{name}/snapshots",
|
||||
...options,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -778,6 +778,32 @@ export type GetRepositoryResponses = {
|
||||
|
||||
export type GetRepositoryResponse = GetRepositoryResponses[keyof GetRepositoryResponses];
|
||||
|
||||
export type ListSnapshotsData = {
|
||||
body?: never;
|
||||
path: {
|
||||
name: string;
|
||||
};
|
||||
query?: never;
|
||||
url: "/api/v1/repositories/{name}/snapshots";
|
||||
};
|
||||
|
||||
export type ListSnapshotsResponses = {
|
||||
/**
|
||||
* List of snapshots
|
||||
*/
|
||||
200: {
|
||||
snapshots: Array<{
|
||||
duration: number;
|
||||
paths: Array<string>;
|
||||
short_id: string;
|
||||
size: number;
|
||||
time: number;
|
||||
}>;
|
||||
};
|
||||
};
|
||||
|
||||
export type ListSnapshotsResponse = ListSnapshotsResponses[keyof ListSnapshotsResponses];
|
||||
|
||||
export type ClientOptions = {
|
||||
baseUrl: "http://192.168.2.42:4096" | (string & {});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user