pinakes-core: update remaining modules and tests
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I9e0ff5ea33a5cf697473423e88f167ce6a6a6964
This commit is contained in:
parent
c8425a4c34
commit
3d9f8933d2
44 changed files with 1207 additions and 578 deletions
|
|
@ -1,6 +1,6 @@
|
|||
//! Upload processing for managed storage.
|
||||
//!
|
||||
//! Handles file uploads, metadata extraction, and MediaItem creation
|
||||
//! Handles file uploads, metadata extraction, and `MediaItem` creation
|
||||
//! for files stored in managed content-addressable storage.
|
||||
|
||||
use std::{collections::HashMap, path::Path};
|
||||
|
|
@ -24,7 +24,11 @@ use crate::{
|
|||
/// 1. Stores the file in managed storage
|
||||
/// 2. Checks for duplicates by content hash
|
||||
/// 3. Extracts metadata from the file
|
||||
/// 4. Creates or updates the MediaItem
|
||||
/// 4. Creates or updates the `MediaItem`
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`PinakesError`] if storage, hashing, or metadata extraction fails.
|
||||
pub async fn process_upload<R: AsyncRead + Unpin>(
|
||||
storage: &DynStorageBackend,
|
||||
managed: &ManagedStorageService,
|
||||
|
|
@ -54,13 +58,10 @@ pub async fn process_upload<R: AsyncRead + Unpin>(
|
|||
let blob_path = managed.path(&content_hash);
|
||||
|
||||
// Extract metadata
|
||||
let extracted =
|
||||
metadata::extract_metadata(&blob_path, media_type.clone()).ok();
|
||||
let extracted = metadata::extract_metadata(&blob_path, &media_type).ok();
|
||||
|
||||
// Create or get blob record
|
||||
let mime = mime_type
|
||||
.map(String::from)
|
||||
.unwrap_or_else(|| media_type.mime_type().to_string());
|
||||
let mime = mime_type.map_or_else(|| media_type.mime_type(), String::from);
|
||||
let _blob = storage
|
||||
.get_or_create_blob(&content_hash, file_size, &mime)
|
||||
.await?;
|
||||
|
|
@ -123,6 +124,10 @@ pub async fn process_upload<R: AsyncRead + Unpin>(
|
|||
}
|
||||
|
||||
/// Process an upload from bytes.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`PinakesError`] if storage or processing fails.
|
||||
pub async fn process_upload_bytes(
|
||||
storage: &DynStorageBackend,
|
||||
managed: &ManagedStorageService,
|
||||
|
|
@ -138,6 +143,10 @@ pub async fn process_upload_bytes(
|
|||
/// Process an upload from a local file path.
|
||||
///
|
||||
/// This is useful for migrating existing external files to managed storage.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`PinakesError`] if the file cannot be opened or processing fails.
|
||||
pub async fn process_upload_file(
|
||||
storage: &DynStorageBackend,
|
||||
managed: &ManagedStorageService,
|
||||
|
|
@ -160,6 +169,11 @@ pub async fn process_upload_file(
|
|||
}
|
||||
|
||||
/// Migrate an existing external media item to managed storage.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`PinakesError`] if the media item cannot be found, the file is
|
||||
/// missing, or the storage migration fails.
|
||||
pub async fn migrate_to_managed(
|
||||
storage: &DynStorageBackend,
|
||||
managed: &ManagedStorageService,
|
||||
|
|
@ -190,7 +204,7 @@ pub async fn migrate_to_managed(
|
|||
}
|
||||
|
||||
// Get or create blob record
|
||||
let mime = item.media_type.mime_type().to_string();
|
||||
let mime = item.media_type.mime_type().clone();
|
||||
let _blob = storage
|
||||
.get_or_create_blob(&new_hash, new_size, &mime)
|
||||
.await?;
|
||||
|
|
@ -227,6 +241,11 @@ fn sanitize_filename(name: &str) -> String {
|
|||
}
|
||||
|
||||
/// Delete a managed media item and clean up the blob if orphaned.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`PinakesError`] if the media item cannot be found or deletion
|
||||
/// fails.
|
||||
pub async fn delete_managed_media(
|
||||
storage: &DynStorageBackend,
|
||||
managed: &ManagedStorageService,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue