Resultify Message::get_filebytes()

This commit is contained in:
link2xt
2023-01-06 19:22:57 +00:00
parent 087b4289e5
commit 58ba107d01
8 changed files with 18 additions and 16 deletions

View File

@@ -494,11 +494,12 @@ impl Message {
.map(|name| name.to_string_lossy().to_string())
}
pub async fn get_filebytes(&self, context: &Context) -> u64 {
match self.param.get_path(Param::File, context) {
Ok(Some(path)) => get_filebytes(context, &path).await,
Ok(None) => 0,
Err(_) => 0,
/// Returns the size of the file in bytes, if applicable.
pub async fn get_filebytes(&self, context: &Context) -> Result<Option<u64>> {
if let Some(path) = self.param.get_path(Param::File, context)? {
Ok(Some(get_filebytes(context, &path).await?))
} else {
Ok(None)
}
}
@@ -1102,7 +1103,7 @@ pub async fn get_msg_info(context: &Context, msg_id: MsgId) -> Result<String> {
}
if let Some(path) = msg.get_file(context) {
let bytes = get_filebytes(context, &path).await;
let bytes = get_filebytes(context, &path).await?;
ret += &format!("\nFile: {}, {}, bytes\n", path.display(), bytes);
}