From a683f44ecb15cff1973f74a5377f015fe94a50b9 Mon Sep 17 00:00:00 2001 From: 409 <409dev@protonmail.com> Date: Wed, 16 Jul 2025 04:14:26 +0200 Subject: [PATCH] directory entries show created at date --- .../src/lib/domain/file_system/models/file.rs | 13 +++++++++- .../handlers/warrens/list_warren_files.rs | 2 ++ backend/src/lib/outbound/file_system.rs | 11 ++++++++- frontend/components/DirectoryEntry.vue | 24 ++++++++++++------- frontend/types/index.ts | 2 ++ 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/backend/src/lib/domain/file_system/models/file.rs b/backend/src/lib/domain/file_system/models/file.rs index 667c71a..e347cdd 100644 --- a/backend/src/lib/domain/file_system/models/file.rs +++ b/backend/src/lib/domain/file_system/models/file.rs @@ -9,14 +9,21 @@ pub struct File { name: FileName, file_type: FileType, mime_type: Option, + created_at: u64, } impl File { - pub fn new(name: FileName, file_type: FileType, mime_type: Option) -> Self { + pub fn new( + name: FileName, + file_type: FileType, + mime_type: Option, + created_at: u64, + ) -> Self { Self { name, file_type, mime_type, + created_at, } } @@ -31,6 +38,10 @@ impl File { pub fn mime_type(&self) -> Option<&FileMimeType> { self.mime_type.as_ref() } + + pub fn created_at(&self) -> u64 { + self.created_at + } } /// A valid file name diff --git a/backend/src/lib/inbound/http/handlers/warrens/list_warren_files.rs b/backend/src/lib/inbound/http/handlers/warrens/list_warren_files.rs index f38a62c..673eff8 100644 --- a/backend/src/lib/inbound/http/handlers/warrens/list_warren_files.rs +++ b/backend/src/lib/inbound/http/handlers/warrens/list_warren_files.rs @@ -68,6 +68,7 @@ pub struct WarrenFileElement { name: String, file_type: FileType, mime_type: Option, + created_at: u64, } #[derive(Debug, Clone, PartialEq, Eq, Serialize)] @@ -82,6 +83,7 @@ impl From for WarrenFileElement { name: value.name().to_string(), file_type: value.file_type().to_owned(), mime_type: value.mime_type().map(FileMimeType::to_string), + created_at: value.created_at(), } } } diff --git a/backend/src/lib/outbound/file_system.rs b/backend/src/lib/outbound/file_system.rs index ac655bf..178651c 100644 --- a/backend/src/lib/outbound/file_system.rs +++ b/backend/src/lib/outbound/file_system.rs @@ -1,3 +1,5 @@ +use std::time::UNIX_EPOCH; + use anyhow::{Context, anyhow}; use tokio::{fs, io::AsyncWriteExt as _}; @@ -67,13 +69,20 @@ impl FileSystem { continue; } }; + let metadata = entry.metadata().await?; + let created_at = metadata.created()?.duration_since(UNIX_EPOCH)?.as_secs(); let mime_type = match file_type { FileType::File => FileMimeType::from_name(&name), _ => None, }; - files.push(File::new(FileName::new(&name)?, file_type, mime_type)); + files.push(File::new( + FileName::new(&name)?, + file_type, + mime_type, + created_at, + )); } Ok(files) diff --git a/frontend/components/DirectoryEntry.vue b/frontend/components/DirectoryEntry.vue index 59083f7..674c757 100644 --- a/frontend/components/DirectoryEntry.vue +++ b/frontend/components/DirectoryEntry.vue @@ -7,6 +7,7 @@ import { } from '@/components/ui/context-menu'; import { deleteWarrenDirectory, deleteWarrenFile } from '~/lib/api/warrens'; import type { DirectoryEntry } from '~/types'; +import { buttonVariants } from '@/components/ui/button'; const route = useRoute(); const warrenRoute = useWarrenRoute(); @@ -37,22 +38,27 @@ async function submitDelete(force: boolean = false) { - + {{ entry.name }} + + diff --git a/frontend/types/index.ts b/frontend/types/index.ts index f759455..9cc83b9 100644 --- a/frontend/types/index.ts +++ b/frontend/types/index.ts @@ -9,6 +9,8 @@ export type DirectoryEntry = { name: string; fileType: FileType; mimeType: string | null; + /// Timestamp in seconds + createdAt: number; }; export type UploadStatus =