refactor: move business logic out of presentation — ReadAssetFile, checksum, auth checks, MetadataValue conversions
This commit is contained in:
@@ -15,7 +15,6 @@ use axum::{
|
||||
response::Response,
|
||||
};
|
||||
use domain::value_objects::{MetadataValue, StructuredData, SystemId};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
pub struct TimelineParams {
|
||||
@@ -80,17 +79,12 @@ pub async fn ingest(
|
||||
))
|
||||
})?;
|
||||
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(&data);
|
||||
let checksum = format!("{:x}", hasher.finalize());
|
||||
|
||||
let file_size = data.len() as u64;
|
||||
|
||||
let cmd = IngestAssetCommand {
|
||||
uploader_id: claims.user_id,
|
||||
client_device_id,
|
||||
filename: fname,
|
||||
checksum,
|
||||
target_path_id: SystemId::from_uuid(path_id),
|
||||
file_size,
|
||||
data,
|
||||
@@ -110,11 +104,12 @@ pub async fn ingest(
|
||||
|
||||
pub async fn get_asset(
|
||||
State(state): State<AppState>,
|
||||
_claims: JwtClaims,
|
||||
claims: JwtClaims,
|
||||
Path((asset_id,)): Path<(uuid::Uuid,)>,
|
||||
) -> Result<Json<AssetResponse>, AppError> {
|
||||
let query = GetAssetQuery {
|
||||
asset_id: SystemId::from_uuid(asset_id),
|
||||
user_id: claims.user_id,
|
||||
};
|
||||
let (asset, metadata) = state.get_asset_handler.execute(query).await?;
|
||||
Ok(Json(AssetResponse::from_domain(&asset, &metadata)))
|
||||
|
||||
Reference in New Issue
Block a user