From 3ff68fc4a652700bf710db465709d2d9a9fcef38 Mon Sep 17 00:00:00 2001 From: shiroyashik Date: Fri, 26 Jul 2024 00:38:54 +0300 Subject: [PATCH] func user_info fixed + "temporary" removed --- src/api/figura/profile.rs | 11 +++++------ src/api/figura/websocket.rs | 6 +++--- src/main.rs | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/api/figura/profile.rs b/src/api/figura/profile.rs index 724d46b..9390b4b 100644 --- a/src/api/figura/profile.rs +++ b/src/api/figura/profile.rs @@ -2,11 +2,10 @@ use std::sync::Arc; use anyhow_http::{http_error_ret, response::Result}; use axum::{ - body::Bytes, - extract::{Path, State}, - Json, + body::Bytes, extract::{Path, State}, response::{IntoResponse, Response} }; use dashmap::DashMap; +use reqwest::StatusCode; use tracing::debug; use serde_json::{json, Value}; use tokio::{ @@ -25,7 +24,7 @@ use super::types::S2CMessage; pub async fn user_info( Path(uuid): Path, State(state): State, -) -> Json { +) -> Response { tracing::info!("Receiving profile information for {}", uuid); let formatted_uuid = format_uuid(&uuid); @@ -34,7 +33,7 @@ pub async fn user_info( let auth_system = match state.user_manager.get_by_uuid(&uuid) { Some(d) => d.auth_system.to_string(), - None => return Json(json!("err")), + None => return (StatusCode::NO_CONTENT, "not sculptor user".to_string()).into_response(), //(StatusCode::NOT_FOUND, "not found".to_string()).into_response(), }; let mut user_info_response = json!({ @@ -83,7 +82,7 @@ pub async fn user_info( } } } - Json(user_info_response) + (StatusCode::OK, user_info_response.to_string()).into_response() } pub async fn download_avatar(Path(uuid): Path) -> Result> { diff --git a/src/api/figura/websocket.rs b/src/api/figura/websocket.rs index 33f151a..d8ea92d 100644 --- a/src/api/figura/websocket.rs +++ b/src/api/figura/websocket.rs @@ -1,4 +1,4 @@ -use std::{sync::Arc, thread}; +use std::sync::Arc; use axum::{ extract::{ @@ -173,9 +173,9 @@ async fn handle_socket(mut socket: WebSocket, state: AppState) { } // Closing connection if let Some(u) = owner { - // state.session.remove(&u.uuid); // FIXME: Temporary solution + state.session.remove(&u.uuid); // FIXME: Temporary solution // state.broadcasts.remove(&u.uuid); // NOTE: Create broadcasts manager ?? - // state.user_manager.remove(&u.uuid); + state.user_manager.remove(&u.uuid); } } diff --git a/src/main.rs b/src/main.rs index 43309c9..adc114e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -118,7 +118,7 @@ async fn main() -> Result<()> { .route("/motd", get(api_info::motd)) .route("/equip", post(api_profile::equip_avatar)) .route("/:uuid", get(api_profile::user_info)) - .route("/:uuid/avatar", get(api_profile::download_avatar).layer(DefaultBodyLimit::disable())) + .route("/:uuid/avatar", get(api_profile::download_avatar)) .route("/avatar", put(api_profile::upload_avatar).layer(DefaultBodyLimit::disable())) .route("/avatar", delete(api_profile::delete_avatar));