refactor(control): replace === 'inode/directory' with is_folder()

This commit is contained in:
E44
2026-01-19 17:54:47 +01:00
parent 4acbc96a58
commit 209080db22
5 changed files with 42 additions and 31 deletions
@@ -12,6 +12,7 @@ import { notifications } from './stores/notification';
import { generate_thumbnail } from './stores/thumbnails';
import {
get_file_primary_key,
is_folder,
type FileLoadingData,
type FileOnDisplay,
type FileTransferTask,
@@ -109,7 +110,7 @@ export async function add_sync_recursively(
);
if (!file_data) return console.warn('Sync canceled: no file_data');
if (file_data.file.type === 'inode/directory') {
if (is_folder(file_data.file)) {
const new_path = file_data.file.path + file_data.file.name + '/';
const elements_in_folder = await get_folder_elements(new_path, selected_display_ids);
if (elements_in_folder.length === 0) {
@@ -294,7 +295,7 @@ export async function download_file(selected_file_id: string, selected_display_i
selected_file_id,
selected_display_ids
);
if (!file_data || file_data.file.type === 'inode/directory')
if (!file_data || is_folder(file_data.file))
return console.warn('Download cancelled: is folder');
try {
+6 -5
View File
@@ -1,6 +1,7 @@
import { get, writable, type Writable } from 'svelte/store';
import {
get_file_primary_key,
is_folder,
type Display,
type FileOnDisplay,
type Inode,
@@ -59,7 +60,7 @@ export async function remove_file_from_display_recusively(
const inode_element = await get_file_by_id(found.file_primary_key);
if (!inode_element) return;
if (inode_element.type === 'inode/directory') {
if (is_folder(inode_element)) {
const path_inside_folder = inode_element.path + inode_element.name + `/`;
const primary_file_keys_in_folder = (
await db.files.where('path').equals(path_inside_folder).toArray()
@@ -149,7 +150,7 @@ export async function get_displays_where_path_not_exists(
const folders_of_current_path = await db.files
.where('name')
.equals(last_path_part)
.filter((inode) => inode.path === path_without_last_part && inode.type === 'inode/directory')
.filter((inode) => inode.path === path_without_last_part && is_folder(inode))
.first();
if (!folders_of_current_path) return [];
const folder_primary_key = get_file_primary_key(folders_of_current_path);
@@ -278,7 +279,7 @@ export async function update_folder_elements_recursively(
};
await db.files_on_display.put(file_on_display);
if (new_element.folder_element.type === 'inode/directory') {
if (is_folder(new_element.folder_element)) {
await update_folder_elements_recursively(
display,
file_path + new_element.folder_element.name + '/'
@@ -334,8 +335,8 @@ export async function get_folder_elements(
function sort_files(files: Inode[]) {
files.sort((a, b) => {
const isDirA = a.type === 'inode/directory';
const isDirB = b.type === 'inode/directory';
const isDirA = is_folder(a);
const isDirB = is_folder(b);
// Ordner zuerst
if (isDirA && !isDirB) return -1;
+10 -6
View File
@@ -46,7 +46,7 @@ export type FileTransferTaskData =
type: 'sync';
destination_display_data: {
display: ShortDisplay;
loading_data: FileLoadingData
loading_data: FileLoadingData;
}[];
};
@@ -135,11 +135,11 @@ export type PopupContent = {
};
export type NumberSetting = {
max: number,
min: number,
now: number,
step: number
}
max: number;
min: number;
now: number;
step: number;
};
export type DisplayStatus = 'host_offline' | 'app_offline' | 'app_online' | null;
@@ -148,3 +148,7 @@ export function to_display_status(value: string): DisplayStatus {
? (value as DisplayStatus)
: null;
}
export function is_folder(inode: Inode) {
return inode.type === 'inode/directory';
}