aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/main.rs12
3 files changed, 12 insertions, 4 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 01dd077..f211f99 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1143,7 +1143,7 @@ dependencies = [
[[package]]
name = "rocket_test"
-version = "0.2.0"
+version = "0.2.1"
dependencies = [
"chrono",
"rocket",
diff --git a/Cargo.toml b/Cargo.toml
index 6ba4d6c..515f4ba 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "rocket_test"
-version = "0.2.0"
+version = "0.2.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
diff --git a/src/main.rs b/src/main.rs
index 3d5398b..1955963 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -26,8 +26,12 @@ fn get_message(id: usize, db: &State<SharedDB>) -> Json<Response<Message, &'stat
}
#[get("/get_message_id_list/<id_start>/<id_end>")]
fn get_message_id_list(id_start: u64, id_end: u64, db: &State<SharedDB>) -> Json<Response<Vec<UID>, &'static str>> {
- if id_end - id_start > 25 {
+ let delta = id_end as i128 - id_start as i128;
+
+ if delta > 25 {
return Json(Response(Err("Request limit is 25")))
+ } else if delta < 0 {
+ return Json(Response(Err("Request range is less than 0")))
}
let lock = db.sdb.lock().unwrap();
@@ -41,8 +45,12 @@ fn get_message_id_list(id_start: u64, id_end: u64, db: &State<SharedDB>) -> Json
}
#[get("/get_message_list/<id_start>/<id_end>")]
fn get_message_list(id_start: u64, id_end: u64, db: &State<SharedDB>) -> Json<Response<Vec<Message>, &'static str>> {
- if id_end - id_start > 25 {
+ let delta = id_end as i128 - id_start as i128;
+
+ if delta > 25 {
return Json(Response(Err("Request limit is 25")))
+ } else if delta < 0 {
+ return Json(Response(Err("Request range is less than 0")))
}
let lock = db.sdb.lock().unwrap();