From c1483ab210a46abccbca809bbeba70e4c7e9ca0b Mon Sep 17 00:00:00 2001 From: askiiart Date: Wed, 27 Nov 2024 23:41:31 -0600 Subject: [PATCH] fix limit panicking in search() if config is specified --- src/api.rs | 12 +++++------- src/dummy.rs | 5 ++++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/api.rs b/src/api.rs index 86a2b90..f485dba 100644 --- a/src/api.rs +++ b/src/api.rs @@ -57,12 +57,12 @@ pub(crate) fn caps() -> status::Custom> { pub(crate) fn search(form: SearchForm) -> status::Custom> { // The compiler won't let you get a field from a struct in the Option here, since the default is None // So this is needed - let conf = create_empty_config(); + let mut conf = create_empty_config(); unsafe { if CONFIG.is_none() { return (*STATUS_CONFIG_NOT_SPECIFIED).clone(); } else { - let conf: Config = CONFIG.clone().ok_or("").unwrap(); + conf = CONFIG.clone().ok_or("").unwrap(); } } @@ -99,11 +99,9 @@ pub(crate) fn search(form: SearchForm) -> status::Custom> { offset = form.offset.ok_or(0).unwrap(); } - let mut limit: u32 = 0; - limit = conf.caps.limits.max; - let wanted_limit = form.limit.ok_or(limit).unwrap(); - if wanted_limit < limit { - limit = wanted_limit + let mut limit: u32 = form.limit.ok_or("").unwrap_or(conf.caps.limits.max); + if limit > conf.caps.limits.max { + limit = conf.caps.limits.max; } match conf.auth { diff --git a/src/dummy.rs b/src/dummy.rs index 4d61c99..84f201c 100644 --- a/src/dummy.rs +++ b/src/dummy.rs @@ -54,7 +54,10 @@ pub(crate) fn create_empty_config() -> Config { image: None, version: Some("1.0".to_string()), }, - limits: Limits { max: 1, default: 1 }, + limits: Limits { + max: 100, + default: 20, + }, searching: searching, categories: categories, genres: Some(genres),