Merge pull request 'clan-cli: Refactor the API to use the Flake object' (#3531) from Qubasa/clan-core:replace_machine_name_with_machine_obj into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3531
This commit is contained in:
Mic92
2025-05-07 13:21:13 +00:00
31 changed files with 168 additions and 136 deletions

View File

@@ -13,9 +13,9 @@ export async function get_inventory(client: QueryClient, base_path: string) {
queryKey: [base_path, "inventory"],
queryFn: () => {
console.log("Refreshing inventory");
return callApi("get_inventory", { base_path }) as Promise<
ApiEnvelope<Inventory>
>;
return callApi("get_inventory", {
flake: { identifier: base_path },
}) as Promise<ApiEnvelope<Inventory>>;
},
revalidateIfStale: true,
staleTime: 60 * 1000,

View File

@@ -6,7 +6,7 @@ export const instance_name = (machine_name: string) =>
export async function get_iwd_service(base_path: string, machine_name: string) {
const r = await callApi("get_inventory", {
base_path,
flake: { identifier: base_path },
});
if (r.status == "error") {
return null;

View File

@@ -43,7 +43,7 @@ export const tagsQuery = (uri: string | null) =>
if (!uri) return [];
const response = await callApi("get_inventory", {
base_path: uri,
flake: { identifier: uri },
});
if (response.status === "error") {
toast.error("Failed to fetch data");
@@ -64,7 +64,7 @@ export const machinesQuery = (uri: string | null) =>
if (!uri) return [];
const response = await callApi("get_inventory", {
base_path: uri,
flake: { identifier: uri },
});
if (response.status === "error") {
toast.error("Failed to fetch data");

View File

@@ -42,7 +42,7 @@ const EditClanForm = (props: EditClanFormProps) => {
(async () => {
await callApi("update_clan_meta", {
options: {
directory: props.directory,
flake: { identifier: props.directory },
meta: values,
},
});

View File

@@ -10,7 +10,9 @@ export function DiskView() {
const currUri = activeURI();
if (currUri) {
// Example of calling an API
const result = await callApi("get_inventory", { base_path: currUri });
const result = await callApi("get_inventory", {
flake: { identifier: currUri },
});
if (result.status === "error") throw new Error("Failed to fetch data");
return result.data;
}

View File

@@ -115,7 +115,7 @@ const InstallMachine = (props: InstallMachineProps) => {
if (shouldRunDisk) {
setProgressText("Setting up disk ... (1/5)");
const disk_response = await callApi("set_machine_disk_schema", {
base_path: curr_uri,
flake: { identifier: curr_uri },
machine_name: props.name,
placeholders: diskValues.placeholders,
schema_name: diskValues.schema,
@@ -415,7 +415,9 @@ const MachineForm = (props: MachineDetailsProps) => {
}
const machine_response = await callApi("set_machine", {
flake_url: curr_uri,
flake: {
identifier: curr_uri,
},
machine_name: props.initialData.machine.name || "My machine",
machine: {
...values.machine,
@@ -680,8 +682,12 @@ export const MachineDetails = () => {
const curr = activeURI();
if (curr) {
const result = await callApi("get_machine_details", {
flake_url: curr,
machine_name: params.id,
machine: {
flake: {
identifier: curr,
},
name: params.id,
},
});
if (result.status === "error") throw new Error("Failed to fetch data");
return result.data;

View File

@@ -37,7 +37,9 @@ export const DiskStep = (props: StepProps<DiskValues>) => {
queryKey: [props.dir, props.machine_id, "disk_schemas"],
queryFn: async () => {
const result = await callApi("get_disk_schemas", {
base_path: props.dir,
flake: {
identifier: props.dir,
},
machine_name: props.machine_id,
});
if (result.status === "error") throw new Error("Failed to fetch data");

View File

@@ -52,7 +52,9 @@ export const HWStep = (props: StepProps<HardwareValues>) => {
queryKey: [props.dir, props.machine_id, "hw_report"],
queryFn: async () => {
const result = await callApi("show_machine_hardware_config", {
clan_dir: props.dir,
flake: {
identifier: props.dir,
},
machine_name: props.machine_id,
});
if (result.status === "error") throw new Error("Failed to fetch data");

View File

@@ -39,7 +39,9 @@ export const MachineListView: Component = () => {
const uri = activeURI();
if (uri) {
const response = await callApi("list_machines", {
flake_url: uri,
flake: {
identifier: uri,
},
});
if (response.status === "error") {
toast.error("Failed to fetch data");