started working on new tokeniser

This commit is contained in:
2026-05-16 21:11:45 +01:00
parent 94422b307c
commit 0c28bc113d
6 changed files with 125 additions and 30 deletions
+17 -6
View File
@@ -33,7 +33,7 @@ pub async fn api_process
(
data_to_send: Arc<Mutex<DataToSend>>,
characters: Arc<Mutex<HashMap::<String,character::Character>>>,
tx: Sender<(bool, usize)>,
tx: Sender<(bool, usize, String)>,
)
{
// This data must be passed through to the api route in order to be used
@@ -41,6 +41,7 @@ pub async fn api_process
let characters_filter = warp::any().map(move || Arc::clone(&characters));
let tx_filter = warp::any().map(move || tx.clone());
let tx_filter2 = tx_filter.clone();
let tx_filter3 = tx_filter.clone();
info!("Running server");
@@ -50,11 +51,11 @@ pub async fn api_process
.and(data_filter)
.and(tx_filter)
// Perform this code on a GET request
.map(|state: Arc<Mutex<DataToSend>>, tx_handle: Sender<(bool,usize)>|
.map(|state: Arc<Mutex<DataToSend>>, tx_handle: Sender<(bool,usize,String)>|
{
debug!("GET: {state:?}");
let reply = state.as_ref();
let _ = tx_handle.send((true,0));
let _ = tx_handle.send((true,0,String::new()));
warp::reply::json(&reply) // Send the reply data (data_to_send formatted as JSON)
}).boxed();
let characters = warp::path("character")
@@ -89,14 +90,24 @@ pub async fn api_process
.and(warp::post())
.and(warp::body::json())
.and(tx_filter2)
.map(|index: usize, tx_handle: Sender<(bool,usize)>| {
.map(|index: usize, tx_handle: Sender<(bool,usize,String)>| {
debug!("Choice: {index}");
let _ = tx_handle.send((true,index));
let _ = tx_handle.send((true,index,String::new()));
let reply = "ack";
warp::reply::json(&reply)
}).boxed();
let input = warp::path("input")
.and(warp::post())
.and(warp::body::json())
.and(tx_filter3)
.map(|input: String, tx_handle: Sender<(bool, usize, String)>|
{
let _ = tx_handle.send((true,0,input));
let reply = "ack";
warp::reply::json(&reply)
}).boxed();
let routes = main.or(characters).or(choice);
let routes = main.or(characters).or(choice).or(input);
// Start the server
warp::serve(routes)
.run(([127, 0, 0, 1],config::API_PORT))