diff --git a/src/auth.rs b/src/auth.rs index 728c1ea..6ce0ecf 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -26,7 +26,7 @@ pub struct Claims { pub struct AuthUser( pub String, // user_id #[allow(dead_code)] // email is not used in this simplified version - pub String, // email + pub String, // email ); impl FromRequestParts> for Claims { diff --git a/src/handlers/attachments.rs b/src/handlers/attachments.rs index 395306d..303b5f8 100644 --- a/src/handlers/attachments.rs +++ b/src/handlers/attachments.rs @@ -26,7 +26,7 @@ use crate::{ const ATTACHMENTS_BUCKET: &str = "ATTACHMENTS_BUCKET"; const SIZE_LEEWAY_BYTES: i64 = 1024 * 1024; // 1 MiB -const DEFAULT_ATTACHMENT_DOWNLOAD_TTL_SECS: i64 = 300; // 5 minutes +const DEFAULT_ATTACHMENT_TTL_SECS: i64 = 300; // 5 minutes #[derive(Deserialize)] #[serde(rename_all = "camelCase")] @@ -600,7 +600,7 @@ async fn fetch_attachment(db: &D1Database, attachment_id: &str) -> Result Result>, AppError> { if cipher_ids.is_empty() { return Ok(HashMap::new()); @@ -766,22 +766,22 @@ fn jwt_secret(env: &Env) -> Result { } fn download_ttl_secs(env: &Env) -> Result { - match env.var("ATTACHMENT_DOWNLOAD_TTL_SECS") { + match env.var("ATTACHMENT_TTL_SECS") { Ok(v) => { let raw = v.to_string(); let ttl = raw.parse::().map_err(|err| { - log::error!("Invalid ATTACHMENT_DOWNLOAD_TTL_SECS '{}': {}", raw, err); + log::error!("Invalid ATTACHMENT_TTL_SECS '{}': {}", raw, err); AppError::Internal })?; if ttl <= 0 { - log::error!("ATTACHMENT_DOWNLOAD_TTL_SECS '{}' must be positive", raw); + log::error!("ATTACHMENT_TTL_SECS '{}' must be positive", raw); return Err(AppError::Internal); } Ok(ttl) } - Err(_) => Ok(DEFAULT_ATTACHMENT_DOWNLOAD_TTL_SECS), + Err(_) => Ok(DEFAULT_ATTACHMENT_TTL_SECS), } } diff --git a/src/handlers/ciphers.rs b/src/handlers/ciphers.rs index 2124f93..7a089e8 100644 --- a/src/handlers/ciphers.rs +++ b/src/handlers/ciphers.rs @@ -96,8 +96,7 @@ pub async fn create_cipher( .run() .await?; - attachments::hydrate_cipher_attachments(&db, env.as_ref(), &mut cipher) - .await?; + attachments::hydrate_cipher_attachments(&db, env.as_ref(), &mut cipher).await?; db::touch_user_updated_at(&db, &claims.sub).await?; Ok(Json(cipher)) @@ -209,8 +208,7 @@ pub async fn update_cipher( .run() .await?; - attachments::hydrate_cipher_attachments(&db, env.as_ref(), &mut cipher) - .await?; + attachments::hydrate_cipher_attachments(&db, env.as_ref(), &mut cipher).await?; db::touch_user_updated_at(&db, &claims.sub).await?; Ok(Json(cipher)) @@ -257,8 +255,7 @@ pub async fn get_cipher( let cipher = fetch_cipher_for_user(&db, &id, &claims.sub).await?; let mut cipher: Cipher = cipher.into(); - attachments::hydrate_cipher_attachments(&db, env.as_ref(), &mut cipher) - .await?; + attachments::hydrate_cipher_attachments(&db, env.as_ref(), &mut cipher).await?; Ok(Json(cipher)) } @@ -322,8 +319,7 @@ pub async fn update_cipher_partial( let cipher = fetch_cipher_for_user(&db, &id, user_id).await?; let mut cipher: Cipher = cipher.into(); - attachments::hydrate_cipher_attachments(&db, env.as_ref(), &mut cipher) - .await?; + attachments::hydrate_cipher_attachments(&db, env.as_ref(), &mut cipher).await?; Ok(Json(cipher)) } @@ -406,7 +402,9 @@ pub async fn hard_delete_cipher( if attachments::attachments_enabled(env.as_ref()) { let bucket = attachments::require_bucket(env.as_ref())?; - let keys = attachments::list_attachment_keys_for_cipher_ids(&db, &[id.clone()], Some(&claims.sub)).await?; + let keys = + attachments::list_attachment_keys_for_cipher_ids(&db, &[id.clone()], Some(&claims.sub)) + .await?; attachments::delete_r2_objects(&bucket, &keys).await?; } @@ -500,8 +498,7 @@ pub async fn restore_cipher( .ok_or(AppError::NotFound("Cipher not found".to_string()))?; let mut cipher: Cipher = cipher_db.into(); - attachments::hydrate_cipher_attachments(&db, env.as_ref(), &mut cipher) - .await?; + attachments::hydrate_cipher_attachments(&db, env.as_ref(), &mut cipher).await?; db::touch_user_updated_at(&db, &claims.sub).await?; @@ -638,8 +635,7 @@ pub async fn create_cipher_simple( .run() .await?; - attachments::hydrate_cipher_attachments(&db, env.as_ref(), &mut cipher) - .await?; + attachments::hydrate_cipher_attachments(&db, env.as_ref(), &mut cipher).await?; db::touch_user_updated_at(&db, &claims.sub).await?; Ok(Json(cipher)) diff --git a/src/handlers/purge.rs b/src/handlers/purge.rs index 320fc4f..ce5b126 100644 --- a/src/handlers/purge.rs +++ b/src/handlers/purge.rs @@ -4,8 +4,8 @@ //! soft-deleted (marked with deleted_at) for longer than the configured //! retention period. -use chrono::{Duration, Utc}; use crate::handlers::attachments; +use chrono::{Duration, Utc}; use std::collections::HashSet; use worker::{query, D1Database, Env}; diff --git a/src/handlers/sync.rs b/src/handlers/sync.rs index 4ac9d9f..60c5607 100644 --- a/src/handlers/sync.rs +++ b/src/handlers/sync.rs @@ -65,8 +65,7 @@ pub async fn get_sync_data( .collect::>(); let mut ciphers = ciphers; - attachments::hydrate_ciphers_attachments(&db, env.as_ref(), &mut ciphers) - .await?; + attachments::hydrate_ciphers_attachments(&db, env.as_ref(), &mut ciphers).await?; let profile = Profile::from_user(user)?; diff --git a/src/lib.rs b/src/lib.rs index b8a67b7..b9e89de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,4 +77,3 @@ pub async fn scheduled(_event: ScheduledEvent, env: Env, _ctx: ScheduleContext) } } } -