Compare commits
No commits in common. "24f5560d8d34de8fe4f46e14d0b85559c9432a4b" and "c0d02a99902a6b0ac35ba7b026898704e577f5b6" have entirely different histories.
24f5560d8d
...
c0d02a9990
|
@ -10,6 +10,6 @@ once_cell = "1.8.0"
|
||||||
serde = { version = "1.0.130", features = ["derive"] }
|
serde = { version = "1.0.130", features = ["derive"] }
|
||||||
serde_json = "1.0.68"
|
serde_json = "1.0.68"
|
||||||
tokio = { version = "1.12.0", features = ["full"] }
|
tokio = { version = "1.12.0", features = ["full"] }
|
||||||
tokio-stream = { version = "0.1.7", features = ["fs"] }
|
tokio-stream = "0.1.7"
|
||||||
uuid = { version = "0.8.2", features = ["v4"] }
|
uuid = { version = "0.8.2", features = ["v4"] }
|
||||||
warp = "0.3.1"
|
warp = "0.3.1"
|
||||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -6,9 +6,9 @@ use warb::{hyper::StatusCode, Filter, Reply};
|
||||||
use warp as warb; // i think it's funny
|
use warp as warb; // i think it's funny
|
||||||
|
|
||||||
mod events;
|
mod events;
|
||||||
mod utils;
|
|
||||||
mod viewer_connection;
|
mod viewer_connection;
|
||||||
mod watch_session;
|
mod watch_session;
|
||||||
|
mod utils;
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
@ -30,22 +30,6 @@ struct SubscribeQuery {
|
||||||
colour: String,
|
colour: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_emoji_list() -> Result<impl warb::Reply, warb::Rejection> {
|
|
||||||
use tokio_stream::{wrappers::ReadDirStream, StreamExt};
|
|
||||||
|
|
||||||
let dir = tokio::fs::read_dir("frontend/emojis")
|
|
||||||
.await
|
|
||||||
.expect("Couldn't read emojis directory!");
|
|
||||||
|
|
||||||
let files = ReadDirStream::new(dir)
|
|
||||||
.filter_map(|r| r.ok())
|
|
||||||
.map(|e| e.file_name().to_string_lossy().to_string())
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.await;
|
|
||||||
|
|
||||||
Ok(warb::reply::json(&files))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let start_session_route = warb::path!("start_session")
|
let start_session_route = warb::path!("start_session")
|
||||||
|
@ -62,8 +46,6 @@ async fn main() {
|
||||||
warb::reply::json(&json!({ "id": session_uuid.to_string(), "session": session_view }))
|
warb::reply::json(&json!({ "id": session_uuid.to_string(), "session": session_view }))
|
||||||
});
|
});
|
||||||
|
|
||||||
let get_emoji_route = warb::path!("emojis").and_then(get_emoji_list);
|
|
||||||
|
|
||||||
enum RequestedSession {
|
enum RequestedSession {
|
||||||
Session(Uuid, WatchSession),
|
Session(Uuid, WatchSession),
|
||||||
Error(warb::reply::WithStatus<warb::reply::Json>),
|
Error(warb::reply::WithStatus<warb::reply::Json>),
|
||||||
|
@ -114,7 +96,6 @@ async fn main() {
|
||||||
let routes = start_session_route
|
let routes = start_session_route
|
||||||
.or(get_status_route)
|
.or(get_status_route)
|
||||||
.or(ws_subscribe_route)
|
.or(ws_subscribe_route)
|
||||||
.or(get_emoji_route)
|
|
||||||
.or(warb::path::end().and(warb::fs::file("frontend/index.html")))
|
.or(warb::path::end().and(warb::fs::file("frontend/index.html")))
|
||||||
.or(warb::fs::dir("frontend"));
|
.or(warb::fs::dir("frontend"));
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ pub async fn ws_subscribe(session_uuid: Uuid, nickname: String, colour: String,
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut colour = colour;
|
let mut colour = colour;
|
||||||
if colour.len() != 6 || !colour.chars().all(|x| x.is_ascii_hexdigit()) {
|
if !colour.len() == 6 || !colour.chars().all(|x| x.is_ascii_hexdigit()) {
|
||||||
colour = String::from("7ed0ff");
|
colour = String::from("7ed0ff");
|
||||||
}
|
}
|
||||||
let nickname = truncate_str(&nickname, 50).to_string();
|
let nickname = truncate_str(&nickname, 50).to_string();
|
||||||
|
@ -92,7 +92,7 @@ pub async fn ws_subscribe(session_uuid: Uuid, nickname: String, colour: String,
|
||||||
let event: WatchEventData = match event {
|
let event: WatchEventData = match event {
|
||||||
WatchEventData::SetTime { from: _, to } => WatchEventData::SetTime {
|
WatchEventData::SetTime { from: _, to } => WatchEventData::SetTime {
|
||||||
from: Some(session.get_time_ms()),
|
from: Some(session.get_time_ms()),
|
||||||
to,
|
to: to,
|
||||||
},
|
},
|
||||||
_ => event,
|
_ => event,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue