Files
kandev/apps/web/lib/api/domains/fs-api.ts
T
2026-07-23 22:30:40 +01:00

39 lines
1019 B
TypeScript

import { fetchJson, type ApiRequestOptions } from "../client";
export type DirectoryEntry = {
name: string;
path: string;
};
export type DirectoryListing = {
path: string;
parent: string;
entries: DirectoryEntry[];
choosable: boolean;
};
/**
* Lists immediate subdirectories of `path`. When path is empty the backend
* defaults to $HOME. Hidden directories (starting with ".") are excluded.
* Used by the folder picker for repo-less tasks.
*/
export async function listDirectory(path: string, options?: ApiRequestOptions) {
const qs = path ? `?path=${encodeURIComponent(path)}` : "";
return fetchJson<DirectoryListing>(`/api/v1/fs/list-dir${qs}`, options);
}
export async function createDirectory(
parentPath: string,
name: string,
options?: ApiRequestOptions,
) {
return fetchJson<DirectoryListing>("/api/v1/fs/create-dir", {
...options,
init: {
method: "POST",
body: JSON.stringify({ parent_path: parentPath, name }),
...(options?.init ?? {}),
},
});
}