From 7f7a471ca4df749ce35be285bc36e60f638d8d0d Mon Sep 17 00:00:00 2001 From: Timo Ley Date: Thu, 23 Dec 2021 11:32:48 +0100 Subject: [PATCH] Fix URL encoding for CDN --- Cargo.toml | 7 ++++--- src/cdn/mod.rs | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 97d3af9..8860a2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" [dependencies] tokio = { version = "1.0", features = ["full"] } -axum = { version = "0.2.8", features = ["headers"] } +axum = { version = "0.2.8", features = ["headers", "multipart"] } tower = { version = "0.4", features = ["util", "timeout"] } tower-http = { version = "0.1", features = ["add-extension", "trace", "fs", "set-header"] } serde = { version = "1.0", features = ["derive"] } @@ -17,8 +17,9 @@ sqlx = { version = "0.3", features = [ "mysql" ] } rand = "0.8.0" structopt = "0.3.22" toml = "0.5.8" -reqwest = { version = "0.11", features = ["stream", "multipart"] } +reqwest = { version = "0.11", features = ["stream", "multipart", "json"] } new_mime_guess = "3.0.2" headers = "0.3.5" url = {version = "2.2.2", features = ["serde"]} -askama = "0.10" \ No newline at end of file +askama = "0.10" +urlencoding = "2.1.0" \ No newline at end of file diff --git a/src/cdn/mod.rs b/src/cdn/mod.rs index 03f48df..ade1a2f 100644 --- a/src/cdn/mod.rs +++ b/src/cdn/mod.rs @@ -20,6 +20,7 @@ pub fn routes() -> Router { } async fn image(Path((user, filename)): Path<(String, String)>, Extension(db_pool): Extension, Extension(vars): Extension) -> Result { + let filename = urlencoding::decode(&filename).map_err(|err| StatusCode::INTERNAL_SERVER_ERROR)?.into_owned(); let q = sql::get_cid(user, filename.clone(), &db_pool).await; match q { Ok(cid) => {