aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--index.ts4
-rw-r--r--lib/whitelist.ts1
-rw-r--r--routes/users.ts53
3 files changed, 51 insertions, 7 deletions
diff --git a/index.ts b/index.ts
index 10c2b314..a401d3d3 100644
--- a/index.ts
+++ b/index.ts
@@ -142,6 +142,10 @@ app.post("/apps/delete", auth, users.deleteApp);
app.post("/pins", auth, users.addPin);
app.post("/pins/delete", auth, users.deletePin);
+app.get("/trust", auth, users.trust);
+app.post("/trust", auth, users.addTrust);
+app.post("/trust/delete", auth, users.deleteTrust);
+
app.get("/subscriptions", auth, users.subscriptions);
app.post("/subscription", auth, users.subscription);
app.post("/subscription/delete", auth, users.deleteSubscription);
diff --git a/lib/whitelist.ts b/lib/whitelist.ts
index 5df18184..ca0431f5 100644
--- a/lib/whitelist.ts
+++ b/lib/whitelist.ts
@@ -41,6 +41,7 @@ export default [
"shopifyToken",
"theme",
"threshold",
+ "tip",
"twofa",
"username",
"verified",
diff --git a/routes/users.ts b/routes/users.ts
index 7f080cb9..b28d34c6 100644
--- a/routes/users.ts
+++ b/routes/users.ts
@@ -39,7 +39,7 @@ export default {
"blacklist",
user?.username?.toLowerCase().trim(),
);
-
+
const whitelisted = await db.sIsMember(
"whitelist",
user?.username?.toLowerCase().trim(),
@@ -195,9 +195,10 @@ export default {
if (user.id !== tokid) fail("unauthorized");
const { confirm, password, pin, newpin } = body;
- let username = body?.username?.toLowerCase().replace(/\s/g,"");
+ const username = body?.username?.toLowerCase().replace(/\s/g, "");
const valid = /^[\p{L}\p{N}]{2,24}$/u;
- if (!valid.test(username)) fail("Usernames can only have letters and numbers");
+ if (!valid.test(username))
+ fail("Usernames can only have letters and numbers");
let exists;
@@ -205,7 +206,9 @@ export default {
if (pubkey) {
pubkey = pubkey.trim();
exists = await getUser(pubkey);
- let existingUsername = exists.username.toLowerCase().replace(/\s/g,"");
+ const existingUsername = exists.username
+ .toLowerCase()
+ .replace(/\s/g, "");
if (exists && ![username].includes(existingUsername)) {
warn("key in use", pubkey, existingUsername);
if (exists.anon) await db.del(`user:${pubkey}`);
@@ -235,7 +238,7 @@ export default {
if (username) {
exists = await db.exists(`user:${username}`);
- let currentUsername = user.username.replace(/\s/g,"").toLowerCase()
+ const currentUsername = user.username.replace(/\s/g, "").toLowerCase();
if (currentUsername !== username && exists) {
err("username taken", username, currentUsername);
@@ -273,6 +276,7 @@ export default {
"shopifyStore",
"shopifyToken",
"threshold",
+ "tip",
"tokens",
"twofa",
];
@@ -281,6 +285,8 @@ export default {
if (typeof body[a] !== "undefined") user[a] = body[a];
}
+ user.tip = Math.max(0, Math.min(1000, parseInt(user.tip)));
+
if (password && password === confirm) {
user.password = await Bun.password.hash(password, {
algorithm: "bcrypt",
@@ -338,7 +344,7 @@ export default {
}
if (username !== "coinos")
- l("logged in", username, req.headers['cf-connecting-ip']);
+ l("logged in", username, req.headers["cf-connecting-ip"]);
const payload = { id: user.id };
const token = jwt.sign(payload, config.jwt);
@@ -394,7 +400,12 @@ export default {
}
const { username } = user;
- if (await db.sIsMember("compromised", username.replace(/\s/g,"").toLowerCase())) {
+ if (
+ await db.sIsMember(
+ "compromised",
+ username.replace(/\s/g, "").toLowerCase(),
+ )
+ ) {
warn("compromised nostr auth attempt");
fail("unauthorized");
}
@@ -490,6 +501,7 @@ export default {
let contacts = (await g(`${id}:contacts`)) || [];
const pins = await db.sMembers(`${id}:pins`);
+ const trust = await db.sMembers(`${id}:trust`);
for (const { ref } of (
await Promise.all(
@@ -514,6 +526,14 @@ export default {
c.pinned = true;
});
+ const trusted = contacts
+ .filter((c) => trust.includes(c.id))
+ .sort((a, b) => a.username.localeCompare(b.username));
+
+ trusted.map((c) => {
+ c.trusted = true;
+ });
+
let { limit } = params;
limit ||= contacts.length;
contacts = contacts.filter((c) => !pins.includes(c.id));
@@ -994,6 +1014,25 @@ export default {
res.send({});
},
+ async trust(req, res) {
+ const { id } = req.user;
+ res.send(await db.sMembers(`${id}:trust`));
+ },
+
+ async addTrust(req, res) {
+ const { id: uid } = req.user;
+ const { id } = req.body;
+ await db.sAdd(`${uid}:trust`, id);
+ res.send({});
+ },
+
+ async deleteTrust(req, res) {
+ const { id: uid } = req.user;
+ const { id } = req.body;
+ await db.sRem(`${uid}:trust`, id);
+ res.send({});
+ },
+
async credits(req, res) {
const { id } = req.user;
const bitcoin = await g(`credit:bitcoin:${id}`);