add demo downloading

This commit is contained in:
Robin Appelman 2022-04-30 19:52:38 +02:00
commit bdd8ec590a
2 changed files with 18 additions and 1 deletions

View file

@ -1,3 +1,5 @@
use bytes::Bytes;
use futures_util::{Stream, StreamExt};
use reqwest::{multipart, Client, IntoUrl, StatusCode, Url};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::borrow::Cow;
@ -64,6 +66,19 @@ impl Demo {
Ok(Cow::Owned(demo.players))
}
}
pub async fn download(
&self,
client: &ApiClient,
) -> Result<impl Stream<Item = Result<Bytes, Error>>, Error> {
Ok(client
.client
.get(&self.url)
.send()
.await?
.bytes_stream()
.map(|chunk| Ok(chunk?)))
}
}
/// Reference to a user, either contains the full user information or only the user id