diff --git a/src/client.rs b/src/client.rs index 1b68774..ca3b5ab 100644 --- a/src/client.rs +++ b/src/client.rs @@ -90,33 +90,34 @@ impl MatrixClient { match $msg { $( MessageType::$variant(file) => { - Ok(Some(Box::pin( - async move { - let src = match &file.source { - MediaSource::Plain(s) => s, - MediaSource::Encrypted(e) => &e.url, - }; - let filename = file.filename.as_deref().map(|s| s.to_string()).unwrap_or(file.body.clone()); - let url = mxc_url_to_https(src.as_str(), self.client.homeserver().as_str()); - let resp = client.get(&url).send().await?; - let body = resp.bytes_stream(); - Ok(FileStream { - filename, - url, - stream: match &file.source { - MediaSource::Plain(_) => { - Box::pin(body.map_err(DumpError::from)) as Pin> + Send>> + Ok(Some(Box::pin( + async move { + let src = match &file.source { + MediaSource::Plain(s) => s, + MediaSource::Encrypted(e) => &e.url, + }; + let filename = file.filename.as_deref().map(|s| s.to_string()).unwrap_or(file.body.clone()); + let url = mxc_url_to_https(src.as_str(), self.client.homeserver().as_str()); + let resp = client.get(&url).send().await?; + let body = resp.bytes_stream(); + Ok(FileStream { + filename, + url, + stream: match &file.source { + MediaSource::Plain(_) => { + Box::pin(body.map_err(DumpError::from)) + } + MediaSource::Encrypted(e) => Box::pin(decrypt_file(e.as_ref(), body).await?.map_ok(|v| Bytes::from(v)).map_err( + |e| match e { + ErrOrWrongHash::Err(e) => e.into(), + ErrOrWrongHash::WrongHash => DumpError::HashMismatch, + }, + )) + }}) } - MediaSource::Encrypted(e) => Box::pin(decrypt_file(e.as_ref(), body).await?.map_ok(|v| Bytes::from(v)).map_err( - |e| match e { - ErrOrWrongHash::Err(e) => e.into(), - ErrOrWrongHash::WrongHash => DumpError::HashMismatch, - }, - )) as Pin> + Send>>, - } - }) - })))} - )* + ))) + } + )* _ => Ok(None), } };