From 49c25531d66875602f17e8754fa32a13e733ca97 Mon Sep 17 00:00:00 2001 From: Jamie Pine Date: Sat, 28 May 2022 22:23:50 -0700 Subject: [PATCH] fixed explorer --- .vscode/settings.json | 2 + Cargo.lock | 1 + core/Cargo.toml | 2 +- core/bindings/ClientCommand.ts | 2 +- core/bindings/DirectoryWithContents.ts | 3 +- core/bindings/FilePath.ts | 3 +- core/src/encode/thumb.rs | 4 +- core/src/file/explorer/open.rs | 38 ++++++++++--------- core/src/file/mod.rs | 19 +++------- .../src/components/file/FileList.tsx | 2 +- .../src/components/file/Inspector.tsx | 28 +++++++------- 11 files changed, 50 insertions(+), 54 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 3d1c13bb5..a325ff094 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,7 @@ "actix", "bpfrpt", "consts", + "countup", "creationdate", "ipfs", "Keepsafe", @@ -16,6 +17,7 @@ "tailwindcss", "trivago", "tsparticles", + "unlisten", "upsert" ], "[rust]": { diff --git a/Cargo.lock b/Cargo.lock index 5f2869ac6..015c6632f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8058,6 +8058,7 @@ version = "6.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d26cba30c9b3a2f537f765cf754126f11c983b7426d280ae0b4cef2374cab98" dependencies = [ + "chrono", "thiserror", "ts-rs-macros", ] diff --git a/core/Cargo.toml b/core/Cargo.toml index f8a2c9cde..449629580 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -26,7 +26,7 @@ ring = "0.17.0-alpha.10" int-enum = "0.4.0" # Project dependencies -ts-rs = "6.1" +ts-rs = { version = "6.1", features = ["chrono-impl"] } prisma-client-rust = { git = "https://github.com/Brendonovich/prisma-client-rust.git", tag = "0.5.0" } walkdir = "^2.3.2" libp2p = { version = "0.43.0", optional = true } diff --git a/core/bindings/ClientCommand.ts b/core/bindings/ClientCommand.ts index d6b37840c..30f671ffc 100644 --- a/core/bindings/ClientCommand.ts +++ b/core/bindings/ClientCommand.ts @@ -1,2 +1,2 @@ -export type ClientCommand = { key: "FileRead", params: { id: number, } } | { key: "FileDelete", params: { id: number, } } | { key: "LibDelete", params: { id: number, } } | { key: "TagCreate", params: { name: string, color: string, } } | { key: "TagUpdate", params: { name: string, color: string, } } | { key: "TagAssign", params: { file_id: number, tag_id: number, } } | { key: "TagDelete", params: { id: number, } } | { key: "LocCreate", params: { path: string, } } | { key: "LocUpdate", params: { id: number, name: string | null, } } | { key: "LocDelete", params: { id: number, } } | { key: "SysVolumeUnmount", params: { id: number, } } | { key: "GenerateThumbsForLocation", params: { id: number, path: string, } } | { key: "IdentifyUniqueFiles" }; \ No newline at end of file +export type ClientCommand = { key: "FileRead", params: { id: number, } } | { key: "FileDelete", params: { id: number, } } | { key: "LibDelete", params: { id: number, } } | { key: "TagCreate", params: { name: string, color: string, } } | { key: "TagUpdate", params: { name: string, color: string, } } | { key: "TagAssign", params: { file_id: number, tag_id: number, } } | { key: "TagDelete", params: { id: number, } } | { key: "LocCreate", params: { path: string, } } | { key: "LocUpdate", params: { id: number, name: string | null, } } | { key: "LocDelete", params: { id: number, } } | { key: "SysVolumeUnmount", params: { id: number, } } | { key: "GenerateThumbsForLocation", params: { id: number, path: string, } } | { key: "IdentifyUniqueFiles", params: { id: number, path: string, } }; \ No newline at end of file diff --git a/core/bindings/DirectoryWithContents.ts b/core/bindings/DirectoryWithContents.ts index a707e2db7..89c0fb64f 100644 --- a/core/bindings/DirectoryWithContents.ts +++ b/core/bindings/DirectoryWithContents.ts @@ -1,4 +1,3 @@ -import type { File } from "./File"; import type { FilePath } from "./FilePath"; -export interface DirectoryWithContents { directory: FilePath, contents: Array, } \ No newline at end of file +export interface DirectoryWithContents { directory: FilePath, contents: Array, } \ No newline at end of file diff --git a/core/bindings/FilePath.ts b/core/bindings/FilePath.ts index eef368325..c492c893d 100644 --- a/core/bindings/FilePath.ts +++ b/core/bindings/FilePath.ts @@ -1,2 +1,3 @@ +import type { File } from "./File"; -export interface FilePath { id: number, is_dir: boolean, location_id: number, materialized_path: string, name: string, extension: string | null, file_id: number | null, parent_id: number | null, has_local_thumbnail: boolean, date_created: string, date_modified: string, date_indexed: string, } \ No newline at end of file +export interface FilePath { id: number, is_dir: boolean, location_id: number, materialized_path: string, name: string, extension: string | null, file_id: number | null, parent_id: number | null, date_created: string, date_modified: string, date_indexed: string, file: File | null, } \ No newline at end of file diff --git a/core/src/encode/thumb.rs b/core/src/encode/thumb.rs index aaf949609..b42e39e8a 100644 --- a/core/src/encode/thumb.rs +++ b/core/src/encode/thumb.rs @@ -45,8 +45,6 @@ impl Job for ThumbnailJob { let image_files = get_images(&core_ctx, self.location_id, &self.path).await?; - let location_id = location.id.clone(); - println!("Found {:?} files", image_files.len()); let is_background = self.background.clone(); @@ -79,7 +77,7 @@ impl Job for ThumbnailJob { // Define and write the WebP-encoded file to a given path let output_path = Path::new(&config.data_path) .join(THUMBNAIL_CACHE_DIR_NAME) - .join(format!("{}", location_id)) + .join(format!("{}", location.id)) .join(&cas_id) .with_extension("webp"); diff --git a/core/src/file/explorer/open.rs b/core/src/file/explorer/open.rs index 2ff867955..d29e0c8fa 100644 --- a/core/src/file/explorer/open.rs +++ b/core/src/file/explorer/open.rs @@ -1,6 +1,6 @@ use crate::{ encode::thumb::THUMBNAIL_CACHE_DIR_NAME, - file::{DirectoryWithContents, File, FileError}, + file::{DirectoryWithContents, File, FileError, FilePath}, node::state, prisma::{file, file_path}, sys::locations::get_location, @@ -30,33 +30,35 @@ pub async fn open_dir( .await? .ok_or(FileError::DirectoryNotFound(path.to_string()))?; - // TODO: this is incorrect, we need to query on file paths - let files: Vec = db - .file() - .find_many(vec![file::paths::some(vec![file_path::parent_id::equals( - Some(directory.id), - )])]) + println!("DIRECTORY: {:?}", directory); + + let mut file_paths: Vec = db + .file_path() + .find_many(vec![ + file_path::location_id::equals(location.id), + file_path::parent_id::equals(Some(directory.id)), + ]) + .with(file_path::file::fetch()) .exec() .await? .into_iter() .map(Into::into) .collect(); - let mut contents: Vec = vec![]; + for file_path in &mut file_paths { + if let Some(file) = &mut file_path.file { + let thumb_path = Path::new(&config.data_path) + .join(THUMBNAIL_CACHE_DIR_NAME) + .join(format!("{}", location.id)) + .join(file.cas_id.clone()) + .with_extension("webp"); - for mut file in files { - let thumb_path = Path::new(&config.data_path) - .join(THUMBNAIL_CACHE_DIR_NAME) - .join(format!("{}", location.id)) - .join(file.cas_id.clone()) - .with_extension("webp"); - - file.has_thumbnail = thumb_path.exists(); - contents.push(file); + file.has_thumbnail = thumb_path.exists(); + } } Ok(DirectoryWithContents { directory: directory.into(), - contents, + contents: file_paths, }) } diff --git a/core/src/file/mod.rs b/core/src/file/mod.rs index a0dff8355..237b8ed2d 100644 --- a/core/src/file/mod.rs +++ b/core/src/file/mod.rs @@ -32,11 +32,8 @@ pub struct File { pub ipfs_id: Option, pub comment: Option, - #[ts(type = "string")] pub date_created: chrono::DateTime, - #[ts(type = "string")] pub date_modified: chrono::DateTime, - #[ts(type = "string")] pub date_indexed: chrono::DateTime, pub paths: Vec, @@ -57,14 +54,12 @@ pub struct FilePath { pub extension: Option, pub file_id: Option, pub parent_id: Option, - // pub temp_cas_id: Option, - pub has_local_thumbnail: bool, - #[ts(type = "string")] + pub date_created: chrono::DateTime, - #[ts(type = "string")] pub date_modified: chrono::DateTime, - #[ts(type = "string")] pub date_indexed: chrono::DateTime, + + pub file: Option, } #[repr(i32)] @@ -108,7 +103,7 @@ impl Into for file::Data { } impl Into for file_path::Data { - fn into(self) -> FilePath { + fn into(mut self) -> FilePath { FilePath { id: self.id, is_dir: self.is_dir, @@ -117,13 +112,11 @@ impl Into for file_path::Data { parent_id: self.parent_id, location_id: self.location_id, date_indexed: self.date_indexed.into(), - // permissions: self.permissions, - has_local_thumbnail: false, name: self.name, extension: self.extension, - // temp_cas_id: self.temp_cas_id, date_created: self.date_created.into(), date_modified: self.date_modified.into(), + file: self.file.take().unwrap_or(None).map(|file| (*file).into()), } } } @@ -132,7 +125,7 @@ impl Into for file_path::Data { #[ts(export)] pub struct DirectoryWithContents { pub directory: FilePath, - pub contents: Vec, + pub contents: Vec, } #[derive(Error, Debug)] diff --git a/packages/interface/src/components/file/FileList.tsx b/packages/interface/src/components/file/FileList.tsx index 529edf572..b6ac631f5 100644 --- a/packages/interface/src/components/file/FileList.tsx +++ b/packages/interface/src/components/file/FileList.tsx @@ -227,7 +227,7 @@ const RenderCell: React.FC<{ const location = useContext(LocationContext); const { newThumbnails } = useExplorerState(); - const hasNewThumbnail = !!newThumbnails[row?.temp_cas_id ?? '']; + const hasNewThumbnail = !!newThumbnails[row?.file?.cas_id ?? '']; switch (colKey) { case 'name': diff --git a/packages/interface/src/components/file/Inspector.tsx b/packages/interface/src/components/file/Inspector.tsx index 8b050ad91..efc583527 100644 --- a/packages/interface/src/components/file/Inspector.tsx +++ b/packages/interface/src/components/file/Inspector.tsx @@ -35,7 +35,7 @@ export const Inspector = (props: { selectedFile?: FilePath; locationId: number } // const { selectedRowIndex } = useExplorerState(); // const isOpen = !!props.selectedFile; - const file = props.selectedFile; + const file_path = props.selectedFile; return (
- {!!file && ( + {!!file_path && (
-

{file?.name}

+

{file_path?.name}

- {file?.temp_cas_id && ( - + {file_path?.file?.cas_id && ( + )} - + - {!file?.is_dir && ( + {!file_path?.is_dir && ( <>
- {file?.extension && ( + {file_path?.extension && ( - {file?.extension} + {file_path?.extension} )}

- {file?.extension + {file_path?.extension ? //@ts-ignore - types[file.extension.toUpperCase()]?.descriptions.join(' / ') + types[file_path.extension.toUpperCase()]?.descriptions.join(' / ') : 'Unknown'}