pinakes-server: fix subtitle list response and registration
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I22c7237877862acbf931ce4c662bd2816a6a6964
This commit is contained in:
parent
5e29de82eb
commit
fd11b2b7c4
5 changed files with 9 additions and 7 deletions
|
|
@ -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<SubtitleFormat> {
|
||||
match path.extension()?.to_str()?.to_lowercase().as_str() {
|
||||
"srt" => Some(SubtitleFormat::Srt),
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -80,13 +80,12 @@ pub async fn add_subtitle(
|
|||
Json(req): Json<AddSubtitleRequest>,
|
||||
) -> Result<Json<SubtitleResponse>, 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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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:?}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue