diff --git a/src/analytics/plausible.rs b/src/analytics/plausible.rs index 3d68379..c6e0c65 100644 --- a/src/analytics/plausible.rs +++ b/src/analytics/plausible.rs @@ -69,18 +69,9 @@ impl Analytics for PlausibleAnalytics { None => return Ok(()), // ignore request }, url: req.uri().to_string(), - referrer: match req.headers().get_one("Referer") { - Some(s) => Some(s.to_string()), - None => None, - }, - user_agent: match req.headers().get_one("User-Agent") { - Some(s) => Some(s.to_string()), - None => None, - }, - xff: match req.headers().get_one("X-Forwarded-For") { - Some(s) => Some(s.to_string()), - None => None, - }, + referrer: req.headers().get_one("Referer").map(|s| s.to_string()), + user_agent: req.headers().get_one("User-Agent").map(|s| s.to_string()), + xff: req.headers().get_one("X-Forwarded-For").map(|s| s.to_string()), })?) } } diff --git a/src/db.rs b/src/db.rs index f5991ea..7538027 100644 --- a/src/db.rs +++ b/src/db.rs @@ -108,7 +108,7 @@ impl Database { .bind(file.width) .bind(file.height) .bind(&file.alt) - .bind(&file.created); + .bind(file.created); tx.execute(q).await?; let q2 = sqlx::query("insert ignore into user_uploads(file,user_id) values(?,?)") diff --git a/src/routes/blossom.rs b/src/routes/blossom.rs index 6240ca6..8a35beb 100644 --- a/src/routes/blossom.rs +++ b/src/routes/blossom.rs @@ -147,7 +147,7 @@ async fn list_files( Ok((files, _count)) => BlossomResponse::BlobDescriptorList(Json( files .iter() - .map(|f| BlobDescriptor::from_upload(&settings, f)) + .map(|f| BlobDescriptor::from_upload(settings, f)) .collect(), )), Err(e) => BlossomResponse::error(format!("Could not list files: {}", e)), @@ -174,13 +174,13 @@ async fn upload_head(auth: BlossomAuth, settings: &State) -> BlossomHe }; } - if let None = auth.x_sha_256 { + if auth.x_sha_256.is_none() { return BlossomHead { msg: Some("Missing x-sha-256 header"), }; } - if let None = auth.x_content_type { + if auth.x_content_type.is_none() { return BlossomHead { msg: Some("Missing x-content-type header"), }; @@ -313,7 +313,7 @@ async fn process_upload( BlossomResponse::error(format!("Error saving file (db): {}", e)) } else { BlossomResponse::BlobDescriptor(Json(BlobDescriptor::from_upload( - &settings, + settings, &blob.upload, ))) } diff --git a/src/routes/nip96.rs b/src/routes/nip96.rs index 84095bf..827b588 100644 --- a/src/routes/nip96.rs +++ b/src/routes/nip96.rs @@ -188,7 +188,7 @@ async fn upload( // account for upload speeds as slow as 1MB/s (8 Mbps) let mbs = form.size / 1.megabytes().as_u64(); - let max_time = 60.max(mbs) as u64; + let max_time = 60.max(mbs); if auth.event.created_at < Timestamp::now().sub(Duration::from_secs(max_time)) { return Nip96Response::error("Auth event timestamp out of range"); } @@ -208,10 +208,7 @@ async fn upload( Some(c) => c.to_string(), None => "".to_string(), }; - blob.upload.alt = match &form.alt { - Some(s) => Some(s.to_string()), - None => None, - }; + blob.upload.alt = form.alt.as_ref().map(|s| s.to_string()); let pubkey_vec = auth.event.pubkey.to_bytes().to_vec(); if let Some(wh) = webhook.as_ref() { match wh.store_file(&pubkey_vec, blob.clone()) {