html terminal
add /savefile
bendn 2023-09-21
parent 75acf8f · commit 39efdec
-rw-r--r--Cargo.toml1
-rw-r--r--src/bot/maps.rs14
-rw-r--r--src/server.rs10
3 files changed, 20 insertions, 5 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 886f7b0..4973400 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -42,6 +42,7 @@ serde_json = "1.0"
btparse = "0.1.1"
mindus = { version = "5", features = [], default-features = false }
oxipng = { git = "https://github.com/shssoichiro/oxipng", branch = "master", features = [], default-features = false }
+flate2 = { version = "1.0", features = ["cloudflare_zlib"], default-features = false }
strip-ansi-escapes = "0.2.0"
dashmap = "5.5.1"
lemu = { features = ["diagnose"], default-features = false, version = "0.2.0" }
diff --git a/src/bot/maps.rs b/src/bot/maps.rs
index b18a305..b9df598 100644
--- a/src/bot/maps.rs
+++ b/src/bot/maps.rs
@@ -91,11 +91,7 @@ impl MapImage {
{
(self.0.lock().await, None)
} else {
- send!(stdin, "save 0")?;
- let _ = get_nextblock().await;
-
- // parsing the thing doesnt negate the need for a env var sooo
- let o = std::fs::read(std::env::var("SAVE_PATH").unwrap())?;
+ let o = savefile(stdin).await?;
let (i, info) = tokio::task::spawn_blocking(move || {
let then = Instant::now();
let m = Map::deserialize(&mut mindus::data::DataRead::new(&o))?;
@@ -167,3 +163,11 @@ pub async fn view(ctx: Context<'_>) -> Result<()> {
.await?;
Ok(())
}
+
+pub async fn savefile(s: &Sender<String>) -> Result<Vec<u8>> {
+ send!(s, "save 0")?;
+ let _ = get_nextblock().await;
+
+ // parsing the thing doesnt negate the need for a env var sooo
+ Ok(std::fs::read(std::env::var("SAVE_PATH").unwrap())?)
+}
diff --git a/src/server.rs b/src/server.rs
index 218bf84..78e3b1c 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -63,6 +63,15 @@ async fn map_view(
)
}
+async fn map_file(
+ axum::extract::State(state): axum::extract::State<Arc<State>>,
+) -> impl IntoResponse {
+ (
+ AppendHeaders([(CONTENT_TYPE, "application/octet-stream")]),
+ crate::bot::maps::savefile(&state.stdin).await.unwrap(),
+ )
+}
+
pub struct Server;
impl Server {
pub async fn spawn(addr: SocketAddr) {
@@ -73,6 +82,7 @@ impl Server {
.route("/plaguess.png", png!(plaguess))
.route("/favicon.ico", png!(logo32))
.route("/view", get(map_view))
+ .route("/savefile", get(map_file))
.with_state(state.clone());
tokio::spawn(async move {
AxumServer::bind(&addr)