style: cargo fmt --all

This commit is contained in:
2026-05-31 05:31:42 +02:00
parent 4b31a0f74b
commit c2ebca0da0
138 changed files with 2422 additions and 1164 deletions

View File

@@ -1,15 +1,17 @@
use std::sync::Arc;
use bytes::Bytes;
use domain::{
entities::{Asset, AssetType, IngestSession, IngestStatus, SourceReference, UsageLedgerEntry, UsageType},
entities::{
Asset, AssetType, IngestSession, IngestStatus, SourceReference, UsageLedgerEntry, UsageType,
},
errors::DomainError,
events::DomainEvent,
ports::{
AssetRepository, EventPublisher, FileStoragePort,
IngestSessionRepository, LibraryPathRepository, QuotaRepository, UsageLedgerRepository,
AssetRepository, EventPublisher, FileStoragePort, IngestSessionRepository,
LibraryPathRepository, QuotaRepository, UsageLedgerRepository,
},
value_objects::{Checksum, DateTimeStamp, SystemId},
};
use std::sync::Arc;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct IngestAssetCommand {
@@ -43,25 +45,53 @@ impl IngestAssetHandler {
file_storage: Arc<dyn FileStoragePort>,
event_pub: Arc<dyn EventPublisher>,
) -> Self {
Self { ingest_repo, path_repo, quota_repo, ledger_repo, asset_repo, file_storage, event_pub }
Self {
ingest_repo,
path_repo,
quota_repo,
ledger_repo,
asset_repo,
file_storage,
event_pub,
}
}
pub async fn execute(&self, cmd: IngestAssetCommand) -> Result<(Asset, IngestSession), DomainError> {
pub async fn execute(
&self,
cmd: IngestAssetCommand,
) -> Result<(Asset, IngestSession), DomainError> {
let checksum = Checksum::new(&cmd.checksum)?;
let path = self.path_repo.find_by_id(&cmd.target_path_id).await?
.ok_or_else(|| DomainError::NotFound(format!("Library path {} not found", cmd.target_path_id)))?;
let path = self
.path_repo
.find_by_id(&cmd.target_path_id)
.await?
.ok_or_else(|| {
DomainError::NotFound(format!("Library path {} not found", cmd.target_path_id))
})?;
if !path.is_ingest_destination {
return Err(DomainError::Validation("Target path is not an ingest destination".to_string()));
return Err(DomainError::Validation(
"Target path is not an ingest destination".to_string(),
));
}
if let Some(quota) = self.quota_repo.find_by_owner(&cmd.uploader_id).await? {
let current = self.ledger_repo.sum_usage(&cmd.uploader_id, UsageType::StorageBytes, None).await?;
let result = domain::storage::services::check_quota(&quota, UsageType::StorageBytes, current, cmd.file_size);
let current = self
.ledger_repo
.sum_usage(&cmd.uploader_id, UsageType::StorageBytes, None)
.await?;
let result = domain::storage::services::check_quota(
&quota,
UsageType::StorageBytes,
current,
cmd.file_size,
);
if !result.allowed {
return Err(DomainError::QuotaExceeded(format!(
"Storage quota exceeded: {} / {} bytes", current + cmd.file_size, result.limit
"Storage quota exceeded: {} / {} bytes",
current + cmd.file_size,
result.limit
)));
}
}
@@ -75,10 +105,16 @@ impl IngestAssetHandler {
);
let storage_path = format!("{}/{}", path.relative_path, cmd.filename);
self.file_storage.store_file(&storage_path, cmd.data).await?;
self.file_storage
.store_file(&storage_path, cmd.data)
.await?;
let mime_type = mime_type_from_filename(&cmd.filename);
let asset_type = if mime_type.starts_with("video") { AssetType::Video } else { AssetType::Image };
let asset_type = if mime_type.starts_with("video") {
AssetType::Video
} else {
AssetType::Image
};
let asset = Asset::new(
SourceReference {
@@ -105,11 +141,13 @@ impl IngestAssetHandler {
);
self.ledger_repo.record(&entry).await?;
self.event_pub.publish(DomainEvent::AssetIngested {
asset_id: asset.asset_id,
owner_user_id: cmd.uploader_id,
timestamp: DateTimeStamp::now(),
}).await?;
self.event_pub
.publish(DomainEvent::AssetIngested {
asset_id: asset.asset_id,
owner_user_id: cmd.uploader_id,
timestamp: DateTimeStamp::now(),
})
.await?;
Ok((asset, session))
}