style: apply rustfmt formatting to fix CI

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
zjean
2026-03-05 21:28:51 +01:00
parent aa666f5bbb
commit 190527edfb
29 changed files with 242 additions and 165 deletions
@@ -325,9 +325,7 @@ impl FileReadPort for FileBlobReadRepository {
.fetch_all(self.pool.as_ref())
.await
}
.map_err(|e| {
DomainError::internal_error("FileBlobRead", format!("list_for_owner: {e}"))
})?;
.map_err(|e| DomainError::internal_error("FileBlobRead", format!("list_for_owner: {e}")))?;
rows.into_iter()
.map(|(id, name, fid, fpath, size, mime, ca, ma, uid)| {
@@ -868,7 +868,9 @@ impl FolderRepository for FolderDbRepository {
user_id: &str,
) -> Result<Vec<Folder>, DomainError> {
let (where_extra, name_pattern) = match name_contains {
Some(name) if name.len() >= 3 => (" AND fo.name ILIKE $3", Some(super::like_escape(name))),
Some(name) if name.len() >= 3 => {
(" AND fo.name ILIKE $3", Some(super::like_escape(name)))
}
_ => ("", None),
};
+4 -1
View File
@@ -50,6 +50,9 @@ pub use user_pg_repository::UserPgRepository;
/// `%` is a wildcard in LIKE patterns.
#[inline]
pub fn like_escape(raw: &str) -> String {
let escaped = raw.replace('\\', "\\\\").replace('%', "\\%").replace('_', "\\_");
let escaped = raw
.replace('\\', "\\\\")
.replace('%', "\\%")
.replace('_', "\\_");
format!("%{escaped}%")
}
@@ -102,10 +102,7 @@ impl SettingsRepository for SettingsPgRepository {
///
/// Only the first caller that inserts the row gets `rows_affected == 1`;
/// concurrent callers see 0 rows affected and receive `false`.
async fn try_claim_initialization(
&self,
admin_user_id: &str,
) -> Result<bool, DomainError> {
async fn try_claim_initialization(&self, admin_user_id: &str) -> Result<bool, DomainError> {
let result = sqlx::query(
"INSERT INTO auth.admin_settings (key, value, category, is_secret, updated_by, updated_at)
VALUES ('system_initialized', 'true', 'system', false, $1, NOW())
@@ -202,10 +202,7 @@ impl ShareStoragePort for SharePgRepository {
.await
.map_err(|e| {
tracing::error!("Database error deleting share for user: {}", e);
DomainError::internal_error(
"Share",
format!("Failed to delete share: {e}"),
)
DomainError::internal_error("Share", format!("Failed to delete share: {e}"))
})?;
if result.rows_affected() == 0 {
@@ -242,10 +239,7 @@ impl ShareStoragePort for SharePgRepository {
.await
.map_err(|e| {
tracing::error!("Database error finding shares by item for user: {}", e);
DomainError::internal_error(
"Share",
format!("Failed to find shares by item: {e}"),
)
DomainError::internal_error("Share", format!("Failed to find shares by item: {e}"))
})?;
rows.iter().map(Self::row_to_entity).collect()
@@ -371,11 +371,7 @@ impl ChunkedUploadService {
/// Verify that the given session belongs to the given user.
/// Returns 404 (not 403) to avoid revealing the existence of other users' sessions.
fn verify_session_owner(
&self,
upload_id: &str,
user_id: &str,
) -> Result<(), String> {
fn verify_session_owner(&self, upload_id: &str, user_id: &str) -> Result<(), String> {
let session = self
.sessions
.get(upload_id)
@@ -592,7 +588,11 @@ impl ChunkedUploadService {
}
/// Get upload status
async fn get_status_inner(&self, upload_id: &str, user_id: &str) -> Result<UploadStatusResponseDto, String> {
async fn get_status_inner(
&self,
upload_id: &str,
user_id: &str,
) -> Result<UploadStatusResponseDto, String> {
self.verify_session_owner(upload_id, user_id)?;
let session = self
@@ -808,9 +808,16 @@ impl ChunkedUploadPort for ChunkedUploadService {
total_size: u64,
chunk_size: Option<usize>,
) -> Result<CreateUploadResponseDto, DomainError> {
self.create_session_inner(user_id.to_owned(), filename, folder_id, content_type, total_size, chunk_size)
.await
.map_err(|e| DomainError::new(ErrorKind::InternalError, "ChunkedUpload", e))
self.create_session_inner(
user_id.to_owned(),
filename,
folder_id,
content_type,
total_size,
chunk_size,
)
.await
.map_err(|e| DomainError::new(ErrorKind::InternalError, "ChunkedUpload", e))
}
async fn upload_chunk(
@@ -826,7 +833,11 @@ impl ChunkedUploadPort for ChunkedUploadService {
.map_err(|e| DomainError::new(ErrorKind::InternalError, "ChunkedUpload", e))
}
async fn get_status(&self, upload_id: &str, user_id: &str) -> Result<UploadStatusResponseDto, DomainError> {
async fn get_status(
&self,
upload_id: &str,
user_id: &str,
) -> Result<UploadStatusResponseDto, DomainError> {
self.get_status_inner(upload_id, user_id)
.await
.map_err(|e| DomainError::new(ErrorKind::NotFound, "ChunkedUpload", e))
@@ -1097,14 +1108,19 @@ mod tests {
assert_eq!(r1.bytes_received, 1024);
// 3. Status check
let status = service.get_status_inner(&id, "test-user").await.expect("status");
let status = service
.get_status_inner(&id, "test-user")
.await
.expect("status");
assert!(status.is_complete);
assert_eq!(status.completed_chunks, 2);
assert!(status.pending_chunks.is_empty());
// 4. Complete (assemble)
let (path, filename, _folder, _ct, size, hash) =
service.complete_upload_inner(&id, "test-user").await.expect("complete");
let (path, filename, _folder, _ct, size, hash) = service
.complete_upload_inner(&id, "test-user")
.await
.expect("complete");
assert_eq!(filename, "test.txt");
assert_eq!(size, 1024);
assert!(!hash.is_empty());
@@ -1116,7 +1132,10 @@ mod tests {
assert_eq!(&content[512..], &[b'B'; 512]);
// 6. Finalize
service.finalize_upload_inner(&id, "test-user").await.expect("finalize");
service
.finalize_upload_inner(&id, "test-user")
.await
.expect("finalize");
assert_eq!(service.active_sessions().await, 0);
let _ = fs::remove_dir_all(&base).await;
@@ -1,8 +1,8 @@
use serde_json::Value;
use std::collections::HashMap;
use std::path::PathBuf;
use tokio::sync::RwLock;
use tokio::fs;
use tokio::sync::RwLock;
use crate::domain::services::i18n_service::{I18nError, I18nResult, I18nService, Locale};
+1 -1
View File
@@ -6,8 +6,8 @@
//! Compatible with Authentik, Keycloak, and any standard OIDC provider.
use serde::Deserialize;
use tokio::sync::RwLock;
use std::time::{Duration, Instant};
use tokio::sync::RwLock;
use crate::application::ports::auth_ports::{OidcIdClaims, OidcServicePort, OidcTokenSet};
use crate::common::config::OidcConfig;
@@ -119,10 +119,10 @@ impl PathResolverService {
LIMIT 1
"#,
)
.bind(path) // $1
.bind(filename) // $2
.bind(&folder_path) // $3
.bind(user_id) // $4
.bind(path) // $1
.bind(filename) // $2
.bind(&folder_path) // $3
.bind(user_id) // $4
.fetch_optional(self.pool.as_ref())
.await
.map_err(|e| DomainError::internal_error("PathResolver", format!("resolve_for_user: {e}")))?
@@ -215,7 +215,9 @@ impl PathResolverService {
.bind(user_id)
.fetch_one(self.pool.as_ref())
.await
.map_err(|e| DomainError::internal_error("PathResolver", format!("exists_for_user: {e}")))?;
.map_err(|e| {
DomainError::internal_error("PathResolver", format!("exists_for_user: {e}"))
})?;
Ok(exists)
}
@@ -8,11 +8,8 @@ fn tiny_png() -> Vec<u8> {
let mut img = image::RgbaImage::new(1, 1);
img.put_pixel(0, 0, image::Rgba([255, 0, 0, 255]));
let mut buf = Vec::new();
img.write_to(
&mut std::io::Cursor::new(&mut buf),
image::ImageFormat::Png,
)
.expect("encode test PNG");
img.write_to(&mut std::io::Cursor::new(&mut buf), image::ImageFormat::Png)
.expect("encode test PNG");
buf
}