aboutsummaryrefslogtreecommitdiffstats
path: root/lib/utils.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-03-27 21:09:22 -0700
committerAdam Soltys <[email protected]>2023-03-27 21:09:22 -0700
commit0559a382066722b794e1aaaafbb24266c7302f9e (patch)
treeac390cb5f44f1d878f72760c89d8ee01f583e939 /lib/utils.js
parent5756d04533a69d93091dcbb469d83da6b55456bc (diff)
downloadcoinos-server-0559a382066722b794e1aaaafbb24266c7302f9e.tar.gz
coinos-server-0559a382066722b794e1aaaafbb24266c7302f9e.zip
strip spaces from usernames
Diffstat (limited to 'lib/utils.js')
-rw-r--r--lib/utils.js18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/utils.js b/lib/utils.js
index ae794a5e..05819ecb 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -4,7 +4,7 @@ import config from "$config";
export const nada = () => {};
-export const sleep = (n) => new Promise((r) => setTimeout(r, n));
+export const sleep = n => new Promise(r => setTimeout(r, n));
export const wait = async (f, s = 300, n = 50) => {
let i = 0;
while (!(await f()) && i < s) (await sleep(n)) && i++;
@@ -13,17 +13,17 @@ export const wait = async (f, s = 300, n = 50) => {
};
export const prod = process.env.NODE_ENV === "production";
-export const fail = (msg) => {
+export const fail = msg => {
throw new Error(msg);
};
export const bail = (res, msg) => res.code(500).send(msg);
export const SATS = 100000000;
-export const sats = (n) => Math.round(n * SATS);
-export const btc = (n) => parseFloat((n / SATS).toFixed(8));
+export const sats = n => Math.round(n * SATS);
+export const btc = n => parseFloat((n / SATS).toFixed(8));
-export const uniq = (a, k) => [...new Map(a.map((x) => [k(x), x])).values()];
+export const uniq = (a, k) => [...new Map(a.map(x => [k(x), x])).values()];
export const pick = (O, K) =>
K.reduce((o, k) => (typeof O[k] !== "undefined" && (o[k] = O[k]), o), {});
@@ -53,5 +53,11 @@ export const fields = [
"haspin",
"profile",
"prompt",
- "banner",
+ "banner"
];
+
+export const getUser = async username => {
+ username = username.replace(/\s/g, "").toLowerCase()
+ let uid = await g(`user:${username}`);
+ return g(`user:${uid}`);
+};