chore: format code
This commit is contained in:
parent
eee4cc90ef
commit
d72ef417b7
6 changed files with 18 additions and 24 deletions
|
|
@ -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<Arc<Env>> for Claims {
|
||||
|
|
|
|||
|
|
@ -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<Attach
|
|||
|
||||
async fn load_attachment_map(
|
||||
db: &D1Database,
|
||||
cipher_ids: &[String]
|
||||
cipher_ids: &[String],
|
||||
) -> Result<HashMap<String, Vec<AttachmentResponse>>, AppError> {
|
||||
if cipher_ids.is_empty() {
|
||||
return Ok(HashMap::new());
|
||||
|
|
@ -766,22 +766,22 @@ fn jwt_secret(env: &Env) -> Result<String, AppError> {
|
|||
}
|
||||
|
||||
fn download_ttl_secs(env: &Env) -> Result<i64, AppError> {
|
||||
match env.var("ATTACHMENT_DOWNLOAD_TTL_SECS") {
|
||||
match env.var("ATTACHMENT_TTL_SECS") {
|
||||
Ok(v) => {
|
||||
let raw = v.to_string();
|
||||
let ttl = raw.parse::<i64>().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),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
||||
|
|
|
|||
|
|
@ -65,8 +65,7 @@ pub async fn get_sync_data(
|
|||
.collect::<Vec<Cipher>>();
|
||||
|
||||
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)?;
|
||||
|
||||
|
|
|
|||
|
|
@ -77,4 +77,3 @@ pub async fn scheduled(_event: ScheduledEvent, env: Env, _ctx: ScheduleContext)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue