1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
import { g, s } from "$lib/db";
import { generate } from "$lib/invoices";
import { fail, pick } from "$lib/utils";
import whitelist from "$lib/whitelist";
import got from "got";
import config from "$config";
import ln from "$lib/ln";
export default {
async get({ params: { hash } }, res) {
let pr;
if (hash.startsWith("ln")) {
({ payment_hash: hash } = await ln.decode(hash));
}
let invoice = await g(`invoice:${hash}`);
if (invoice) {
invoice.user = pick(await g(`user:${invoice.uid}`), whitelist);
invoice.id = hash;
} else if (config.classic) {
invoice = await got(`${config.classic}/invoice/${pr}`).json();
if (invoice) {
invoice.id = invoice.uuid;
invoice.classic = true;
invoice.user.id = invoice.user.uuid;
invoice.user.username += "@classic";
}
}
if (invoice) res.send(invoice);
else res.code(500).send("invoice not found");
},
async create({ body: { invoice, user }, user: sender }, res) {
res.send(await generate({ invoice, user, sender }));
},
async classic({ params: { username } }, res) {
let invoice = await got
.post(`${config.classic}/invoice`, {
json: {
invoice: { amount: 0, network: "lightning" },
user: { username }
}
})
.json();
res.send(invoice);
}
};
|