mirror of
https://codeberg.org/PLG-Development/PLG-MuDiCS
synced 2026-07-06 00:47:09 +00:00
handle cd directory errors
This commit is contained in:
@@ -20,7 +20,6 @@ export async function send_keyboard_input(ip: string, key: string): Promise<void
|
|||||||
key: key,
|
key: key,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
console.log(options)
|
|
||||||
await request_display(ip, '/keyboardInput', options);
|
await request_display(ip, '/keyboardInput', options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +47,10 @@ done
|
|||||||
` })
|
` })
|
||||||
};
|
};
|
||||||
const raw_response = await request_display(ip, '/shellCommand', options);
|
const raw_response = await request_display(ip, '/shellCommand', options);
|
||||||
if (!raw_response) return [];
|
if (is_cd_directory_error(ip, raw_response)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
const response: FileInfo[] = raw_response.stdout.trim()
|
const response: FileInfo[] = raw_response.stdout.trim()
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
@@ -83,9 +85,11 @@ export async function get_file_tree_data(ip: string, path: string): Promise<Tree
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
const raw_response = await request_display(ip, '/shellCommand', options);
|
const raw_response = await request_display(ip, '/shellCommand', options);
|
||||||
if (!raw_response) return null;
|
if (is_cd_directory_error(ip, raw_response)) {
|
||||||
const tree_structure: TreeElement[] | null = (JSON.parse(raw_response.stdout.trim()) as [TreeElement, any])[0].contents || null;
|
return null;
|
||||||
return tree_structure;
|
}
|
||||||
|
|
||||||
|
return (JSON.parse(raw_response.stdout.trim()) as [TreeElement, any])[0].contents || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -144,10 +148,24 @@ async function raw_request(url: string, options: { method: string, headers?: Rec
|
|||||||
if (error instanceof TypeError && /fetch|NetworkError/i.test(error.message)) {
|
if (error instanceof TypeError && /fetch|NetworkError/i.test(error.message)) {
|
||||||
console.log("Request failed - Is the targeted device online?")
|
console.log("Request failed - Is the targeted device online?")
|
||||||
} else {
|
} else {
|
||||||
console.log(typeof error, error instanceof TypeError, error.message);
|
|
||||||
console.error(error);
|
console.error(error);
|
||||||
notifications.push("error", `Fehler bei API-Anfrage`, `${url}\nFehler: ${error}`);
|
notifications.push("error", `Fehler bei API-Anfrage`, `${url}\nFehler: ${error}`);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function is_cd_directory_error(ip: string, raw_response: any): boolean {
|
||||||
|
if (!raw_response) return true;
|
||||||
|
if (raw_response.exitCode !== 0) {
|
||||||
|
if (raw_response.stderr && /bash: line \d+: cd: .+: No such file or directory/.test(raw_response.stderr)) {
|
||||||
|
console.log("current file_path does not exist on display:", ip);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
console.error(raw_response);
|
||||||
|
notifications.push("error", "Fehler in ShellCommand", `Fehlercode: ${raw_response.exitCode}\nFehler: ${raw_response.stderr ?? ''}`)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (raw_response.stdout.trim() === '') return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -67,7 +67,7 @@ export function get_display_ids_where_file_is_missing(path: string, file: Folder
|
|||||||
|
|
||||||
async function get_changed_directory_paths(display: Display, file_path: string): Promise<string[] | null> {
|
async function get_changed_directory_paths(display: Display, file_path: string): Promise<string[] | null> {
|
||||||
const current_folder = await get_file_tree_data(display.ip, file_path);
|
const current_folder = await get_file_tree_data(display.ip, file_path);
|
||||||
if (current_folder === null) return null;
|
if (current_folder === null) return [file_path];
|
||||||
const directory_strings = get_recursive_changed_directory_paths(display, file_path, current_folder, get(all_files));
|
const directory_strings = get_recursive_changed_directory_paths(display, file_path, current_folder, get(all_files));
|
||||||
if (directory_strings.size === 0) return null;
|
if (directory_strings.size === 0) return null;
|
||||||
const directory_strings_array = [...directory_strings];
|
const directory_strings_array = [...directory_strings];
|
||||||
|
|||||||
Reference in New Issue
Block a user