diff options
| author | Adam Soltys <[email protected]> | 2026-02-28 19:26:13 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-02-28 19:26:13 -0800 |
| commit | 205ffb7684f18256690f374ab78745ccfe5d850d (patch) | |
| tree | 2defac29b4579a3aa67ec536b6aef0d6452b91fe | |
| parent | caf1f126d0569670712e26fa2f6ac3127605cd91 (diff) | |
| download | coinos-server-205ffb7684f18256690f374ab78745ccfe5d850d.tar.gz coinos-server-205ffb7684f18256690f374ab78745ccfe5d850d.zip | |
fix hono route order
| -rw-r--r-- | index.ts | 4 | ||||
| -rw-r--r-- | lib/app.ts | 3 | ||||
| -rw-r--r-- | routes/payments.ts | 12 | ||||
| -rw-r--r-- | routes/users.ts | 28 |
4 files changed, 36 insertions, 11 deletions
@@ -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); @@ -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}`); + l("deleteAccount account:", !!account, "type:", account?.type); + if (!account) fail("account not found"); - const pos = await db.lPos(`${uid}:accounts`, id); - if (!(account && pos != null)) 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) { |
