From 205ffb7684f18256690f374ab78745ccfe5d850d Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 28 Feb 2026 19:26:13 -0800 Subject: fix hono route order --- index.ts | 4 ++-- lib/app.ts | 3 ++- routes/payments.ts | 12 ++++++++++++ routes/users.ts | 30 +++++++++++++++++++++--------- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/index.ts b/index.ts index d40bae55..032913a3 100644 --- a/index.ts +++ b/index.ts @@ -138,16 +138,17 @@ app.post("/ark/send", auth, payments.ark); app.post("/ark/vault-send", auth, payments.arkVaultSend); app.post("/ark/vault-receive", auth, payments.arkVaultReceive); +app.post("/account/delete", auth, users.deleteAccount); app.get("/account/:id", auth, users.account); app.post("/account/:id", auth, users.updateAccount); app.get("/accounts", auth, users.accounts); app.post("/accounts", auth, users.createAccount); -app.post("/account/delete", auth, users.deleteAccount); app.get("/users", auth, users.list); app.get("/me", auth, users.me); app.get("/ro", auth, users.ro); app.get("/credits", auth, users.credits); +app.get("/users/delete/:username", users.del); app.get("/users/:key", users.get); app.post("/register", users.create); app.post("/disable2fa", auth, users.disable2fa); @@ -155,7 +156,6 @@ app.post("/2fa", auth, users.enable2fa); app.post("/user", auth, users.update); app.post("/reset", optional, users.reset); app.post("/upload/:type", users.upload); -app.get("/users/delete/:username", users.del); app.post("/acl", users.acl); app.post("/superuser", users.superuser); app.get("/verify/:code", users.verify); diff --git a/lib/app.ts b/lib/app.ts index 8dc1e106..e2b8d49e 100644 --- a/lib/app.ts +++ b/lib/app.ts @@ -141,7 +141,8 @@ app.use("*", async (c, next) => { }); // Error handler -app.onError((_err, c) => { +app.onError((err, c) => { + console.error("unhandled error:", c.req.method, c.req.path, err?.message || err); return c.json({ ok: false }, 500); }); diff --git a/routes/payments.ts b/routes/payments.ts index 0689f57d..beae4d1a 100644 --- a/routes/payments.ts +++ b/routes/payments.ts @@ -953,6 +953,18 @@ export default { if (!gotLock) return c.json({ synced: 0, received: 0, payments: [] }); try { + // Sync ark address if client reports a different one + if (body.arkAddress) { + const account = await g(`account:${aid}`); + if (account && account.arkAddress !== body.arkAddress) { + if (account.arkAddress) await db.del(`arkaddr:${account.arkAddress}`); + account.arkAddress = body.arkAddress; + await s(`account:${aid}`, account); + await db.set(`arkaddr:${body.arkAddress}`, JSON.stringify({ aid, uid })); + l("arkSync updated arkAddress for", aid); + } + } + const { rate, currency } = await getUserRate(user); let synced = 0; diff --git a/routes/users.ts b/routes/users.ts index 4d07a288..9ebe3614 100644 --- a/routes/users.ts +++ b/routes/users.ts @@ -1010,10 +1010,22 @@ export default { const body = await c.req.json(); const { id } = body; const { id: uid } = c.get("user"); + l("deleteAccount", id, "uid:", uid); const account = await g(`account:${id}`); - - const pos = await db.lPos(`${uid}:accounts`, id); - if (!(account && pos != null)) fail("account not found"); + l("deleteAccount account:", !!account, "type:", account?.type); + if (!account) fail("account not found"); + + // Support both list and set storage for accounts + const keyType = await db.type(`${uid}:accounts`); + if (keyType === "list") { + const pos = await db.lPos(`${uid}:accounts`, id); + if (pos == null) fail("account not found"); + } else if (keyType === "set") { + const isMember = await db.sIsMember(`${uid}:accounts`, id); + if (!isMember) fail("account not found"); + } else { + fail("account not found"); + } if (account.type !== "ark") { try { @@ -1024,12 +1036,12 @@ export default { } } - await db - .multi() - .lRem(`${uid}:accounts`, 1, id) - .del(`account:${id}`) - .del(`${id}:payments`) - .exec(); + const m = db.multi(); + if (keyType === "list") m.lRem(`${uid}:accounts`, 1, id); + else if (keyType === "set") m.sRem(`${uid}:accounts`, id); + m.del(`account:${id}`).del(`${id}:payments`); + if (account.arkAddress) m.del(`arkaddr:${account.arkAddress}`); + await m.exec(); return c.json({ ok: true }); } catch (e) { -- cgit v1.2.3