mirror of
https://codeberg.org/PLG-Development/PLG-MuDiCS
synced 2026-07-06 00:47:09 +00:00
chore: better logging
log some things only in dev mode
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
|||||||
type ShellCommandResponse,
|
type ShellCommandResponse,
|
||||||
type TreeElement
|
type TreeElement
|
||||||
} from './types';
|
} from './types';
|
||||||
|
import { dev } from '$app/environment';
|
||||||
|
|
||||||
export async function get_screenshot(ip: string): Promise<Blob | null> {
|
export async function get_screenshot(ip: string): Promise<Blob | null> {
|
||||||
const options = { method: 'PATCH' };
|
const options = { method: 'PATCH' };
|
||||||
@@ -62,7 +63,7 @@ export async function get_file_data(
|
|||||||
echo
|
echo
|
||||||
done
|
done
|
||||||
`;
|
`;
|
||||||
const raw_response = await run_shell_command(ip, command, true);
|
const raw_response = await run_shell_command(ip, command);
|
||||||
if (!raw_response.ok || !raw_response.json) return null;
|
if (!raw_response.ok || !raw_response.json) return null;
|
||||||
const json_response = raw_response.json as ShellCommandResponse;
|
const json_response = raw_response.json as ShellCommandResponse;
|
||||||
if (json_response.exitCode === 0 && json_response.stdout.trim() === '') return [];
|
if (json_response.exitCode === 0 && json_response.stdout.trim() === '') return [];
|
||||||
@@ -93,7 +94,7 @@ export async function get_file_data(
|
|||||||
|
|
||||||
export async function get_file_tree_data(ip: string, path: string): Promise<TreeElement[] | null> {
|
export async function get_file_tree_data(ip: string, path: string): Promise<TreeElement[] | null> {
|
||||||
const command = `cd ".${path}" && tree -Js`;
|
const command = `cd ".${path}" && tree -Js`;
|
||||||
const raw_response = await run_shell_command(ip, command, true);
|
const raw_response = await run_shell_command(ip, command);
|
||||||
|
|
||||||
if (!raw_response.ok || !raw_response.json) return null;
|
if (!raw_response.ok || !raw_response.json) return null;
|
||||||
const json_response = raw_response.json as ShellCommandResponse;
|
const json_response = raw_response.json as ShellCommandResponse;
|
||||||
@@ -166,7 +167,6 @@ export async function get_thumbnail_blob(ip: string, path_to_file: string): Prom
|
|||||||
ip,
|
ip,
|
||||||
`/file/preview${path_to_file}`,
|
`/file/preview${path_to_file}`,
|
||||||
{ method: 'GET' },
|
{ method: 'GET' },
|
||||||
true,
|
|
||||||
[415]
|
[415]
|
||||||
);
|
);
|
||||||
if (!raw_response.ok || !raw_response.blob) return null;
|
if (!raw_response.ok || !raw_response.blob) return null;
|
||||||
@@ -188,11 +188,10 @@ async function request_display(
|
|||||||
ip: string,
|
ip: string,
|
||||||
api_route: string,
|
api_route: string,
|
||||||
options: { method: string; headers?: Record<string, string>; body?: string },
|
options: { method: string; headers?: Record<string, string>; body?: string },
|
||||||
log_in_debug: boolean = false,
|
|
||||||
supress_error_handling_http_codes: number[] = []
|
supress_error_handling_http_codes: number[] = []
|
||||||
): Promise<RequestResponse> {
|
): Promise<RequestResponse> {
|
||||||
const url = `http://${ip}:1323/api${api_route}`;
|
const url = `http://${ip}:1323/api${api_route}`;
|
||||||
return await request(url, options, log_in_debug, supress_error_handling_http_codes);
|
return await request(url, options, supress_error_handling_http_codes);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function request_control(
|
async function request_control(
|
||||||
@@ -206,15 +205,12 @@ async function request_control(
|
|||||||
async function request(
|
async function request(
|
||||||
url: string,
|
url: string,
|
||||||
options: { method: string; headers?: Record<string, string>; body?: string },
|
options: { method: string; headers?: Record<string, string>; body?: string },
|
||||||
log_in_debug: boolean = false,
|
|
||||||
supress_error_handling_http_codes: number[] = []
|
supress_error_handling_http_codes: number[] = []
|
||||||
): Promise<RequestResponse> {
|
): Promise<RequestResponse> {
|
||||||
try {
|
try {
|
||||||
const cache_buster = `${url.includes('?') ? '&' : '?'}=${Date.now()}`;
|
const cache_buster = `${url.includes('?') ? '&' : '?'}=${Date.now()}`;
|
||||||
if (log_in_debug) {
|
if (dev) {
|
||||||
console.debug(url + cache_buster, options.body);
|
console.debug('Sending request: ', url + cache_buster, 'with', options.body ?? 'none');
|
||||||
} else {
|
|
||||||
console.log(url + cache_buster, options.body);
|
|
||||||
}
|
}
|
||||||
const response = await fetch(url + cache_buster, options);
|
const response = await fetch(url + cache_buster, options);
|
||||||
if (response.ok || supress_error_handling_http_codes.includes(response.status)) {
|
if (response.ok || supress_error_handling_http_codes.includes(response.status)) {
|
||||||
@@ -227,10 +223,8 @@ async function request(
|
|||||||
const json: Record<string, unknown> = await response.json();
|
const json: Record<string, unknown> = await response.json();
|
||||||
request_response = { ok: response.ok, http_code: response.status, json: json };
|
request_response = { ok: response.ok, http_code: response.status, json: json };
|
||||||
}
|
}
|
||||||
if (log_in_debug) {
|
if (dev) {
|
||||||
console.debug(request_response);
|
console.debug(request_response);
|
||||||
} else {
|
|
||||||
console.log(request_response);
|
|
||||||
}
|
}
|
||||||
return request_response;
|
return request_response;
|
||||||
}
|
}
|
||||||
@@ -250,7 +244,9 @@ async function request(
|
|||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
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?');
|
if (dev) {
|
||||||
|
console.warn('Request failed - Is the targeted device online?');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error(url, error);
|
console.error(url, error);
|
||||||
notifications.push('error', `Fataler Fehler bei API-Anfrage`, `${url}\nFehler: ${error}`);
|
notifications.push('error', `Fataler Fehler bei API-Anfrage`, `${url}\nFehler: ${error}`);
|
||||||
@@ -271,7 +267,9 @@ function handle_shell_error(
|
|||||||
shell_response.stderr &&
|
shell_response.stderr &&
|
||||||
/bash: line \d+: cd: .+: No such file or directory/.test(shell_response.stderr)
|
/bash: line \d+: cd: .+: No such file or directory/.test(shell_response.stderr)
|
||||||
) {
|
) {
|
||||||
console.log('current file_path does not exist on display:', ip);
|
if (dev) {
|
||||||
|
console.debug('current file_path does not exist on display:', ip);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
console.error(shell_response);
|
console.error(shell_response);
|
||||||
@@ -286,11 +284,7 @@ function handle_shell_error(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function run_shell_command(
|
async function run_shell_command(ip: string, command: string): Promise<RequestResponse> {
|
||||||
ip: string,
|
|
||||||
command: string,
|
|
||||||
log_in_debug: boolean = false
|
|
||||||
): Promise<RequestResponse> {
|
|
||||||
const options = {
|
const options = {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
headers: { 'content-type': 'application/json' },
|
headers: { 'content-type': 'application/json' },
|
||||||
@@ -298,5 +292,5 @@ async function run_shell_command(
|
|||||||
command: command
|
command: command
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
return await request_display(ip, '/shellCommand', options, log_in_debug);
|
return await request_display(ip, '/shellCommand', options);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { dev } from '$app/environment';
|
||||||
import { db } from './files_display.db';
|
import { db } from './files_display.db';
|
||||||
import { get_display_by_id } from './stores/displays';
|
import { get_display_by_id } from './stores/displays';
|
||||||
import { remove_all_files_without_display, remove_file_from_display } from './stores/files';
|
import { remove_all_files_without_display, remove_file_from_display } from './stores/files';
|
||||||
@@ -86,7 +87,9 @@ async function start_task_loop() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('AKTUELL IN TASKS', tasks.length);
|
if (dev) {
|
||||||
|
console.debug('AKTUELL IN TASKS', tasks.length);
|
||||||
|
}
|
||||||
tasks.shift(); // Remove current_task from tasks
|
tasks.shift(); // Remove current_task from tasks
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,6 +167,6 @@ async function show_error(
|
|||||||
`Datei: "${task.file_name}", Display-IP: ${task.display_ip}\nFehler: ${error}`
|
`Datei: "${task.file_name}", Display-IP: ${task.display_ip}\nFehler: ${error}`
|
||||||
);
|
);
|
||||||
if (type === 'download') return;
|
if (type === 'download') return;
|
||||||
await remove_file_from_display(task.display_id, task.file_primary_key);
|
await remove_file_from_display(task.display_id, task.file_primary_key);
|
||||||
await remove_all_files_without_display();
|
await remove_all_files_without_display();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { get_uuid, image_content_hash } from '../utils';
|
|||||||
import { get_screenshot } from '../api_handler';
|
import { get_screenshot } from '../api_handler';
|
||||||
import { delete_and_deselect_unique_files_from_display } from './files';
|
import { delete_and_deselect_unique_files_from_display } from './files';
|
||||||
import { db } from '../files_display.db';
|
import { db } from '../files_display.db';
|
||||||
|
import { dev } from '$app/environment';
|
||||||
|
|
||||||
export async function is_display_name_taken(name: string): Promise<boolean> {
|
export async function is_display_name_taken(name: string): Promise<boolean> {
|
||||||
const exists = await db.displays.where('name').equals(name).first();
|
const exists = await db.displays.where('name').equals(name).first();
|
||||||
@@ -23,11 +24,15 @@ export async function add_display(
|
|||||||
let group_id: string;
|
let group_id: string;
|
||||||
if (group) {
|
if (group) {
|
||||||
group_id = group.id;
|
group_id = group.id;
|
||||||
console.log('DISPLAYGROUP WURDE NICHT ERSTELLT');
|
if (dev) {
|
||||||
|
console.debug('DISPLAYGROUP WURDE NICHT ERSTELLT');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
group_id = get_uuid();
|
group_id = get_uuid();
|
||||||
await db.display_groups.put({ id: group_id, position: 0 });
|
await db.display_groups.put({ id: group_id, position: 0 });
|
||||||
console.log('DISPLAYGROUP WURDE ERSTELLT');
|
if (dev) {
|
||||||
|
console.info('DISPLAYGROUP WURDE ERSTELLT');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const element_count_in_group = (await db.displays.where('group_id').equals(group_id).toArray())
|
const element_count_in_group = (await db.displays.where('group_id').equals(group_id).toArray())
|
||||||
.length;
|
.length;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export async function change_file_path(new_path: string) {
|
|||||||
for (const display of displays) {
|
for (const display of displays) {
|
||||||
const changed_paths = await get_changed_directory_paths(display, new_path);
|
const changed_paths = await get_changed_directory_paths(display, new_path);
|
||||||
if (!changed_paths) continue;
|
if (!changed_paths) continue;
|
||||||
console.log('Update file system from', display.name, ':', changed_paths);
|
console.debug('Update file system from', display.name, ':', changed_paths);
|
||||||
for (const path of changed_paths) {
|
for (const path of changed_paths) {
|
||||||
await update_folder_elements_recursively(display, path);
|
await update_folder_elements_recursively(display, path);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,11 @@
|
|||||||
import PopUp from '$lib/components/PopUp.svelte';
|
import PopUp from '$lib/components/PopUp.svelte';
|
||||||
import { get_file_primary_key, type Inode, type PopupContent } from '$lib/ts/types';
|
import { get_file_primary_key, type Inode, type PopupContent } from '$lib/ts/types';
|
||||||
import TextInput from '$lib/components/TextInput.svelte';
|
import TextInput from '$lib/components/TextInput.svelte';
|
||||||
import { first_letter_is_valid, get_accepted_file_type_string, is_valid_name } from '$lib/ts/utils';
|
import {
|
||||||
|
first_letter_is_valid,
|
||||||
|
get_accepted_file_type_string,
|
||||||
|
is_valid_name
|
||||||
|
} from '$lib/ts/utils';
|
||||||
import { delete_files, rename_file } from '$lib/ts/api_handler';
|
import { delete_files, rename_file } from '$lib/ts/api_handler';
|
||||||
import HighlightedText from '$lib/components/HighlightedText.svelte';
|
import HighlightedText from '$lib/components/HighlightedText.svelte';
|
||||||
import { liveQuery, type Observable } from 'dexie';
|
import { liveQuery, type Observable } from 'dexie';
|
||||||
@@ -88,7 +92,7 @@
|
|||||||
popup_close_function();
|
popup_close_function();
|
||||||
await run_for_selected_files_on_selected_displays(async (ip: string, file_names: string[]) => {
|
await run_for_selected_files_on_selected_displays(async (ip: string, file_names: string[]) => {
|
||||||
if (file_names.length !== 1) {
|
if (file_names.length !== 1) {
|
||||||
console.log('EEEERRRRROOOOOOR', file_names);
|
console.error(file_names);
|
||||||
return; // Error
|
return; // Error
|
||||||
}
|
}
|
||||||
await rename_file(ip, $current_file_path, file_names[0], new_file_name);
|
await rename_file(ip, $current_file_path, file_names[0], new_file_name);
|
||||||
@@ -165,7 +169,8 @@
|
|||||||
const trimmed_input = input.trim();
|
const trimmed_input = input.trim();
|
||||||
if (trimmed_input.length === 0 || trimmed_input.length > 50)
|
if (trimmed_input.length === 0 || trimmed_input.length > 50)
|
||||||
return [false, 'Ungültige Länge'];
|
return [false, 'Ungültige Länge'];
|
||||||
if (!first_letter_is_valid(trimmed_input)) return [false, `Name darf nicht mit ${trimmed_input[0]} beginnen`];
|
if (!first_letter_is_valid(trimmed_input))
|
||||||
|
return [false, `Name darf nicht mit ${trimmed_input[0]} beginnen`];
|
||||||
if (!is_valid_name(trimmed_input)) return [false, 'Name enthält ungültige Zeichen'];
|
if (!is_valid_name(trimmed_input)) return [false, 'Name enthält ungültige Zeichen'];
|
||||||
if (($current_folder_elements ?? []).some((e) => e.name === trimmed_input))
|
if (($current_folder_elements ?? []).some((e) => e.name === trimmed_input))
|
||||||
return [false, 'Name bereits verwendet'];
|
return [false, 'Name bereits verwendet'];
|
||||||
@@ -191,7 +196,8 @@
|
|||||||
const trimmed_input = input.trim() + extension;
|
const trimmed_input = input.trim() + extension;
|
||||||
if (trimmed_input.length === 0 || trimmed_input.length > 50)
|
if (trimmed_input.length === 0 || trimmed_input.length > 50)
|
||||||
return [false, 'Ungültige Länge'];
|
return [false, 'Ungültige Länge'];
|
||||||
if (!first_letter_is_valid(trimmed_input)) return [false, `Name darf nicht mit ${trimmed_input[0]} beginnen`];
|
if (!first_letter_is_valid(trimmed_input))
|
||||||
|
return [false, `Name darf nicht mit ${trimmed_input[0]} beginnen`];
|
||||||
if (!is_valid_name(trimmed_input)) return [false, 'Name enthält ungültige Zeichen'];
|
if (!is_valid_name(trimmed_input)) return [false, 'Name enthält ungültige Zeichen'];
|
||||||
if (
|
if (
|
||||||
($current_folder_elements ?? []).some(
|
($current_folder_elements ?? []).some(
|
||||||
@@ -250,7 +256,8 @@
|
|||||||
bind:this={file_input}
|
bind:this={file_input}
|
||||||
multiple
|
multiple
|
||||||
accept={get_accepted_file_type_string()}
|
accept={get_accepted_file_type_string()}
|
||||||
onchange={(e) => add_upload((e.target as HTMLInputElement).files!, $selected_display_ids, $current_file_path)}
|
onchange={(e) =>
|
||||||
|
add_upload((e.target as HTMLInputElement).files!, $selected_display_ids, $current_file_path)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="bg-stone-800 h-full rounded-2xl grid grid-rows-[2.5rem_1fr] min-h-0">
|
<div class="bg-stone-800 h-full rounded-2xl grid grid-rows-[2.5rem_1fr] min-h-0">
|
||||||
|
|||||||
Reference in New Issue
Block a user