From 3f67cb4641eb35463a1ba38f21fc51615f7fd724 Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Fri, 10 Jan 2025 22:13:02 +0400 Subject: [PATCH] chore: remove nom & thiserror --- Cargo.lock | 2 -- Cargo.toml | 2 -- src/web_server/old_app_api/mod.rs | 29 +++++++++++++++++------------ 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eb37b9d..c77d0cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1093,7 +1093,6 @@ dependencies = [ "hex", "hifitime", "lazy_static", - "nom", "ntex", "phf", "regex", @@ -1104,7 +1103,6 @@ dependencies = [ "serde_with", "smallstr", "snafu", - "thiserror", "tokio", "ufmt", ] diff --git a/Cargo.toml b/Cargo.toml index d571bc0..7c5840c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ heapless = { version = "0.8.0", features = ["ufmt"] } hex = { version = "0.4.3", default-features = false, features = ["std", "alloc"] } hifitime = "4.0.2" lazy_static = "1.4.0" -nom = { version = "7.1.3", default-features = false, features = ["std", "alloc"] } ntex = { version = "2.10.0", features = ["tokio", "cookie", "url"] } phf = { version = "0.11.2", features = ["serde", "macros"] } regex = "1.8.4" @@ -26,7 +25,6 @@ serde_json = "1.0.99" serde_qs = "0.13.0" serde_with = { version = "3.6.1", features = ["hex"] } smallstr = { version = "0.3.0", features = ["std", "union"] } -thiserror = "1.0.40" tokio = { version = "1.28.2", features = ["full"] } ufmt = { version = "0.2.0", features = ["std"] } futures-util = { version = "0.3.30", features = ["tokio-io"] } diff --git a/src/web_server/old_app_api/mod.rs b/src/web_server/old_app_api/mod.rs index 3430f7c..c970829 100644 --- a/src/web_server/old_app_api/mod.rs +++ b/src/web_server/old_app_api/mod.rs @@ -3,20 +3,19 @@ mod handlers; mod types; -use ntex::web::types::State; -use ntex::util::Bytes; -use ntex::web; -use nom::AsBytes; -use snafu::ResultExt; use crate::web_server::app_error::AppError; -use crate::web_server::NMAppState; use crate::web_server::old_app_api::handlers::{app_init, version}; use crate::web_server::old_app_api::types::{AppInitRequest, MandatoryParams}; use crate::web_server::utils::redis::is_api_key_valid; +use crate::web_server::NMAppState; +use bstr::ByteSlice; +use ntex::util::Bytes; +use ntex::web; +use ntex::web::types::State; +use snafu::ResultExt; use super::app_error; - /// Обработчик запросов от приложений. /// /// Отвечает за разделение на функции по `cmd`. @@ -31,22 +30,28 @@ pub async fn old_api_handler( return Err(AppError::RequestTooLarge); } - let body_bytes = body_bytes.as_bytes(); + let body_bytes = body_bytes.as_bstr(); - let mandatory_params: MandatoryParams<'_> = serde_json::from_slice(body_bytes).context(app_error::JsonSnafu {})?; // TODO: Simd-JSON + let mandatory_params: MandatoryParams<'_> = + serde_json::from_slice(body_bytes).context(app_error::JsonSnafu {})?; // TODO: Simd-JSON // Ignore clippy singlematch - if mandatory_params.cmd.as_ref() == "version" { return version((), &app_state).await } + if mandatory_params.cmd.as_ref() == "version" { + return version((), &app_state).await; + } is_api_key_valid(&app_state.redis_client, mandatory_params.api_key.as_ref()).await?; match mandatory_params.cmd.as_ref() { "appInit" => { - let body: AppInitRequest = serde_json::from_slice(body_bytes).context(app_error::JsonSnafu {})?; + let body: AppInitRequest = + serde_json::from_slice(body_bytes).context(app_error::JsonSnafu {})?; app_init(body, &app_state).await } - _ => Err(AppError::UnknownMethod { method: mandatory_params.cmd.to_string() }), + _ => Err(AppError::UnknownMethod { + method: mandatory_params.cmd.to_string(), + }), } //Ok("fuck")