aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-09-04 19:03:03 -0700
committerAdam Soltys <[email protected]>2026-09-04 19:03:14 -0700
commit671a114060ceaa7922affa00f90857bf99317d0a (patch)
treeeb972364ef7338d7c47a428153fceacb9b1c9a24
parenta7fc7959eeb58fa7230c7e0869012f03ad2b23b7 (diff)
downloadcoinos-server-671a114060ceaa7922affa00f90857bf99317d0a.tar.gz
coinos-server-671a114060ceaa7922affa00f90857bf99317d0a.zip
flash: create printer dir and return errors instead of unhandled 500
The web flasher config endpoint wrote ./printer/config.txt without creating the directory, so on a fresh deploy it threw ENOENT and the JSON error body was flashed to devices as the LittleFS partition. Create the directory, validate inputs, and route errors through bail. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_014gVYGi29FjTeLdNTiutkZx
-rw-r--r--routes/users.ts20
1 files changed, 13 insertions, 7 deletions
diff --git a/routes/users.ts b/routes/users.ts
index 438452b2..a6b75342 100644
--- a/routes/users.ts
+++ b/routes/users.ts
@@ -1,5 +1,5 @@
import { createReadStream } from "node:fs";
-import { unlink, writeFile } from "node:fs/promises";
+import { mkdir, unlink, writeFile } from "node:fs/promises";
import config from "$config";
import { requirePin } from "$lib/auth";
import { db, g, ga, gf, s } from "$lib/db";
@@ -1077,12 +1077,18 @@ export default {
},
async flash(req, res) {
- const { ssid, key, token } = req.body;
- const cfg = `${ssid.trim()}\n${key.trim()}\n${token.trim()}\n`;
- await writeFile("./printer/config.txt", cfg, "utf8");
- await $`./mklittlefs -c ./printer -p 256 -b 4096 -s 0x20000 ./littlefs.img`;
- res.header("Content-Type", "application/octet-stream");
- return res.send(createReadStream("./littlefs.img"));
+ try {
+ const { ssid, key, token } = req.body;
+ if (!ssid || !key || !token) fail("ssid, key and token required");
+ const cfg = `${ssid.trim()}\n${key.trim()}\n${token.trim()}\n`;
+ await mkdir("./printer", { recursive: true });
+ await writeFile("./printer/config.txt", cfg, "utf8");
+ await $`./mklittlefs -c ./printer -p 256 -b 4096 -s 0x20000 ./littlefs.img`;
+ res.header("Content-Type", "application/octet-stream");
+ return res.send(createReadStream("./littlefs.img"));
+ } catch (e) {
+ bail(res, e.message);
+ }
},
async app(req, res) {