allow uploading private demos

This commit is contained in:
Robin Appelman 2025-05-03 16:20:26 +02:00
commit ef7e590be0
5 changed files with 502 additions and 343 deletions

798
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -13,25 +13,25 @@ categories = ["api-bindings"]
rust-version = "1.81.0" rust-version = "1.81.0"
[dependencies] [dependencies]
serde = { version = "1.0.216", features = ["derive"] } serde = { version = "1.0.219", features = ["derive"] }
time = { version = "0.3.37", features = ["serde"] } time = { version = "0.3.41", features = ["serde"] }
reqwest = { version = "0.12.9", default-features = false, features = [ reqwest = { version = "0.12.15", default-features = false, features = [
"json", "json",
"multipart", "multipart",
"stream", "stream",
] } ] }
thiserror = "2.0.9" thiserror = "2.0.12"
hex = "0.4.3" hex = "0.4.3"
steamid-ng = "1.0.0" steamid-ng = "1.0.0"
bytes = "1.9.0" bytes = "1.10.1"
futures-util = "0.3.31" futures-util = "0.3.31"
tracing = "0.1.41" tracing = "0.1.41"
tinyvec = { version = "1.8.1", features = ["alloc"] } tinyvec = { version = "1.9.0", features = ["alloc"] }
md5 = "0.7.0" md5 = "0.7.0"
[dev-dependencies] [dev-dependencies]
tokio = { version = "1.42.0", features = ["macros"] } tokio = { version = "1.44.2", features = ["macros"] }
sqlx = { version = "0.8.2", features = ["postgres", "runtime-tokio-rustls"] } sqlx = { version = "0.8.5", features = ["postgres", "runtime-tokio-rustls"] }
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] } tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
[features] [features]

View file

@ -15,8 +15,8 @@ in
src = fetchFromGitHub { src = fetchFromGitHub {
owner = "demostf"; owner = "demostf";
repo = "api"; repo = "api";
rev = "1a8380360b993226ae1c6fcc226011e03a6c1467"; rev = "9595b7f6f520fffb6e31c31c08d897b5b7593574";
hash = "sha256-JcBRU1N44tt0QDLnj6z9MCT3V2s2dkf+JbpWb1rmXnY="; hash = "sha256-HncThFvIQ02QD8jpdsj70kvE+OlVO/loKM3hCVgJ2tk=";
}; };
vendorHash = "sha256-EYWCR2aJAoyWvEX+SML4Fb3F3KGcUtwCgqhAGT6ZjZ4="; vendorHash = "sha256-EYWCR2aJAoyWvEX+SML4Fb3F3KGcUtwCgqhAGT6ZjZ4=";

View file

@ -108,7 +108,7 @@
testBinary = lib.getExe pkgs.test-runner; testBinary = lib.getExe pkgs.test-runner;
initSql = pkgs.fetchurl { initSql = pkgs.fetchurl {
url = "https://github.com/demostf/db/raw/refs/heads/master/schema.sql"; url = "https://github.com/demostf/db/raw/refs/heads/master/schema.sql";
hash = "sha256-AwXN9mh9CRk6HWdvyUR+YdBkpmExNIDOIeDMz6XqjEQ="; hash = "sha256-tdMYDxlvpuQRxHglX46sCldxzsh1cDxkch2lGWnFH8E=";
}; };
in '' in ''
machine.succeed("mkdir /demos && chmod 0777 /demos"); machine.succeed("mkdir /demos && chmod 0777 /demos");

View file

@ -377,12 +377,39 @@ impl ApiClient {
red: String, red: String,
blue: String, blue: String,
key: String, key: String,
) -> Result<u32, Error> {
self.upload_maybe_private_demo(file_name, body, red, blue, key, false)
.await
}
#[instrument(skip(body))]
pub async fn upload_private_demo(
&self,
file_name: String,
body: Vec<u8>,
red: String,
blue: String,
key: String,
) -> Result<u32, Error> {
self.upload_maybe_private_demo(file_name, body, red, blue, key, true)
.await
}
async fn upload_maybe_private_demo(
&self,
file_name: String,
body: Vec<u8>,
red: String,
blue: String,
key: String,
private: bool,
) -> Result<u32, Error> { ) -> Result<u32, Error> {
let form = multipart::Form::new() let form = multipart::Form::new()
.text("red", red) .text("red", red)
.text("blue", blue) .text("blue", blue)
.text("name", file_name) .text("name", file_name)
.text("key", key); .text("key", key)
.text("private", if private { "1" } else { "0" });
let file = multipart::Part::bytes(body) let file = multipart::Part::bytes(body)
.file_name("demo.dem") .file_name("demo.dem")