chore: remove nom & thiserror
This commit is contained in:
parent
71e3b90a0b
commit
3f67cb4641
3 changed files with 17 additions and 16 deletions
|
@ -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")
|
||||
|
|
Loading…
Add table
Reference in a new issue