Typstify /chat_message to /chat
This commit is contained in:
parent
8bece23baf
commit
de7ae63a5e
13 changed files with 93 additions and 153 deletions
|
|
@ -3,17 +3,13 @@ mod r#static;
|
|||
pub mod statuscode;
|
||||
|
||||
use axum::{
|
||||
Form, Router,
|
||||
extract::{DefaultBodyLimit, State},
|
||||
Router,
|
||||
extract::DefaultBodyLimit,
|
||||
routing::{get, post},
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use tokio::{net::TcpListener, sync::mpsc};
|
||||
|
||||
use crate::{
|
||||
documents,
|
||||
drawer::{ChatMessageDrawing, Command},
|
||||
};
|
||||
use crate::{documents, drawer::Command};
|
||||
|
||||
use self::r#static::get_static_file;
|
||||
|
||||
|
|
@ -32,7 +28,10 @@ pub async fn run(tx: mpsc::Sender<Command>, addr: String) -> anyhow::Result<()>
|
|||
"/cells",
|
||||
post(documents::cells::post).fallback(get_static_file),
|
||||
)
|
||||
.route("/chat_message", post(post_chat_message))
|
||||
.route(
|
||||
"/chat",
|
||||
post(documents::chat::post).fallback(get_static_file),
|
||||
)
|
||||
.route("/egg", post(documents::egg::post).fallback(get_static_file))
|
||||
.route(
|
||||
"/image",
|
||||
|
|
@ -54,21 +53,3 @@ pub async fn run(tx: mpsc::Sender<Command>, addr: String) -> anyhow::Result<()>
|
|||
axum::serve(listener, app).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// /chat_message
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct PostChatMessageForm {
|
||||
username: String,
|
||||
content: String,
|
||||
}
|
||||
|
||||
async fn post_chat_message(server: State<Server>, request: Form<PostChatMessageForm>) {
|
||||
let _ = server
|
||||
.tx
|
||||
.send(Command::draw(ChatMessageDrawing {
|
||||
username: request.0.username,
|
||||
content: request.0.content,
|
||||
}))
|
||||
.await;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue