Skip to content

Commit 4763822

Browse files
authored
Merge pull request #188 from zjean/fix/ci-clippy-fmt
fix: resolve clippy and rustfmt CI failures
2 parents cf9fe82 + 18518be commit 4763822

34 files changed

+370
-336
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.rs

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn process_release(manifest_dir: &Path, static_dir: &Path, out_dir: &Path) {
109109
fs::write(dist_dir.join("css").join(&css_name), &css_bundle).expect("write css bundle");
110110

111111
// ── 4. Minify ALL individual CSS in static-dist/ ─────────────────────────
112-
minify_tree_css(&dist_dir.join("css"), &css_name);
112+
minify_tree_css(&dist_dir.join("css"));
113113

114114
// ── 5. Build JS bundle for index.html ────────────────────────────────────
115115
let index_html = fs::read_to_string(static_dir.join("index.html")).expect("read index.html");
@@ -120,11 +120,11 @@ fn process_release(manifest_dir: &Path, static_dir: &Path, out_dir: &Path) {
120120
fs::write(dist_dir.join("js").join(&js_name), &js_bundle).expect("write js bundle");
121121

122122
// ── 6. Minify ALL individual JS in static-dist/ ──────────────────────────
123-
minify_tree_js(&dist_dir.join("js"), &js_name);
123+
minify_tree_js(&dist_dir.join("js"));
124124

125125
// ── 7. Inline theme-init.js & rewrite index.html ──────────────────────
126-
let theme_init = fs::read_to_string(static_dir.join("js/core/theme-init.js"))
127-
.unwrap_or_default();
126+
let theme_init =
127+
fs::read_to_string(static_dir.join("js/core/theme-init.js")).unwrap_or_default();
128128
let theme_init_min = js_minify_safe(&theme_init);
129129
let rewritten_index = rewrite_index_html(
130130
&index_html,
@@ -153,9 +153,7 @@ fn process_release(manifest_dir: &Path, static_dir: &Path, out_dir: &Path) {
153153
// index.html too (future use / embedded route)
154154
fs::write(out_dir.join("index.html"), &rewritten_index).expect("write out index.html");
155155

156-
eprintln!(
157-
"cargo:warning=OxiCloud static-dist built ✓ CSS: {css_name} JS: {js_name}"
158-
);
156+
eprintln!("cargo:warning=OxiCloud static-dist built ✓ CSS: {css_name} JS: {js_name}");
159157
}
160158

161159
// ═══════════════════════════════════════════════════════════════════════════════
@@ -206,8 +204,8 @@ fn css_minify_safe(source: &str) -> String {
206204
fn css_minify(source: &str) -> Result<String, String> {
207205
use lightningcss::stylesheet::{ParserOptions, PrinterOptions, StyleSheet};
208206

209-
let mut sheet = StyleSheet::parse(source, ParserOptions::default())
210-
.map_err(|e| format!("{e}"))?;
207+
let mut sheet =
208+
StyleSheet::parse(source, ParserOptions::default()).map_err(|e| format!("{e}"))?;
211209

212210
sheet
213211
.minify(Default::default())
@@ -224,12 +222,14 @@ fn css_minify(source: &str) -> Result<String, String> {
224222
}
225223

226224
/// Walk a directory and minify every `.css` in-place (skips generated bundles).
227-
fn minify_tree_css(dir: &Path, skip_prefix: &str) {
228-
let Ok(entries) = fs::read_dir(dir) else { return };
225+
fn minify_tree_css(dir: &Path) {
226+
let Ok(entries) = fs::read_dir(dir) else {
227+
return;
228+
};
229229
for entry in entries.flatten() {
230230
let p = entry.path();
231231
if p.is_dir() {
232-
minify_tree_css(&p, skip_prefix);
232+
minify_tree_css(&p);
233233
} else if p.extension().is_some_and(|e| e == "css") {
234234
let fname = p.file_name().unwrap().to_string_lossy();
235235
// Skip the generated bundle and already-processed main.css
@@ -336,12 +336,14 @@ fn js_minify(source: &str) -> Result<String, String> {
336336
}
337337

338338
/// Walk a directory and minify every `.js` in-place (skips generated bundles).
339-
fn minify_tree_js(dir: &Path, skip_prefix: &str) {
340-
let Ok(entries) = fs::read_dir(dir) else { return };
339+
fn minify_tree_js(dir: &Path) {
340+
let Ok(entries) = fs::read_dir(dir) else {
341+
return;
342+
};
341343
for entry in entries.flatten() {
342344
let p = entry.path();
343345
if p.is_dir() {
344-
minify_tree_js(&p, skip_prefix);
346+
minify_tree_js(&p);
345347
} else if p.extension().is_some_and(|e| e == "js") {
346348
let fname = p.file_name().unwrap().to_string_lossy();
347349
if fname.starts_with("app.") {
@@ -359,13 +361,15 @@ fn minify_tree_js(dir: &Path, skip_prefix: &str) {
359361
// ═══════════════════════════════════════════════════════════════════════════════
360362

361363
fn minify_tree_json(dir: &Path) {
362-
let Ok(entries) = fs::read_dir(dir) else { return };
364+
let Ok(entries) = fs::read_dir(dir) else {
365+
return;
366+
};
363367
for entry in entries.flatten() {
364368
let p = entry.path();
365-
if p.extension().is_some_and(|e| e == "json") {
366-
if let Ok(src) = fs::read_to_string(&p) {
367-
let _ = fs::write(&p, json_minify(&src));
368-
}
369+
if p.extension().is_some_and(|e| e == "json")
370+
&& let Ok(src) = fs::read_to_string(&p)
371+
{
372+
let _ = fs::write(&p, json_minify(&src));
369373
}
370374
}
371375
}
@@ -407,12 +411,7 @@ fn json_minify(source: &str) -> String {
407411
// ═══════════════════════════════════════════════════════════════════════════════
408412

409413
/// Rewrite index.html: single CSS bundle, inline theme-init, single JS bundle.
410-
fn rewrite_index_html(
411-
html: &str,
412-
css_path: &str,
413-
js_path: &str,
414-
inline_theme_js: &str,
415-
) -> String {
414+
fn rewrite_index_html(html: &str, css_path: &str, js_path: &str, inline_theme_js: &str) -> String {
416415
let mut out: Vec<String> = Vec::with_capacity(html.lines().count());
417416
let mut css_done = false;
418417
let mut defer_done = false;
@@ -423,29 +422,22 @@ fn rewrite_index_html(
423422
// ── Replace all stylesheet <link>s with single bundle ────────────────
424423
if t.starts_with("<link") && t.contains("stylesheet") && t.contains("href=\"/css/") {
425424
if !css_done {
426-
out.push(format!(
427-
" <link rel=\"stylesheet\" href=\"{css_path}\">"
428-
));
425+
out.push(format!(" <link rel=\"stylesheet\" href=\"{css_path}\">"));
429426
css_done = true;
430427
}
431428
continue;
432429
}
433430

434431
// ── Replace sync theme-init.js with inline <script> ─────────────────
435-
if t.starts_with("<script")
436-
&& !t.contains("defer")
437-
&& t.contains("theme-init")
438-
{
432+
if t.starts_with("<script") && !t.contains("defer") && t.contains("theme-init") {
439433
out.push(format!(" <script>{inline_theme_js}</script>"));
440434
continue;
441435
}
442436

443437
// ── Replace all defer <script>s with single bundle ──────────────────
444438
if t.starts_with("<script") && t.contains("defer") && t.contains("src=\"") {
445439
if !defer_done {
446-
out.push(format!(
447-
" <script defer src=\"{js_path}\"></script>"
448-
));
440+
out.push(format!(" <script defer src=\"{js_path}\"></script>"));
449441
defer_done = true;
450442
}
451443
continue;

src/application/ports/thumbnail_ports.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,7 @@ pub trait ThumbnailPort: Send + Sync + 'static {
8989
/// Returns `None` if no cached thumbnail exists on disk or in memory.
9090
/// Used for non-image file types (videos) where thumbnails are
9191
/// generated client-side and uploaded.
92-
async fn get_cached_thumbnail(
93-
&self,
94-
file_id: &str,
95-
size: ThumbnailSize,
96-
) -> Option<Bytes>;
92+
async fn get_cached_thumbnail(&self, file_id: &str, size: ThumbnailSize) -> Option<Bytes>;
9793

9894
/// Store an externally-generated thumbnail (e.g. client-side video frame).
9995
///

src/application/services/auth_application_service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ use crate::infrastructure::services::jwt_service::JwtTokenService;
1717
use crate::infrastructure::services::oidc_service::OidcService;
1818
use crate::infrastructure::services::password_hasher::Argon2PasswordHasher;
1919
use moka::sync::Cache;
20-
use uuid::Uuid;
2120
use std::path::PathBuf;
2221
use std::sync::Arc;
2322
use std::sync::RwLock;
2423
use std::time::Duration;
24+
use uuid::Uuid;
2525

2626
/// Result of a successful OIDC callback. The handler layer inspects this to
2727
/// decide whether to redirect to the regular frontend or complete a Nextcloud

src/application/services/batch_operations.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -448,11 +448,9 @@ impl BatchOperationService {
448448
},
449449
};
450450

451-
let uid = user_id;
452-
453451
let mut operation_stream = stream::iter(file_ids.into_iter().map(|file_id| {
454452
let trash = trash_service.clone();
455-
let uid = uid;
453+
let uid = user_id;
456454

457455
async move {
458456
let trash_result = trash.move_to_trash(&file_id, "file", uid).await;
@@ -513,11 +511,9 @@ impl BatchOperationService {
513511
},
514512
};
515513

516-
let uid = user_id;
517-
518514
let mut operation_stream = stream::iter(folder_ids.into_iter().map(|folder_id| {
519515
let trash = trash_service.clone();
520-
let uid = uid;
516+
let uid = user_id;
521517

522518
async move {
523519
let trash_result = trash.move_to_trash(&folder_id, "folder", uid).await;

src/application/services/contact_service.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use chrono::Utc;
2-
use uuid::Uuid;
32
use std::sync::Arc;
3+
use uuid::Uuid;
44

55
use crate::application::dtos::address_book_dto::{
66
AddressBookDto, CreateAddressBookDto, ShareAddressBookDto, UnshareAddressBookDto,
@@ -296,8 +296,11 @@ impl AddressBookUseCase for ContactService {
296296

297297
// Check if user has write access to the address book
298298
let address_book = self
299-
.check_address_book_write_access(&id, &Uuid::parse_str(&update.user_id)
300-
.map_err(|_| DomainError::validation_error("Invalid user ID format"))?)
299+
.check_address_book_write_access(
300+
&id,
301+
&Uuid::parse_str(&update.user_id)
302+
.map_err(|_| DomainError::validation_error("Invalid user ID format"))?,
303+
)
301304
.await?;
302305

303306
// Apply updates
@@ -526,9 +529,12 @@ impl ContactUseCase for ContactService {
526529
.map_err(|_| DomainError::validation_error("Invalid address book ID format"))?;
527530

528531
// Check if user has write access to the address book
529-
self.check_address_book_write_access(&address_book_id, &Uuid::parse_str(&dto.user_id)
530-
.map_err(|_| DomainError::validation_error("Invalid user ID format"))?)
531-
.await?;
532+
self.check_address_book_write_access(
533+
&address_book_id,
534+
&Uuid::parse_str(&dto.user_id)
535+
.map_err(|_| DomainError::validation_error("Invalid user ID format"))?,
536+
)
537+
.await?;
532538

533539
// Convert DTOs to domain entities
534540
let email: Vec<Email> = dto
@@ -604,9 +610,12 @@ impl ContactUseCase for ContactService {
604610
.map_err(|_| DomainError::validation_error("Invalid address book ID format"))?;
605611

606612
// Check if user has write access to the address book
607-
self.check_address_book_write_access(&address_book_id, &Uuid::parse_str(&dto.user_id)
608-
.map_err(|_| DomainError::validation_error("Invalid user ID format"))?)
609-
.await?;
613+
self.check_address_book_write_access(
614+
&address_book_id,
615+
&Uuid::parse_str(&dto.user_id)
616+
.map_err(|_| DomainError::validation_error("Invalid user ID format"))?,
617+
)
618+
.await?;
610619

611620
// Parse vCard data
612621
let mut contact = self.parse_vcard(&dto.vcard)?;
@@ -819,9 +828,12 @@ impl ContactUseCase for ContactService {
819828
.map_err(|_| DomainError::validation_error("Invalid address book ID format"))?;
820829

821830
// Check if user has write access to the address book
822-
self.check_address_book_write_access(&address_book_id, &Uuid::parse_str(&dto.user_id)
823-
.map_err(|_| DomainError::validation_error("Invalid user ID format"))?)
824-
.await?;
831+
self.check_address_book_write_access(
832+
&address_book_id,
833+
&Uuid::parse_str(&dto.user_id)
834+
.map_err(|_| DomainError::validation_error("Invalid user ID format"))?,
835+
)
836+
.await?;
825837

826838
let group = ContactGroup::new(address_book_id, dto.name);
827839

@@ -845,9 +857,12 @@ impl ContactUseCase for ContactService {
845857
.ok_or_else(|| DomainError::not_found("Contact group", "not found"))?;
846858

847859
// Check if user has write access to the address book
848-
self.check_address_book_write_access(group.address_book_id(), &Uuid::parse_str(&update.user_id)
849-
.map_err(|_| DomainError::validation_error("Invalid user ID format"))?)
850-
.await?;
860+
self.check_address_book_write_access(
861+
group.address_book_id(),
862+
&Uuid::parse_str(&update.user_id)
863+
.map_err(|_| DomainError::validation_error("Invalid user ID format"))?,
864+
)
865+
.await?;
851866

852867
// Update the group
853868
let updated_group = ContactGroup::from_raw(

src/application/services/file_management_service.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ impl FileManagementUseCase for FileManagementService {
178178
async fn delete_file(&self, id: &str) -> Result<(), DomainError> {
179179
self.file_repository.delete_file(id).await?;
180180
// Best-effort thumbnail cleanup
181-
if let Some(thumb) = &self.thumbnail_service {
182-
if let Err(e) = thumb.delete_thumbnails(id).await {
183-
warn!("Failed to delete thumbnails for file {}: {}", id, e);
184-
}
181+
if let Some(thumb) = &self.thumbnail_service
182+
&& let Err(e) = thumb.delete_thumbnails(id).await
183+
{
184+
warn!("Failed to delete thumbnails for file {}: {}", id, e);
185185
}
186186
Ok(())
187187
}
@@ -223,10 +223,10 @@ impl FileManagementUseCase for FileManagementService {
223223
warn!("Permanently deleting file: {}", id);
224224
self.file_repository.delete_file(id).await?;
225225
// Best-effort thumbnail cleanup
226-
if let Some(thumb) = &self.thumbnail_service {
227-
if let Err(e) = thumb.delete_thumbnails(id).await {
228-
warn!("Failed to delete thumbnails for file {}: {}", id, e);
229-
}
226+
if let Some(thumb) = &self.thumbnail_service
227+
&& let Err(e) = thumb.delete_thumbnails(id).await
228+
{
229+
warn!("Failed to delete thumbnails for file {}: {}", id, e);
230230
}
231231
info!("File permanently deleted: {}", id);
232232

0 commit comments

Comments
 (0)