Date header is not working (#2321)

* wip

* more

* bindings

* show date taken

* improve date lookup and include placeholder

* date taken

---------

Co-authored-by: nikec <nikec.job@gmail.com>
This commit is contained in:
Oscar Beaumont 2024-04-15 20:53:11 +08:00 committed by GitHub
parent d9b31a90b3
commit e77a475e61
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 56 additions and 12 deletions

1
Cargo.lock generated
View file

@ -8691,6 +8691,7 @@ name = "sd-core-prisma-helpers"
version = "0.1.0"
dependencies = [
"prisma-client-rust",
"sd-cache",
"sd-prisma",
"serde",
]

View file

@ -11,6 +11,7 @@ edition = { workspace = true }
[dependencies]
# Spacedrive Sub-crates
sd-prisma = { path = "../../../crates/prisma" }
sd-cache = { path = "../../../crates/cache" }
prisma-client-rust = { workspace = true }
serde = { workspace = true }

View file

@ -27,7 +27,7 @@
#![forbid(deprecated_in_future)]
#![allow(clippy::missing_errors_doc, clippy::module_name_repetitions)]
use sd_prisma::prisma::{file_path, job, label, location, object};
use sd_prisma::prisma::{self, file_path, job, label, location, object};
// File Path selectables!
file_path::select!(file_path_pub_and_cas_ids { id pub_id cas_id });
@ -136,7 +136,20 @@ file_path::select!(file_path_to_full_path {
});
// File Path includes!
file_path::include!(file_path_with_object { object });
file_path::include!(file_path_with_object {
object: include {
media_data: select {
resolution
media_date
media_location
camera_data
artist
description
copyright
exif_version
}
}
});
// Object selectables!
object::select!(object_for_file_identifier {
@ -145,7 +158,29 @@ object::select!(object_for_file_identifier {
});
// Object includes!
object::include!(object_with_file_paths { file_paths });
object::include!(object_with_file_paths {
file_paths: include {
object: include {
media_data: select {
resolution
media_date
media_location
camera_data
artist
description
copyright
exif_version
}
}
}
});
impl sd_cache::Model for object_with_file_paths::file_paths::Data {
fn name() -> &'static str {
// This is okay because it's a superset of the available fields.
prisma::file_path::NAME
}
}
// Job selectables!
job::select!(job_without_data {

View file

@ -36,11 +36,8 @@ export function getDate(item: ExplorerItem, orderBy: OrderingKey) {
return filePath.dateAccessed;
}
// TODO: Uncomment when we add sorting by date taken
// case 'object.mediaData.epochTime': {
// firstFilePathDate = firstFilePath.dateTaken;
// lastFilePathDate = lastFilePath.dateTaken;
// break;
// }
case 'object.mediaData.epochTime': {
return filePath.dateTaken;
}
}
}

View file

@ -272,7 +272,7 @@ export type FilePathOrder = { field: "name"; value: SortOrder } | { field: "size
export type FilePathSearchArgs = { take?: number | null; orderAndPagination?: OrderAndPagination<number, FilePathOrder, FilePathCursor> | null; filters?: SearchFilterArgs[]; groupDirectories?: boolean }
export type FilePathWithObject = { id: number; pub_id: number[]; is_dir: boolean | null; cas_id: string | null; integrity_checksum: string | null; location_id: number | null; materialized_path: string | null; name: string | null; extension: string | null; hidden: boolean | null; size_in_bytes: string | null; size_in_bytes_bytes: number[] | null; inode: number[] | null; object_id: number | null; key_id: number | null; date_created: string | null; date_modified: string | null; date_indexed: string | null; object: { id: number; pub_id: number[]; kind: number | null; key_id: number | null; hidden: boolean | null; favorite: boolean | null; important: boolean | null; note: string | null; date_created: string | null; date_accessed: string | null } | null }
export type FilePathWithObject = { id: number; pub_id: number[]; is_dir: boolean | null; cas_id: string | null; integrity_checksum: string | null; location_id: number | null; materialized_path: string | null; name: string | null; extension: string | null; hidden: boolean | null; size_in_bytes: string | null; size_in_bytes_bytes: number[] | null; inode: number[] | null; object_id: number | null; key_id: number | null; date_created: string | null; date_modified: string | null; date_indexed: string | null; object: { id: number; pub_id: number[]; kind: number | null; key_id: number | null; hidden: boolean | null; favorite: boolean | null; important: boolean | null; note: string | null; date_created: string | null; date_accessed: string | null; media_data: { resolution: number[] | null; media_date: number[] | null; media_location: number[] | null; camera_data: number[] | null; artist: string | null; description: string | null; copyright: string | null; exif_version: string | null } | null } | null }
export type Flash = {
/**
@ -504,7 +504,7 @@ export type ObjectSearchArgs = { take: number; orderAndPagination?: OrderAndPagi
export type ObjectValidatorArgs = { id: number; path: string }
export type ObjectWithFilePaths = { id: number; pub_id: number[]; kind: number | null; key_id: number | null; hidden: boolean | null; favorite: boolean | null; important: boolean | null; note: string | null; date_created: string | null; date_accessed: string | null; file_paths: FilePath[] }
export type ObjectWithFilePaths = { id: number; pub_id: number[]; kind: number | null; key_id: number | null; hidden: boolean | null; favorite: boolean | null; important: boolean | null; note: string | null; date_created: string | null; date_accessed: string | null; file_paths: ({ id: number; pub_id: number[]; is_dir: boolean | null; cas_id: string | null; integrity_checksum: string | null; location_id: number | null; materialized_path: string | null; name: string | null; extension: string | null; hidden: boolean | null; size_in_bytes: string | null; size_in_bytes_bytes: number[] | null; inode: number[] | null; object_id: number | null; key_id: number | null; date_created: string | null; date_modified: string | null; date_indexed: string | null; object: { id: number; pub_id: number[]; kind: number | null; key_id: number | null; hidden: boolean | null; favorite: boolean | null; important: boolean | null; note: string | null; date_created: string | null; date_accessed: string | null; media_data: { resolution: number[] | null; media_date: number[] | null; media_location: number[] | null; camera_data: number[] | null; artist: string | null; description: string | null; copyright: string | null; exif_version: string | null } | null } | null })[] }
export type ObjectWithFilePaths2 = { id: number; pub_id: number[]; kind: number | null; key_id: number | null; hidden: boolean | null; favorite: boolean | null; important: boolean | null; note: string | null; date_created: string | null; date_accessed: string | null; file_paths: Reference<FilePath>[] }

View file

@ -18,6 +18,7 @@ export interface ItemData {
dateCreated: string | null;
dateModified: string | null;
dateAccessed: string | null;
dateTaken: string | null;
thumbnailKey: string[]; // default behavior is to render a single thumbnail
thumbnailKeys?: string[][]; // if set, we can render multiple thumbnails
hasLocalThumbnail: boolean; // this is overwritten when new thumbnails are generated
@ -37,7 +38,15 @@ export function getExplorerItemData(data?: ExplorerItem | null): ItemData {
// handle object
const object = getItemObject(data);
if (object?.kind) itemData.kind = ObjectKind[object?.kind] ?? 'Unknown';
if (object) {
if (object.kind) itemData.kind = ObjectKind[object.kind] ?? 'Unknown';
if ('media_data' in object && object.media_data?.media_date) {
const byteArray = object.media_data.media_date;
const dateString = String.fromCharCode.apply(null, byteArray);
const [date, time] = dateString.replace(/"/g, '').split(' ');
if (date && time) itemData.dateTaken = `${date}T${time}Z`;
}
}
// Objects only have dateCreated and dateAccessed
itemData.dateCreated = object?.date_created ?? null;
@ -152,6 +161,7 @@ function getDefaultItemData(kind: ObjectKindKey = 'Unknown'): ItemData {
dateCreated: null,
dateModified: null,
dateAccessed: null,
dateTaken: null,
thumbnailKey: [],
hasLocalThumbnail: false,
customIcon: null