refactor(server): apply fmt + lint recos
This commit is contained in:
@@ -60,9 +60,7 @@ impl AudioMetadataService {
|
||||
///
|
||||
/// All I/O is synchronous (id3 + mp3_duration crates), so this MUST
|
||||
/// only be called inside `spawn_blocking`.
|
||||
fn extract_metadata_blocking(
|
||||
file_path: &Path,
|
||||
) -> Option<AudioMetadataFields> {
|
||||
fn extract_metadata_blocking(file_path: &Path) -> Option<AudioMetadataFields> {
|
||||
if !file_path.exists() {
|
||||
warn!("File does not exist: {:?}", file_path);
|
||||
return None;
|
||||
@@ -114,13 +112,14 @@ impl AudioMetadataService {
|
||||
|
||||
// ── Sync I/O on the blocking thread pool (never stalls Tokio workers) ──
|
||||
let path = file_path.to_path_buf();
|
||||
let metadata = tokio::task::spawn_blocking(move || {
|
||||
Self::extract_metadata_blocking(&path)
|
||||
})
|
||||
.await
|
||||
.map_err(|e| {
|
||||
DomainError::internal_error("AudioMetadataService", format!("spawn_blocking join error: {e}"))
|
||||
})?;
|
||||
let metadata = tokio::task::spawn_blocking(move || Self::extract_metadata_blocking(&path))
|
||||
.await
|
||||
.map_err(|e| {
|
||||
DomainError::internal_error(
|
||||
"AudioMetadataService",
|
||||
format!("spawn_blocking join error: {e}"),
|
||||
)
|
||||
})?;
|
||||
|
||||
let Some(m) = metadata else {
|
||||
return Ok(());
|
||||
|
||||
@@ -717,7 +717,11 @@ impl DedupService {
|
||||
// Also clean up any thumbnail files for these blob hashes
|
||||
// (thumbnails are keyed by blob_hash and live under
|
||||
// storage_root/.thumbnails/{icon,preview,large}/{hash}.jpg).
|
||||
let thumbnails_root = self.blob_root.parent().unwrap_or(&self.blob_root).join(".thumbnails");
|
||||
let thumbnails_root = self
|
||||
.blob_root
|
||||
.parent()
|
||||
.unwrap_or(&self.blob_root)
|
||||
.join(".thumbnails");
|
||||
for (hash, size) in &batch {
|
||||
let blob_path = self.blob_path(hash);
|
||||
if let Err(e) = fs::remove_file(&blob_path).await {
|
||||
|
||||
@@ -40,7 +40,12 @@ async fn generate_thumbnail_from_blob_path() {
|
||||
|
||||
// The key assertion: the service can read from a blob path (not a logical path)
|
||||
let result = svc
|
||||
.get_thumbnail("test-file-id", "ab1234567890", ThumbnailSize::Icon, &blob_path)
|
||||
.get_thumbnail(
|
||||
"test-file-id",
|
||||
"ab1234567890",
|
||||
ThumbnailSize::Icon,
|
||||
&blob_path,
|
||||
)
|
||||
.await;
|
||||
|
||||
let thumb_bytes = result.expect("thumbnail generation should succeed from blob path");
|
||||
@@ -67,7 +72,12 @@ async fn generate_thumbnail_nonexistent_path_returns_error() {
|
||||
|
||||
let bad_path = tmp.path().join("does-not-exist.png");
|
||||
let result = svc
|
||||
.get_thumbnail("missing-id", "nonexistent-hash", ThumbnailSize::Icon, &bad_path)
|
||||
.get_thumbnail(
|
||||
"missing-id",
|
||||
"nonexistent-hash",
|
||||
ThumbnailSize::Icon,
|
||||
&bad_path,
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(result.is_err(), "should fail for nonexistent file");
|
||||
|
||||
Reference in New Issue
Block a user