aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-03-16 23:00:39 -0700
committerAdam Soltys <[email protected]>2023-03-16 23:00:55 -0700
commit013dffcbd0bdc901dc977af7c09daffe639614ee (patch)
tree4d4200e1655b536760e29dca54b7df3d6f06f087
parentd3a35dad2f335a6291f5d656e101956a51bdaa6b (diff)
downloadcoinos-server-013dffcbd0bdc901dc977af7c09daffe639614ee.tar.gz
coinos-server-013dffcbd0bdc901dc977af7c09daffe639614ee.zip
admin route
-rw-r--r--index.js1
-rw-r--r--routes/users.js41
2 files changed, 29 insertions, 13 deletions
diff --git a/index.js b/index.js
index 04e9187f..af27f27c 100644
--- a/index.js
+++ b/index.js
@@ -65,6 +65,7 @@ app.post("/bitcoin", payments.bitcoin);
app.post("/bitcoin/fee", auth, payments.fee);
app.post("/bitcoin/send", auth, payments.send);
+app.get("/users", auth, users.list);
app.get("/lower", users.lower);
app.get("/me", auth, users.me);
app.get("/users/:key", users.get);
diff --git a/routes/users.js b/routes/users.js
index 68e59b24..c9efc795 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -37,6 +37,21 @@ export default {
}
},
+ async list({ user }, res) {
+ if (!user.admin) fail("unauthorized");
+
+ let users = [];
+
+ for await (let k of db.scanIterator({ MATCH: "balance:*" })) {
+ let uid = k.split(":")[1];
+ let user = await g(`user:${uid}`);
+ user.balance = await g(k);
+ users.push(user);
+ }
+
+ res.send(users);
+ },
+
async get({ params: { key } }, res) {
key = key.toLowerCase().replace(/\s/g, "");
try {
@@ -57,7 +72,7 @@ export default {
username: key,
display: key.substr(0, 6),
pubkey: key,
- anon: true,
+ anon: true
};
}
@@ -74,7 +89,7 @@ export default {
"pubkey",
"display",
"prompt",
- "id",
+ "id"
];
if (user.pubkey)
@@ -98,7 +113,7 @@ export default {
pubkey,
password,
username,
- salt,
+ salt
};
user = await register(user, ip, false);
@@ -174,7 +189,7 @@ export default {
"salt",
"seed",
"tokens",
- "twofa",
+ "twofa"
];
for (let a of attributes) {
@@ -214,7 +229,7 @@ export default {
if (!token) fail();
user = await got(`${classic}/admin/migrate/${username}?zero=true`, {
- headers: { authorization: `Bearer ${config.admin}` },
+ headers: { authorization: `Bearer ${config.admin}` }
}).json();
let { balance } = user;
@@ -226,7 +241,7 @@ export default {
...pick(user, fields),
id: uid,
about: user.address,
- migrated: true,
+ migrated: true
};
await s(`user:${username}`, uid);
@@ -234,7 +249,7 @@ export default {
await s(`balance:${uid}`, balance);
let payments = await got(`${classic}/payments`, {
- headers: { authorization: `Bearer ${token}` },
+ headers: { authorization: `Bearer ${token}` }
}).json();
for (let p of payments) {
@@ -244,7 +259,7 @@ export default {
"confirmed",
"rate",
"currency",
- "preimage",
+ "preimage"
]);
n.id = v4();
n.created = parseISO(p.createdAt).getTime();
@@ -262,7 +277,7 @@ export default {
u = await got(
`${classic}/admin/migrate/${p.with.username.toLowerCase()}`,
{
- headers: { authorization: `Bearer ${config.admin}` },
+ headers: { authorization: `Bearer ${config.admin}` }
}
).json();
@@ -334,7 +349,7 @@ export default {
if (!subscriptions) subscriptions = [];
if (
!subscriptions.find(
- (s) => JSON.stringify(s) === JSON.stringify(subscription)
+ s => JSON.stringify(s) === JSON.stringify(subscription)
)
)
subscriptions.push(subscription);
@@ -371,8 +386,8 @@ export default {
let contacts = (await g(`${id}:contacts`)) || [];
for (let { ref } of (
- await Promise.all(payments.map(async (id) => await g(`payment:${id}`)))
- ).filter((p) => p.type === types.internal && p.ref)) {
+ await Promise.all(payments.map(async id => await g(`payment:${id}`)))
+ ).filter(p => p.type === types.internal && p.ref)) {
!~contacts.findIndex(({ id }) => id === ref) &&
contacts.push(await g(`user:${ref}`));
}
@@ -409,5 +424,5 @@ export default {
}
res.send("ok");
- },
+ }
};