WIP: custom #ingest#protocol parser #23
3 changed files with 17 additions and 16 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1093,7 +1093,6 @@ dependencies = [
|
||||||
"hex",
|
"hex",
|
||||||
"hifitime",
|
"hifitime",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"nom",
|
|
||||||
"ntex",
|
"ntex",
|
||||||
"phf",
|
"phf",
|
||||||
"regex",
|
"regex",
|
||||||
|
@ -1104,7 +1103,6 @@ dependencies = [
|
||||||
"serde_with",
|
"serde_with",
|
||||||
"smallstr",
|
"smallstr",
|
||||||
"snafu",
|
"snafu",
|
||||||
"thiserror",
|
|
||||||
"tokio",
|
"tokio",
|
||||||
"ufmt",
|
"ufmt",
|
||||||
]
|
]
|
||||||
|
|
|
@ -16,7 +16,6 @@ heapless = { version = "0.8.0", features = ["ufmt"] }
|
||||||
hex = { version = "0.4.3", default-features = false, features = ["std", "alloc"] }
|
hex = { version = "0.4.3", default-features = false, features = ["std", "alloc"] }
|
||||||
hifitime = "4.0.2"
|
hifitime = "4.0.2"
|
||||||
lazy_static = "1.4.0"
|
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"] }
|
ntex = { version = "2.10.0", features = ["tokio", "cookie", "url"] }
|
||||||
phf = { version = "0.11.2", features = ["serde", "macros"] }
|
phf = { version = "0.11.2", features = ["serde", "macros"] }
|
||||||
regex = "1.8.4"
|
regex = "1.8.4"
|
||||||
|
@ -26,7 +25,6 @@ serde_json = "1.0.99"
|
||||||
serde_qs = "0.13.0"
|
serde_qs = "0.13.0"
|
||||||
serde_with = { version = "3.6.1", features = ["hex"] }
|
serde_with = { version = "3.6.1", features = ["hex"] }
|
||||||
smallstr = { version = "0.3.0", features = ["std", "union"] }
|
smallstr = { version = "0.3.0", features = ["std", "union"] }
|
||||||
thiserror = "1.0.40"
|
|
||||||
tokio = { version = "1.28.2", features = ["full"] }
|
tokio = { version = "1.28.2", features = ["full"] }
|
||||||
ufmt = { version = "0.2.0", features = ["std"] }
|
ufmt = { version = "0.2.0", features = ["std"] }
|
||||||
futures-util = { version = "0.3.30", features = ["tokio-io"] }
|
futures-util = { version = "0.3.30", features = ["tokio-io"] }
|
||||||
|
|
|
@ -3,20 +3,19 @@
|
||||||
mod handlers;
|
mod handlers;
|
||||||
mod types;
|
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::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::handlers::{app_init, version};
|
||||||
use crate::web_server::old_app_api::types::{AppInitRequest, MandatoryParams};
|
use crate::web_server::old_app_api::types::{AppInitRequest, MandatoryParams};
|
||||||
use crate::web_server::utils::redis::is_api_key_valid;
|
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;
|
use super::app_error;
|
||||||
|
|
||||||
|
|
||||||
/// Обработчик запросов от приложений.
|
/// Обработчик запросов от приложений.
|
||||||
///
|
///
|
||||||
/// Отвечает за разделение на функции по `cmd`.
|
/// Отвечает за разделение на функции по `cmd`.
|
||||||
|
@ -31,22 +30,28 @@ pub async fn old_api_handler(
|
||||||
return Err(AppError::RequestTooLarge);
|
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
|
// 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?;
|
is_api_key_valid(&app_state.redis_client, mandatory_params.api_key.as_ref()).await?;
|
||||||
|
|
||||||
match mandatory_params.cmd.as_ref() {
|
match mandatory_params.cmd.as_ref() {
|
||||||
"appInit" => {
|
"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
|
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")
|
//Ok("fuck")
|
||||||
|
|
Loading…
Add table
Reference in a new issue