mirror of
https://codeberg.org/demostf/api-client.git
synced 2026-06-03 16:44:09 +02:00
add demo downloading
This commit is contained in:
parent
a5e906fac8
commit
bdd8ec590a
2 changed files with 18 additions and 1 deletions
|
|
@ -12,10 +12,12 @@ exclude = [ "tests/data/gully.dem" ]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
time = { version = "0.3", features = ["serde"] }
|
time = { version = "0.3", features = ["serde"] }
|
||||||
reqwest = { version = "0.11", default-features = false, features = ["json", "multipart"] }
|
reqwest = { version = "0.11", default-features = false, features = ["json", "multipart", "stream"] }
|
||||||
thiserror = "1"
|
thiserror = "1"
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
steamid-ng = "1"
|
steamid-ng = "1"
|
||||||
|
bytes = "1.1.0"
|
||||||
|
futures-util = "0.3.21"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio = { version = "1", features = ["macros"] }
|
tokio = { version = "1", features = ["macros"] }
|
||||||
|
|
|
||||||
15
src/lib.rs
15
src/lib.rs
|
|
@ -1,3 +1,5 @@
|
||||||
|
use bytes::Bytes;
|
||||||
|
use futures_util::{Stream, StreamExt};
|
||||||
use reqwest::{multipart, Client, IntoUrl, StatusCode, Url};
|
use reqwest::{multipart, Client, IntoUrl, StatusCode, Url};
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
@ -64,6 +66,19 @@ impl Demo {
|
||||||
Ok(Cow::Owned(demo.players))
|
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
|
/// Reference to a user, either contains the full user information or only the user id
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue