mirror of
https://github.com/dani-garcia/vaultwarden.wiki.git
synced 2026-07-29 21:25:06 +03:00
Trusted proxies, unauthenticated rate limits and various fixes
This commit is contained in:
@@ -231,6 +231,37 @@ impl Send {
|
||||
}
|
||||
}
|
||||
|
||||
/// Registers an access, incrementing `access_count` only while below `max_access_count`.
|
||||
/// Returns false when the limit was already reached. The check and the increment are a single
|
||||
/// statement, otherwise concurrent accesses can both pass the check and exceed the limit.
|
||||
pub async fn register_access(&mut self, conn: &DbConn) -> Result<bool, crate::Error> {
|
||||
self.update_users_revision(conn).await;
|
||||
|
||||
let revision_date = Utc::now().naive_utc();
|
||||
let uuid = self.uuid.clone();
|
||||
let updated = conn
|
||||
.run(move |conn| {
|
||||
diesel::update(sends::table)
|
||||
.filter(sends::uuid.eq(uuid))
|
||||
.filter(
|
||||
sends::max_access_count
|
||||
.is_null()
|
||||
.or(sends::access_count.nullable().lt(sends::max_access_count)),
|
||||
)
|
||||
.set((sends::access_count.eq(sends::access_count + 1), sends::revision_date.eq(revision_date)))
|
||||
.execute(conn)
|
||||
})
|
||||
.await?;
|
||||
|
||||
if updated == 0 {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
self.access_count += 1;
|
||||
self.revision_date = revision_date;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
pub async fn delete(&self, conn: &DbConn) -> EmptyResult {
|
||||
self.update_users_revision(conn).await;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user