diff options
| author | Adam Soltys <[email protected]> | 2020-07-19 13:11:32 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-07-19 13:11:32 -0700 |
| commit | f15a66797c3aef69d7290e7a577f554470cd5d86 (patch) | |
| tree | 1e713401a28e53ebcec663fccf86273cdb4bc82d | |
| parent | 1962a6dcf1bb37bb8beb3fc4c0231d5a504a75fe (diff) | |
| download | coinos-server-f15a66797c3aef69d7290e7a577f554470cd5d86.tar.gz coinos-server-f15a66797c3aef69d7290e7a577f554470cd5d86.zip | |
code post endpoint
| -rw-r--r-- | routes/lnurl.js | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/routes/lnurl.js b/routes/lnurl.js index 82f0f575..e447951b 100644 --- a/routes/lnurl.js +++ b/routes/lnurl.js @@ -19,17 +19,17 @@ var optionalAuth = function (req, res, next) { app.get("/url", async (req, res) => { try { - const { text } = await db.Code.findOne({ + const code = await db.Code.findOne({ where: { code: req.query.code, }, }); - if (text) { - res.send(text); + if (code) { + res.send(code.text); } else { - throw new Error('code not found'); - } + throw new Error("code not found"); + } } catch (e) { l.error("couldn't find url", e.message); } @@ -46,11 +46,6 @@ app.get("/withdraw", auth, async (req, res) => { withdrawals[result.secret] = req.user; - await db.Code.create({ - code: result.encoded.substr(64), - text: result.encoded, - }); - res.send(result); } catch (e) { l.error("problem generating withdrawl url", e.message); @@ -58,6 +53,20 @@ app.get("/withdraw", auth, async (req, res) => { } }); +app.post("/code", async (req, res) => { + try { + const { encoded } = req.body.lnurl; + const code = await db.Code.create({ + code: "lnurl:" + encoded.substr(-32), + text: encoded, + }); + + res.send(code); + } catch (e) { + res.status(500).send(e.message); + } +}); + app.post("/withdraw", auth, async (req, res) => { const { user } = req; const { @@ -109,11 +118,11 @@ const pay = async ({ amount, minSendable, maxSendable }, res, user) => { app.get("/pay/:username", async (req, res) => { const { username } = req.params; - let user = await db.User.findOne({ - where: { - username, - }, - }); + let user = await db.User.findOne({ + where: { + username, + }, + }); pay(req.query, res, user); }); @@ -345,7 +354,6 @@ lnurlServer.bindToHook( ); lnurlServer.bindToHook("login", async (key) => { - l.info("logging in"); try { if (!key) throw new Error("login key not defined"); |
