mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
feat(server): test mount endpoint
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
// This file is auto-generated by @hey-api/openapi-ts
|
||||
|
||||
import { type Options, listVolumes, createVolume, deleteVolume } from "../sdk.gen";
|
||||
import { type Options, listVolumes, createVolume, testConnection, deleteVolume } from "../sdk.gen";
|
||||
import { queryOptions, type UseMutationOptions, type DefaultError } from "@tanstack/react-query";
|
||||
import type {
|
||||
ListVolumesData,
|
||||
CreateVolumeData,
|
||||
CreateVolumeResponse,
|
||||
TestConnectionData,
|
||||
TestConnectionResponse,
|
||||
DeleteVolumeData,
|
||||
DeleteVolumeResponse,
|
||||
} from "../types.gen";
|
||||
@@ -109,6 +111,46 @@ export const createVolumeMutation = (
|
||||
return mutationOptions;
|
||||
};
|
||||
|
||||
export const testConnectionQueryKey = (options?: Options<TestConnectionData>) =>
|
||||
createQueryKey("testConnection", options);
|
||||
|
||||
/**
|
||||
* Test connection to backend
|
||||
*/
|
||||
export const testConnectionOptions = (options?: Options<TestConnectionData>) => {
|
||||
return queryOptions({
|
||||
queryFn: async ({ queryKey, signal }) => {
|
||||
const { data } = await testConnection({
|
||||
...options,
|
||||
...queryKey[0],
|
||||
signal,
|
||||
throwOnError: true,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
queryKey: testConnectionQueryKey(options),
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Test connection to backend
|
||||
*/
|
||||
export const testConnectionMutation = (
|
||||
options?: Partial<Options<TestConnectionData>>,
|
||||
): UseMutationOptions<TestConnectionResponse, DefaultError, Options<TestConnectionData>> => {
|
||||
const mutationOptions: UseMutationOptions<TestConnectionResponse, DefaultError, Options<TestConnectionData>> = {
|
||||
mutationFn: async (localOptions) => {
|
||||
const { data } = await testConnection({
|
||||
...options,
|
||||
...localOptions,
|
||||
throwOnError: true,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
};
|
||||
return mutationOptions;
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete a volume
|
||||
*/
|
||||
|
||||
@@ -6,6 +6,8 @@ import type {
|
||||
ListVolumesResponses,
|
||||
CreateVolumeData,
|
||||
CreateVolumeResponses,
|
||||
TestConnectionData,
|
||||
TestConnectionResponses,
|
||||
DeleteVolumeData,
|
||||
DeleteVolumeResponses,
|
||||
} from "./types.gen";
|
||||
@@ -54,6 +56,22 @@ export const createVolume = <ThrowOnError extends boolean = false>(
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Test connection to backend
|
||||
*/
|
||||
export const testConnection = <ThrowOnError extends boolean = false>(
|
||||
options?: Options<TestConnectionData, ThrowOnError>,
|
||||
) => {
|
||||
return (options?.client ?? _heyApiClient).post<TestConnectionResponses, unknown, ThrowOnError>({
|
||||
url: "/api/v1/volumes/test-connection",
|
||||
...options,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...options?.headers,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete a volume
|
||||
*/
|
||||
|
||||
@@ -33,7 +33,7 @@ export type CreateVolumeData = {
|
||||
exportPath: string;
|
||||
port: number;
|
||||
server: string;
|
||||
version: string;
|
||||
version: "3" | "4" | "4.1";
|
||||
}
|
||||
| {
|
||||
backend: "smb";
|
||||
@@ -61,6 +61,40 @@ export type CreateVolumeResponses = {
|
||||
|
||||
export type CreateVolumeResponse = CreateVolumeResponses[keyof CreateVolumeResponses];
|
||||
|
||||
export type TestConnectionData = {
|
||||
body?: {
|
||||
config:
|
||||
| {
|
||||
backend: "directory";
|
||||
}
|
||||
| {
|
||||
backend: "nfs";
|
||||
exportPath: string;
|
||||
port: number;
|
||||
server: string;
|
||||
version: "3" | "4" | "4.1";
|
||||
}
|
||||
| {
|
||||
backend: "smb";
|
||||
};
|
||||
};
|
||||
path?: never;
|
||||
query?: never;
|
||||
url: "/api/v1/volumes/test-connection";
|
||||
};
|
||||
|
||||
export type TestConnectionResponses = {
|
||||
/**
|
||||
* Connection test result
|
||||
*/
|
||||
200: {
|
||||
message: string;
|
||||
success: boolean;
|
||||
};
|
||||
};
|
||||
|
||||
export type TestConnectionResponse = TestConnectionResponses[keyof TestConnectionResponses];
|
||||
|
||||
export type DeleteVolumeData = {
|
||||
body?: never;
|
||||
path: {
|
||||
|
||||
Reference in New Issue
Block a user