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 {
|
impl SubtitleFormat {
|
||||||
/// Returns the MIME type for this subtitle format.
|
/// Returns the MIME type for this subtitle format.
|
||||||
|
#[must_use]
|
||||||
pub const fn mime_type(self) -> &'static str {
|
pub const fn mime_type(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Self::Srt => "application/x-subrip",
|
Self::Srt => "application/x-subrip",
|
||||||
|
|
@ -45,6 +46,7 @@ impl SubtitleFormat {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this format is binary (not UTF-8 text).
|
/// Returns true if this format is binary (not UTF-8 text).
|
||||||
|
#[must_use]
|
||||||
pub const fn is_binary(self) -> bool {
|
pub const fn is_binary(self) -> bool {
|
||||||
matches!(self, Self::Pgs)
|
matches!(self, Self::Pgs)
|
||||||
}
|
}
|
||||||
|
|
@ -96,6 +98,7 @@ pub struct SubtitleTrackInfo {
|
||||||
/// Detects the subtitle format from a file extension.
|
/// Detects the subtitle format from a file extension.
|
||||||
///
|
///
|
||||||
/// Returns `None` if the extension is unrecognised or absent.
|
/// Returns `None` if the extension is unrecognised or absent.
|
||||||
|
#[must_use]
|
||||||
pub fn detect_format(path: &Path) -> Option<SubtitleFormat> {
|
pub fn detect_format(path: &Path) -> Option<SubtitleFormat> {
|
||||||
match path.extension()?.to_str()?.to_lowercase().as_str() {
|
match path.extension()?.to_str()?.to_lowercase().as_str() {
|
||||||
"srt" => Some(SubtitleFormat::Srt),
|
"srt" => Some(SubtitleFormat::Srt),
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use utoipa::OpenApi;
|
use utoipa::OpenApi;
|
||||||
|
|
||||||
/// Central OpenAPI document registry.
|
/// Central `OpenAPI` document registry.
|
||||||
/// Handler functions and schemas are added here as route modules are annotated.
|
/// Handler functions and schemas are added here as route modules are annotated.
|
||||||
#[derive(OpenApi)]
|
#[derive(OpenApi)]
|
||||||
#[openapi(
|
#[openapi(
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ pub fn create_router_with_tls(
|
||||||
let swagger_ui_enabled = state
|
let swagger_ui_enabled = state
|
||||||
.config
|
.config
|
||||||
.try_read()
|
.try_read()
|
||||||
.map_or(false, |cfg| cfg.server.swagger_ui);
|
.is_ok_and(|cfg| cfg.server.swagger_ui);
|
||||||
|
|
||||||
let global_governor = build_governor(
|
let global_governor = build_governor(
|
||||||
rate_limits.global_per_second,
|
rate_limits.global_per_second,
|
||||||
|
|
|
||||||
|
|
@ -80,13 +80,12 @@ pub async fn add_subtitle(
|
||||||
Json(req): Json<AddSubtitleRequest>,
|
Json(req): Json<AddSubtitleRequest>,
|
||||||
) -> Result<Json<SubtitleResponse>, ApiError> {
|
) -> Result<Json<SubtitleResponse>, ApiError> {
|
||||||
// Validate language code if provided.
|
// Validate language code if provided.
|
||||||
if let Some(ref lang) = req.language {
|
if let Some(ref lang) = req.language
|
||||||
if !validate_language_code(lang) {
|
&& !validate_language_code(lang) {
|
||||||
return Err(ApiError(
|
return Err(ApiError(
|
||||||
pinakes_core::error::PinakesError::InvalidLanguageCode(lang.clone()),
|
pinakes_core::error::PinakesError::InvalidLanguageCode(lang.clone()),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let is_embedded = req.is_embedded.unwrap_or(false);
|
let is_embedded = req.is_embedded.unwrap_or(false);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,11 +59,11 @@ async fn notes_graph_empty() {
|
||||||
let nodes_empty = obj
|
let nodes_empty = obj
|
||||||
.get("nodes")
|
.get("nodes")
|
||||||
.and_then(|v| v.as_array())
|
.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
|
let edges_empty = obj
|
||||||
.get("edges")
|
.get("edges")
|
||||||
.and_then(|v| v.as_array())
|
.and_then(|v| v.as_array())
|
||||||
.map_or(true, |a| a.is_empty());
|
.is_none_or(std::vec::Vec::is_empty);
|
||||||
assert!(
|
assert!(
|
||||||
nodes_empty && edges_empty,
|
nodes_empty && edges_empty,
|
||||||
"graph should be empty, got {obj:?}"
|
"graph should be empty, got {obj:?}"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue