server/upload_path: Expose the final file size in the response

This commit is contained in:
Zhaofeng Li 2023-01-14 23:55:10 -07:00
parent 332ac5051c
commit 064a747bb4
2 changed files with 10 additions and 0 deletions

View file

@ -57,6 +57,10 @@ pub struct UploadPathNarInfo {
pub struct UploadPathResult { pub struct UploadPathResult {
#[serde_as(deserialize_as = "DefaultOnError")] #[serde_as(deserialize_as = "DefaultOnError")]
pub kind: UploadPathResultKind, pub kind: UploadPathResultKind,
/// The compressed size of the NAR, in bytes.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_size: Option<usize>,
} }
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]

View file

@ -188,11 +188,16 @@ async fn upload_path_dedup(
txn.commit().await.map_err(ServerError::database_error)?; txn.commit().await.map_err(ServerError::database_error)?;
let file_size = existing_nar.file_size
.map(|dbs| dbs.try_into().map_err(ServerError::database_error))
.transpose()?;
// Ensure it's not unlocked earlier // Ensure it's not unlocked earlier
drop(existing_nar); drop(existing_nar);
Ok(Json(UploadPathResult { Ok(Json(UploadPathResult {
kind: UploadPathResultKind::Deduplicated, kind: UploadPathResultKind::Deduplicated,
file_size,
})) }))
} }
@ -339,6 +344,7 @@ async fn upload_path_new(
Ok(Json(UploadPathResult { Ok(Json(UploadPathResult {
kind: UploadPathResultKind::Uploaded, kind: UploadPathResultKind::Uploaded,
file_size: Some(*file_size),
})) }))
} }