fixed explorer

This commit is contained in:
Jamie Pine 2022-05-28 22:23:50 -07:00
parent 3a5961a977
commit 49c25531d6
11 changed files with 50 additions and 54 deletions

View file

@ -3,6 +3,7 @@
"actix",
"bpfrpt",
"consts",
"countup",
"creationdate",
"ipfs",
"Keepsafe",
@ -16,6 +17,7 @@
"tailwindcss",
"trivago",
"tsparticles",
"unlisten",
"upsert"
],
"[rust]": {

1
Cargo.lock generated
View file

@ -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",
]

View file

@ -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 }

View file

@ -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" };
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, } };

View file

@ -1,4 +1,3 @@
import type { File } from "./File";
import type { FilePath } from "./FilePath";
export interface DirectoryWithContents { directory: FilePath, contents: Array<File>, }
export interface DirectoryWithContents { directory: FilePath, contents: Array<FilePath>, }

View file

@ -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, }
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, }

View file

@ -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");

View file

@ -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<File> = 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<FilePath> = 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<File> = 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,
})
}

View file

@ -32,11 +32,8 @@ pub struct File {
pub ipfs_id: Option<String>,
pub comment: Option<String>,
#[ts(type = "string")]
pub date_created: chrono::DateTime<chrono::Utc>,
#[ts(type = "string")]
pub date_modified: chrono::DateTime<chrono::Utc>,
#[ts(type = "string")]
pub date_indexed: chrono::DateTime<chrono::Utc>,
pub paths: Vec<FilePath>,
@ -57,14 +54,12 @@ pub struct FilePath {
pub extension: Option<String>,
pub file_id: Option<i32>,
pub parent_id: Option<i32>,
// pub temp_cas_id: Option<String>,
pub has_local_thumbnail: bool,
#[ts(type = "string")]
pub date_created: chrono::DateTime<chrono::Utc>,
#[ts(type = "string")]
pub date_modified: chrono::DateTime<chrono::Utc>,
#[ts(type = "string")]
pub date_indexed: chrono::DateTime<chrono::Utc>,
pub file: Option<File>,
}
#[repr(i32)]
@ -108,7 +103,7 @@ impl Into<File> for file::Data {
}
impl Into<FilePath> 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<FilePath> 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<FilePath> for file_path::Data {
#[ts(export)]
pub struct DirectoryWithContents {
pub directory: FilePath,
pub contents: Vec<File>,
pub contents: Vec<FilePath>,
}
#[derive(Error, Debug)]

View file

@ -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':

View file

@ -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 (
<Transition
@ -48,17 +48,17 @@ export const Inspector = (props: { selectedFile?: FilePath; locationId: number }
leaveTo="translate-x-64"
>
<div className="top-0 right-0 h-full m-2 border border-gray-100 rounded-lg w-60 dark:border-gray-850 ">
{!!file && (
{!!file_path && (
<div className="flex flex-col h-full overflow-hidden bg-white rounded-lg select-text dark:bg-gray-600 bg-opacity-70">
<div className="flex items-center justify-center w-full h-64 overflow-hidden rounded-t-lg bg-gray-50 dark:bg-gray-900">
<FileThumb
hasThumbnailOverride={false}
className="!m-0 flex flex-shrink flex-grow-0"
file={file}
file={file_path}
locationId={props.locationId}
/>
</div>
<h3 className="pt-3 pl-3 text-base font-bold">{file?.name}</h3>
<h3 className="pt-3 pl-3 text-base font-bold">{file_path?.name}</h3>
<div className="flex flex-row m-3 space-x-2">
<Button size="sm" noPadding>
<Heart className="w-[18px] h-[18px]" />
@ -70,34 +70,34 @@ export const Inspector = (props: { selectedFile?: FilePath; locationId: number }
<Link className="w-[18px] h-[18px]" />
</Button>
</div>
{file?.temp_cas_id && (
<MetaItem title="Unique Content ID" value={file.temp_cas_id as string} />
{file_path?.file?.cas_id && (
<MetaItem title="Unique Content ID" value={file_path.file.cas_id as string} />
)}
<Divider />
<MetaItem title="Uri" value={file?.materialized_path as string} />
<MetaItem title="Uri" value={file_path?.materialized_path as string} />
<Divider />
<MetaItem
title="Date Created"
value={moment(file?.date_created).format('MMMM Do YYYY, h:mm:ss a')}
value={moment(file_path?.date_created).format('MMMM Do YYYY, h:mm:ss a')}
/>
<Divider />
<MetaItem
title="Date Indexed"
value={moment(file?.date_indexed).format('MMMM Do YYYY, h:mm:ss a')}
value={moment(file_path?.date_indexed).format('MMMM Do YYYY, h:mm:ss a')}
/>
<Divider />
{!file?.is_dir && (
{!file_path?.is_dir && (
<>
<div className="flex flex-row items-center px-3 py-2 meta-item">
{file?.extension && (
{file_path?.extension && (
<span className="inline px-1 mr-1 text-xs font-bold uppercase bg-gray-500 rounded-md text-gray-150">
{file?.extension}
{file_path?.extension}
</span>
)}
<p className="text-xs text-gray-600 break-all truncate dark:text-gray-300">
{file?.extension
{file_path?.extension
? //@ts-ignore
types[file.extension.toUpperCase()]?.descriptions.join(' / ')
types[file_path.extension.toUpperCase()]?.descriptions.join(' / ')
: 'Unknown'}
</p>
</div>