treewide: fix various UI bugs; optimize crypto dependencies & format
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: If8fe8b38c1d9c4fecd40ff71f88d2ae06a6a6964
This commit is contained in:
parent
764aafa88d
commit
3ccddce7fd
178 changed files with 58342 additions and 54241 deletions
|
|
@ -1,137 +1,137 @@
|
|||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::{collections::HashMap, path::PathBuf, sync::Arc};
|
||||
|
||||
use pinakes_core::media_type::{BuiltinMediaType, MediaType};
|
||||
use pinakes_core::model::{ContentHash, MediaId, MediaItem, StorageMode};
|
||||
use pinakes_core::storage::{DynStorageBackend, StorageBackend, sqlite::SqliteBackend};
|
||||
use pinakes_core::{
|
||||
media_type::{BuiltinMediaType, MediaType},
|
||||
model::{ContentHash, MediaId, MediaItem, StorageMode},
|
||||
storage::{DynStorageBackend, StorageBackend, sqlite::SqliteBackend},
|
||||
};
|
||||
use tempfile::TempDir;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub async fn setup() -> Arc<SqliteBackend> {
|
||||
let backend = SqliteBackend::in_memory().expect("in-memory SQLite");
|
||||
backend.run_migrations().await.expect("migrations");
|
||||
Arc::new(backend)
|
||||
let backend = SqliteBackend::in_memory().expect("in-memory SQLite");
|
||||
backend.run_migrations().await.expect("migrations");
|
||||
Arc::new(backend)
|
||||
}
|
||||
|
||||
pub async fn setup_test_storage() -> (DynStorageBackend, TempDir) {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let db_path = temp_dir.path().join(format!("test_{}.db", Uuid::now_v7()));
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let db_path = temp_dir.path().join(format!("test_{}.db", Uuid::now_v7()));
|
||||
|
||||
let storage = SqliteBackend::new(&db_path).unwrap();
|
||||
storage.run_migrations().await.unwrap();
|
||||
let storage = SqliteBackend::new(&db_path).unwrap();
|
||||
storage.run_migrations().await.unwrap();
|
||||
|
||||
(Arc::new(storage), temp_dir)
|
||||
(Arc::new(storage), temp_dir)
|
||||
}
|
||||
|
||||
pub fn make_test_media(hash: &str) -> MediaItem {
|
||||
let now = chrono::Utc::now();
|
||||
MediaItem {
|
||||
id: MediaId::new(),
|
||||
path: format!("/tmp/test_{hash}.mp4").into(),
|
||||
file_name: format!("test_{hash}.mp4"),
|
||||
media_type: MediaType::Builtin(BuiltinMediaType::Mp4),
|
||||
content_hash: ContentHash::new(hash.to_string()),
|
||||
file_size: 1000,
|
||||
title: Some(format!("Test {hash}")),
|
||||
artist: Some("Test Artist".to_string()),
|
||||
album: None,
|
||||
genre: None,
|
||||
year: Some(2024),
|
||||
duration_secs: Some(120.0),
|
||||
description: None,
|
||||
thumbnail_path: None,
|
||||
custom_fields: HashMap::new(),
|
||||
file_mtime: None,
|
||||
date_taken: None,
|
||||
latitude: None,
|
||||
longitude: None,
|
||||
camera_make: None,
|
||||
camera_model: None,
|
||||
rating: None,
|
||||
perceptual_hash: None,
|
||||
storage_mode: StorageMode::External,
|
||||
original_filename: None,
|
||||
uploaded_at: None,
|
||||
storage_key: None,
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
deleted_at: None,
|
||||
links_extracted_at: None,
|
||||
}
|
||||
let now = chrono::Utc::now();
|
||||
MediaItem {
|
||||
id: MediaId::new(),
|
||||
path: format!("/tmp/test_{hash}.mp4").into(),
|
||||
file_name: format!("test_{hash}.mp4"),
|
||||
media_type: MediaType::Builtin(BuiltinMediaType::Mp4),
|
||||
content_hash: ContentHash::new(hash.to_string()),
|
||||
file_size: 1000,
|
||||
title: Some(format!("Test {hash}")),
|
||||
artist: Some("Test Artist".to_string()),
|
||||
album: None,
|
||||
genre: None,
|
||||
year: Some(2024),
|
||||
duration_secs: Some(120.0),
|
||||
description: None,
|
||||
thumbnail_path: None,
|
||||
custom_fields: HashMap::new(),
|
||||
file_mtime: None,
|
||||
date_taken: None,
|
||||
latitude: None,
|
||||
longitude: None,
|
||||
camera_make: None,
|
||||
camera_model: None,
|
||||
rating: None,
|
||||
perceptual_hash: None,
|
||||
storage_mode: StorageMode::External,
|
||||
original_filename: None,
|
||||
uploaded_at: None,
|
||||
storage_key: None,
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
deleted_at: None,
|
||||
links_extracted_at: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_test_media_item(path: PathBuf, hash: &str) -> MediaItem {
|
||||
let now = chrono::Utc::now();
|
||||
MediaItem {
|
||||
id: MediaId(Uuid::now_v7()),
|
||||
path,
|
||||
file_name: "test.mp3".to_string(),
|
||||
media_type: MediaType::Builtin(BuiltinMediaType::Mp3),
|
||||
content_hash: ContentHash(hash.to_string()),
|
||||
file_size: 1000,
|
||||
title: None,
|
||||
artist: None,
|
||||
album: None,
|
||||
genre: None,
|
||||
year: None,
|
||||
duration_secs: None,
|
||||
description: None,
|
||||
thumbnail_path: None,
|
||||
custom_fields: HashMap::new(),
|
||||
file_mtime: None,
|
||||
date_taken: None,
|
||||
latitude: None,
|
||||
longitude: None,
|
||||
camera_make: None,
|
||||
camera_model: None,
|
||||
rating: None,
|
||||
perceptual_hash: None,
|
||||
storage_mode: StorageMode::External,
|
||||
original_filename: None,
|
||||
uploaded_at: None,
|
||||
storage_key: None,
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
deleted_at: None,
|
||||
links_extracted_at: None,
|
||||
}
|
||||
let now = chrono::Utc::now();
|
||||
MediaItem {
|
||||
id: MediaId(Uuid::now_v7()),
|
||||
path,
|
||||
file_name: "test.mp3".to_string(),
|
||||
media_type: MediaType::Builtin(BuiltinMediaType::Mp3),
|
||||
content_hash: ContentHash(hash.to_string()),
|
||||
file_size: 1000,
|
||||
title: None,
|
||||
artist: None,
|
||||
album: None,
|
||||
genre: None,
|
||||
year: None,
|
||||
duration_secs: None,
|
||||
description: None,
|
||||
thumbnail_path: None,
|
||||
custom_fields: HashMap::new(),
|
||||
file_mtime: None,
|
||||
date_taken: None,
|
||||
latitude: None,
|
||||
longitude: None,
|
||||
camera_make: None,
|
||||
camera_model: None,
|
||||
rating: None,
|
||||
perceptual_hash: None,
|
||||
storage_mode: StorageMode::External,
|
||||
original_filename: None,
|
||||
uploaded_at: None,
|
||||
storage_key: None,
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
deleted_at: None,
|
||||
links_extracted_at: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a test markdown media item with a given ID
|
||||
pub fn make_test_markdown_item(id: MediaId) -> MediaItem {
|
||||
let now = chrono::Utc::now();
|
||||
MediaItem {
|
||||
id,
|
||||
path: format!("/tmp/test_{}.md", id.0).into(),
|
||||
file_name: format!("test_{}.md", id.0),
|
||||
media_type: MediaType::Builtin(BuiltinMediaType::Markdown),
|
||||
content_hash: ContentHash::new(format!("hash_{}", id.0)),
|
||||
file_size: 1024,
|
||||
title: Some("Test Note".to_string()),
|
||||
artist: None,
|
||||
album: None,
|
||||
genre: None,
|
||||
year: None,
|
||||
duration_secs: None,
|
||||
description: Some("Test markdown note".to_string()),
|
||||
thumbnail_path: None,
|
||||
custom_fields: HashMap::new(),
|
||||
file_mtime: None,
|
||||
date_taken: None,
|
||||
latitude: None,
|
||||
longitude: None,
|
||||
camera_make: None,
|
||||
camera_model: None,
|
||||
rating: None,
|
||||
perceptual_hash: None,
|
||||
storage_mode: StorageMode::External,
|
||||
original_filename: None,
|
||||
uploaded_at: None,
|
||||
storage_key: None,
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
deleted_at: None,
|
||||
links_extracted_at: None,
|
||||
}
|
||||
let now = chrono::Utc::now();
|
||||
MediaItem {
|
||||
id,
|
||||
path: format!("/tmp/test_{}.md", id.0).into(),
|
||||
file_name: format!("test_{}.md", id.0),
|
||||
media_type: MediaType::Builtin(BuiltinMediaType::Markdown),
|
||||
content_hash: ContentHash::new(format!("hash_{}", id.0)),
|
||||
file_size: 1024,
|
||||
title: Some("Test Note".to_string()),
|
||||
artist: None,
|
||||
album: None,
|
||||
genre: None,
|
||||
year: None,
|
||||
duration_secs: None,
|
||||
description: Some("Test markdown note".to_string()),
|
||||
thumbnail_path: None,
|
||||
custom_fields: HashMap::new(),
|
||||
file_mtime: None,
|
||||
date_taken: None,
|
||||
latitude: None,
|
||||
longitude: None,
|
||||
camera_make: None,
|
||||
camera_model: None,
|
||||
rating: None,
|
||||
perceptual_hash: None,
|
||||
storage_mode: StorageMode::External,
|
||||
original_filename: None,
|
||||
uploaded_at: None,
|
||||
storage_key: None,
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
deleted_at: None,
|
||||
links_extracted_at: None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue