mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
feat: file explorer (#1)
* feat: list volume files backend * feat: file tree component * feat: load sub folders * fix: filetree wrong opening order * temp: open / close icons * chore: remove all hc files when cleaning * chore: file-tree optimizations
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
||||
mountVolume,
|
||||
unmountVolume,
|
||||
healthCheckVolume,
|
||||
listFiles,
|
||||
} from "../sdk.gen";
|
||||
import { queryOptions, type UseMutationOptions, type DefaultError } from "@tanstack/react-query";
|
||||
import type {
|
||||
@@ -45,6 +46,7 @@ import type {
|
||||
UnmountVolumeResponse,
|
||||
HealthCheckVolumeData,
|
||||
HealthCheckVolumeResponse,
|
||||
ListFilesData,
|
||||
} from "../types.gen";
|
||||
import { client as _heyApiClient } from "../client.gen";
|
||||
|
||||
@@ -539,3 +541,23 @@ export const healthCheckVolumeMutation = (
|
||||
};
|
||||
return mutationOptions;
|
||||
};
|
||||
|
||||
export const listFilesQueryKey = (options: Options<ListFilesData>) => createQueryKey("listFiles", options);
|
||||
|
||||
/**
|
||||
* List files in a volume directory
|
||||
*/
|
||||
export const listFilesOptions = (options: Options<ListFilesData>) => {
|
||||
return queryOptions({
|
||||
queryFn: async ({ queryKey, signal }) => {
|
||||
const { data } = await listFiles({
|
||||
...options,
|
||||
...queryKey[0],
|
||||
signal,
|
||||
throwOnError: true,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
queryKey: listFilesQueryKey(options),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -41,6 +41,9 @@ import type {
|
||||
HealthCheckVolumeData,
|
||||
HealthCheckVolumeResponses,
|
||||
HealthCheckVolumeErrors,
|
||||
ListFilesData,
|
||||
ListFilesResponses,
|
||||
ListFilesErrors,
|
||||
} from "./types.gen";
|
||||
import { client as _heyApiClient } from "./client.gen";
|
||||
|
||||
@@ -248,3 +251,13 @@ export const healthCheckVolume = <ThrowOnError extends boolean = false>(
|
||||
...options,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* List files in a volume directory
|
||||
*/
|
||||
export const listFiles = <ThrowOnError extends boolean = false>(options: Options<ListFilesData, ThrowOnError>) => {
|
||||
return (options.client ?? _heyApiClient).get<ListFilesResponses, ListFilesErrors, ThrowOnError>({
|
||||
url: "/api/v1/volumes/{name}/files",
|
||||
...options,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -600,6 +600,45 @@ export type HealthCheckVolumeResponses = {
|
||||
|
||||
export type HealthCheckVolumeResponse = HealthCheckVolumeResponses[keyof HealthCheckVolumeResponses];
|
||||
|
||||
export type ListFilesData = {
|
||||
body?: never;
|
||||
path: {
|
||||
name: string;
|
||||
};
|
||||
query?: {
|
||||
/**
|
||||
* Subdirectory path to list (relative to volume root)
|
||||
*/
|
||||
path?: string;
|
||||
};
|
||||
url: "/api/v1/volumes/{name}/files";
|
||||
};
|
||||
|
||||
export type ListFilesErrors = {
|
||||
/**
|
||||
* Volume not found
|
||||
*/
|
||||
404: unknown;
|
||||
};
|
||||
|
||||
export type ListFilesResponses = {
|
||||
/**
|
||||
* List of files in the volume
|
||||
*/
|
||||
200: {
|
||||
files: Array<{
|
||||
name: string;
|
||||
path: string;
|
||||
type: "directory" | "file";
|
||||
modifiedAt?: number;
|
||||
size?: number;
|
||||
}>;
|
||||
path: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type ListFilesResponse = ListFilesResponses[keyof ListFilesResponses];
|
||||
|
||||
export type ClientOptions = {
|
||||
baseUrl: "http://localhost:4096" | (string & {});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user