mirror of
https://codeberg.org/PLG-Development/PLG-MuDiCS
synced 2026-07-05 16:37:09 +00:00
chore(control): change create_folder api to create_path
This commit is contained in:
@@ -110,16 +110,11 @@ export async function get_file_tree_data(ip: string, path: string): Promise<Tree
|
|||||||
return tree_element?.contents || null;
|
return tree_element?.contents || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function create_folders(
|
export async function create_path(
|
||||||
ip: string,
|
ip: string,
|
||||||
path: string,
|
path: string,
|
||||||
folder_names: string[]
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
let command = `cd ".${path}"`;
|
const command = `mkdir -p ".${path}"`
|
||||||
|
|
||||||
for (const part of folder_names) {
|
|
||||||
command += ` && mkdir "${part}" && cd "${part}/"`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const raw_response = await run_shell_command(ip, command);
|
const raw_response = await run_shell_command(ip, command);
|
||||||
if (!raw_response.ok || !raw_response.json) return;
|
if (!raw_response.ok || !raw_response.json) return;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
} from '../types';
|
} from '../types';
|
||||||
import { get_display_by_id } from './displays';
|
import { get_display_by_id } from './displays';
|
||||||
import { is_selected, select, selected_display_ids, selected_file_ids } from './select';
|
import { is_selected, select, selected_display_ids, selected_file_ids } from './select';
|
||||||
import { create_folders, get_file_data, get_file_tree_data } from '../api_handler';
|
import { create_path, get_file_data, get_file_tree_data } from '../api_handler';
|
||||||
import { deactivate_old_thumbnail_urls, generate_thumbnail } from './thumbnails';
|
import { deactivate_old_thumbnail_urls, generate_thumbnail } from './thumbnails';
|
||||||
import { db } from '../database';
|
import { db } from '../database';
|
||||||
|
|
||||||
@@ -47,7 +47,10 @@ export async function delete_and_deselect_unique_files_from_display(display_id:
|
|||||||
await remove_all_files_without_display();
|
await remove_all_files_without_display();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function remove_file_from_display_recusively(display_id: string, file_primary_key: string) {
|
export async function remove_file_from_display_recusively(
|
||||||
|
display_id: string,
|
||||||
|
file_primary_key: string
|
||||||
|
) {
|
||||||
const found = await db.files_on_display.get([display_id, file_primary_key]);
|
const found = await db.files_on_display.get([display_id, file_primary_key]);
|
||||||
if (!found) return;
|
if (!found) return;
|
||||||
select(selected_file_ids, file_primary_key, 'deselect');
|
select(selected_file_ids, file_primary_key, 'deselect');
|
||||||
@@ -130,12 +133,11 @@ async function get_display_ids_where_file_is_missing(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get_displays_where_path_exists(
|
export async function get_displays_where_path_not_exists(
|
||||||
path: string,
|
path: string,
|
||||||
selected_display_ids: string[],
|
selected_display_ids: string[]
|
||||||
invert: boolean
|
|
||||||
): Promise<Display[]> {
|
): Promise<Display[]> {
|
||||||
if (path === '/') return [];
|
if (path === '/') return await db.displays.where('id').anyOf(selected_display_ids).toArray();
|
||||||
const last_path_part =
|
const last_path_part =
|
||||||
path
|
path
|
||||||
.slice(0, path.length - 1)
|
.slice(0, path.length - 1)
|
||||||
@@ -148,8 +150,7 @@ export async function get_displays_where_path_exists(
|
|||||||
.equals(last_path_part)
|
.equals(last_path_part)
|
||||||
.filter((inode) => inode.path === path_without_last_part && inode.type === 'inode/directory')
|
.filter((inode) => inode.path === path_without_last_part && inode.type === 'inode/directory')
|
||||||
.first();
|
.first();
|
||||||
if (!folders_of_current_path)
|
if (!folders_of_current_path) return [];
|
||||||
return await db.displays.where('id').anyOf(selected_display_ids).toArray();
|
|
||||||
const folder_primary_key = get_file_primary_key(folders_of_current_path);
|
const folder_primary_key = get_file_primary_key(folders_of_current_path);
|
||||||
|
|
||||||
const display_ids_with_folder = (
|
const display_ids_with_folder = (
|
||||||
@@ -157,11 +158,7 @@ export async function get_displays_where_path_exists(
|
|||||||
).map((fod) => fod.display_id);
|
).map((fod) => fod.display_id);
|
||||||
|
|
||||||
const display_ids = selected_display_ids.filter((display_id) => {
|
const display_ids = selected_display_ids.filter((display_id) => {
|
||||||
if (invert) {
|
return !display_ids_with_folder.includes(display_id);
|
||||||
return !display_ids_with_folder.includes(display_id);
|
|
||||||
} else {
|
|
||||||
return display_ids_with_folder.includes(display_id);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return (await db.displays.bulkGet(display_ids)).filter((e) => e !== undefined);
|
return (await db.displays.bulkGet(display_ids)).filter((e) => e !== undefined);
|
||||||
@@ -404,31 +401,24 @@ export async function create_path_on_all_selected_displays(
|
|||||||
path: string,
|
path: string,
|
||||||
selected_display_ids: string[]
|
selected_display_ids: string[]
|
||||||
) {
|
) {
|
||||||
const path_parts = path
|
const displays_without_path = await get_displays_where_path_not_exists(
|
||||||
.slice(1, path.length - 1)
|
path,
|
||||||
.split('/')
|
selected_display_ids
|
||||||
.filter((e) => e.length !== 0);
|
);
|
||||||
let remaining_display_ids = [...selected_display_ids];
|
if (displays_without_path.length === 0) return;
|
||||||
|
for (const display of displays_without_path) {
|
||||||
const getDisplaysForPath = async (currentPath: string): Promise<Display[]> => {
|
await create_path(display.ip, path);
|
||||||
if (currentPath === '/') {
|
|
||||||
const displays = await db.displays.bulkGet(remaining_display_ids);
|
|
||||||
return displays.filter((d): d is Display => !!d);
|
|
||||||
}
|
|
||||||
return get_displays_where_path_exists(currentPath, remaining_display_ids, false);
|
|
||||||
};
|
|
||||||
|
|
||||||
for (let depth = path_parts.length; depth >= 0 && remaining_display_ids.length; depth--) {
|
|
||||||
const currentPath = depth === 0 ? '/' : `/${path_parts.slice(0, depth).join('/')}/`;
|
|
||||||
|
|
||||||
const displays = await getDisplaysForPath(currentPath);
|
|
||||||
if (!displays.length) continue;
|
|
||||||
|
|
||||||
for (const display of displays) {
|
|
||||||
await create_folders(display.ip, currentPath, path_parts.slice(depth));
|
|
||||||
remaining_display_ids = remaining_display_ids.filter((id) => id !== display.id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
setTimeout(async () => {
|
||||||
|
for (const display of displays_without_path) {
|
||||||
|
const changed_paths = await get_changed_directory_paths(display, '/');
|
||||||
|
if (!changed_paths) continue;
|
||||||
|
console.debug('Update file system from', display.name, ':', changed_paths);
|
||||||
|
for (const path of changed_paths) {
|
||||||
|
await update_folder_elements_recursively(display, path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get_date_mapping(file_primary_key: string): Promise<Record<string, Date>> {
|
export async function get_date_mapping(file_primary_key: string): Promise<Record<string, Date>> {
|
||||||
|
|||||||
Reference in New Issue
Block a user