Dev workflow update and enhance sculptor API:
Some checks failed
Push Dev / docker (push) Has been cancelled

+ remove unused types
+ added sending to all
+ enhance logging
This commit is contained in:
Shiroyasha 2025-02-13 03:18:16 +03:00
parent c7c3bd881f
commit bac1203df8
Signed by: shiroyashik
GPG key ID: E4953D3940D7860A
5 changed files with 51 additions and 44 deletions

View file

@ -2,7 +2,10 @@ name: Push Dev
on:
push:
branches: [ "dev" ]
branches:
- "**"
tags-ignore:
- '**'
jobs:
docker:

View file

@ -1,4 +1,3 @@
## Use port 80 for HTTP or port 443 for HTTPS.
## If running in a Docker container, leave this as default.
listen = "0.0.0.0:6665"

View file

@ -1,8 +1,14 @@
use std::collections::HashMap;
use axum::extract::{Query, State};
use tracing::{debug, trace, warn};
use tracing::instrument;
use uuid::Uuid;
use crate::{api::errors::{error_and_log, internal_and_log}, auth::Token, ApiResult, AppState};
use super::types::UserUuid;
/*
FIXME: need to refactor
*/
pub(super) async fn verify(
Token(token): Token,
@ -13,55 +19,62 @@ pub(super) async fn verify(
Ok("ok")
}
#[instrument(skip(token, state, body))]
pub(super) async fn raw(
Token(token): Token,
Query(query): Query<UserUuid>,
Query(query): Query<HashMap<String, String>>,
State(state): State<AppState>,
body: String,
) -> ApiResult<&'static str> {
trace!(body = body);
tracing::trace!(body = body);
state.config.read().await.clone().verify_token(&token)?;
let mut payload = vec![0; body.len() / 2];
faster_hex::hex_decode(body.as_bytes(), &mut payload).map_err(|err| { warn!("not raw data"); error_and_log(err, crate::ApiError::NotAcceptable) })?;
debug!("{:?}", payload);
faster_hex::hex_decode(body.as_bytes(), &mut payload).map_err(|err| { tracing::warn!("not raw data"); error_and_log(err, crate::ApiError::NotAcceptable) })?;
match query.uuid {
Some(uuid) => {
// for only one
let tx = state.session.get(&uuid).ok_or_else(|| { warn!("unknown uuid"); crate::ApiError::NotFound })?;
if query.contains_key("uuid") == query.contains_key("all") {
tracing::warn!("invalid query params");
return Err(crate::ApiError::BadRequest);
}
if let Some(uuid) = query.get("uuid") {
// for one
let uuid = Uuid::parse_str(uuid).map_err(|err| { tracing::warn!("invalid uuid"); error_and_log(err, crate::ApiError::BadRequest) })?;
let tx = state.session.get(&uuid).ok_or_else(|| { tracing::warn!("unknown uuid"); crate::ApiError::NotFound })?;
tx.value().send(crate::api::figura::SessionMessage::Ping(payload)).await.map_err(internal_and_log)?;
Ok("ok")
},
None => {
} else if query.contains_key("all") {
// for all
warn!("uuid doesnt defined");
Err(crate::ApiError::NotFound)
},
for tx in state.session.iter() {
if let Err(e) = tx.value().send(crate::api::figura::SessionMessage::Ping(payload.clone())).await {
tracing::debug!(error = ?e , "error while sending to session");
}
};
Ok("ok")
} else {
tracing::error!("unreachable code!");
Err(crate::ApiError::Internal)
}
}
#[instrument(skip(token, state, body))]
pub(super) async fn sub_raw(
Token(token): Token,
Query(query): Query<UserUuid>,
Query(query): Query<HashMap<String, String>>,
State(state): State<AppState>,
body: String,
) -> ApiResult<&'static str> {
trace!(body = body);
tracing::trace!(body = body);
state.config.read().await.clone().verify_token(&token)?;
let mut payload = vec![0; body.len() / 2];
faster_hex::hex_decode(body.as_bytes(), &mut payload).map_err(|err| { warn!("not raw data"); error_and_log(err, crate::ApiError::NotAcceptable) })?;
debug!("{:?}", payload);
faster_hex::hex_decode(body.as_bytes(), &mut payload).map_err(|err| { tracing::warn!("not raw data"); error_and_log(err, crate::ApiError::NotAcceptable) })?;
match query.uuid {
Some(uuid) => {
// for only one
let tx = state.subscribes.get(&uuid).ok_or_else(|| { warn!("unknown uuid"); crate::ApiError::NotFound })?;
if let Some(uuid) = query.get("uuid") {
let uuid = Uuid::parse_str(uuid).map_err(|err| { tracing::warn!("invalid uuid"); error_and_log(err, crate::ApiError::BadRequest) })?;
let tx = state.subscribes.get(&uuid).ok_or_else(|| { tracing::warn!("unknown uuid"); crate::ApiError::NotFound })?;
tx.value().send(payload).map_err(internal_and_log)?;
Ok("ok")
},
None => {
warn!("uuid doesnt defined");
} else {
tracing::warn!("uuid doesnt defined");
Err(crate::ApiError::NotFound)
},
}
}

View file

@ -3,7 +3,6 @@ use crate::AppState;
mod http2ws;
mod users;
mod types;
mod avatars;
pub fn router(limit: usize) -> Router<AppState> {

View file

@ -1,7 +0,0 @@
use serde::Deserialize;
use uuid::Uuid;
#[derive(Deserialize)]
pub(super) struct UserUuid {
pub uuid: Option<Uuid>,
}