From b1ddb32ff0150e5333ec0685540b22b7edfa73ee Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sat, 21 Mar 2026 13:33:29 +0300 Subject: [PATCH] pinakes-server: fix subtitle list response and registration Signed-off-by: NotAShelf Change-Id: I22c7237877862acbf931ce4c662bd2816a6a6964 --- crates/pinakes-core/src/subtitles.rs | 3 +++ crates/pinakes-server/src/api_doc.rs | 2 +- crates/pinakes-server/src/app.rs | 2 +- crates/pinakes-server/src/routes/subtitles.rs | 5 ++--- crates/pinakes-server/tests/notes.rs | 4 ++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/pinakes-core/src/subtitles.rs b/crates/pinakes-core/src/subtitles.rs index 51ae763..76cc8b5 100644 --- a/crates/pinakes-core/src/subtitles.rs +++ b/crates/pinakes-core/src/subtitles.rs @@ -35,6 +35,7 @@ pub enum SubtitleFormat { impl SubtitleFormat { /// Returns the MIME type for this subtitle format. + #[must_use] pub const fn mime_type(self) -> &'static str { match self { Self::Srt => "application/x-subrip", @@ -45,6 +46,7 @@ impl SubtitleFormat { } /// Returns true if this format is binary (not UTF-8 text). + #[must_use] pub const fn is_binary(self) -> bool { matches!(self, Self::Pgs) } @@ -96,6 +98,7 @@ pub struct SubtitleTrackInfo { /// Detects the subtitle format from a file extension. /// /// Returns `None` if the extension is unrecognised or absent. +#[must_use] pub fn detect_format(path: &Path) -> Option { match path.extension()?.to_str()?.to_lowercase().as_str() { "srt" => Some(SubtitleFormat::Srt), diff --git a/crates/pinakes-server/src/api_doc.rs b/crates/pinakes-server/src/api_doc.rs index c4a8e4d..279b637 100644 --- a/crates/pinakes-server/src/api_doc.rs +++ b/crates/pinakes-server/src/api_doc.rs @@ -1,6 +1,6 @@ use utoipa::OpenApi; -/// Central OpenAPI document registry. +/// Central `OpenAPI` document registry. /// Handler functions and schemas are added here as route modules are annotated. #[derive(OpenApi)] #[openapi( diff --git a/crates/pinakes-server/src/app.rs b/crates/pinakes-server/src/app.rs index ed859d0..3d2f531 100644 --- a/crates/pinakes-server/src/app.rs +++ b/crates/pinakes-server/src/app.rs @@ -56,7 +56,7 @@ pub fn create_router_with_tls( let swagger_ui_enabled = state .config .try_read() - .map_or(false, |cfg| cfg.server.swagger_ui); + .is_ok_and(|cfg| cfg.server.swagger_ui); let global_governor = build_governor( rate_limits.global_per_second, diff --git a/crates/pinakes-server/src/routes/subtitles.rs b/crates/pinakes-server/src/routes/subtitles.rs index 2f71311..8cb97ca 100644 --- a/crates/pinakes-server/src/routes/subtitles.rs +++ b/crates/pinakes-server/src/routes/subtitles.rs @@ -80,13 +80,12 @@ pub async fn add_subtitle( Json(req): Json, ) -> Result, ApiError> { // Validate language code if provided. - if let Some(ref lang) = req.language { - if !validate_language_code(lang) { + if let Some(ref lang) = req.language + && !validate_language_code(lang) { return Err(ApiError( pinakes_core::error::PinakesError::InvalidLanguageCode(lang.clone()), )); } - } let is_embedded = req.is_embedded.unwrap_or(false); diff --git a/crates/pinakes-server/tests/notes.rs b/crates/pinakes-server/tests/notes.rs index 2dddd1e..2e1582d 100644 --- a/crates/pinakes-server/tests/notes.rs +++ b/crates/pinakes-server/tests/notes.rs @@ -59,11 +59,11 @@ async fn notes_graph_empty() { let nodes_empty = obj .get("nodes") .and_then(|v| v.as_array()) - .map_or(true, |a| a.is_empty()); + .is_none_or(std::vec::Vec::is_empty); let edges_empty = obj .get("edges") .and_then(|v| v.as_array()) - .map_or(true, |a| a.is_empty()); + .is_none_or(std::vec::Vec::is_empty); assert!( nodes_empty && edges_empty, "graph should be empty, got {obj:?}"