diff options
| author | Adam Soltys <[email protected]> | 2024-01-09 23:10:35 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-01-09 23:10:39 -0800 |
| commit | 7a84d2555ffabbe29b23cf6e5035b6a4be8b9eb6 (patch) | |
| tree | 9fe2b7d523bbfe34176f115cb6823403fef1f802 /lib/utils.js | |
| parent | e06878e18fc33e392fd16b76d1ab9f25f8bc7fbe (diff) | |
| download | coinos-server-7a84d2555ffabbe29b23cf6e5035b6a4be8b9eb6.tar.gz coinos-server-7a84d2555ffabbe29b23cf6e5035b6a4be8b9eb6.zip | |
remove users from archive once migrated
Diffstat (limited to 'lib/utils.js')
| -rw-r--r-- | lib/utils.js | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/lib/utils.js b/lib/utils.js index 53ed2277..e6aba14a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -3,32 +3,33 @@ import store from "$lib/store"; import { g } from "$lib/db"; import config from "$config"; -export const nada = () => {}; +export let fail = (msg) => { + throw new Error(msg); +}; + +export let nada = () => {}; -export const sleep = (n) => new Promise((r) => setTimeout(r, n)); -export const wait = async (f, s = 300, n = 50) => { +export let sleep = (n) => new Promise((r) => setTimeout(r, n)); +export let wait = async (f, s = 300, n = 50) => { let i = 0; while (!(await f()) && i < s) (await sleep(n)) && i++; - if (i >= s) throw new Error("timeout"); + if (i >= s) fail("timeout"); return f(); }; -export const prod = process.env.NODE_ENV === "production"; -export const fail = (msg) => { - throw new Error(msg); -}; +export let prod = process.env.NODE_ENV === "production"; -export const bail = (res, msg) => res.code(500).send(msg); +export let 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 let SATS = 100000000; +export let sats = (n) => Math.round(n * SATS); +export let btc = (n) => parseFloat((n / SATS).toFixed(8)); -export const uniq = (a, k) => [...new Map(a.map((x) => [k(x), x])).values()]; -export const pick = (O, K) => +export let uniq = (a, k) => [...new Map(a.map((x) => [k(x), x])).values()]; +export let pick = (O, K) => K.reduce((o, k) => (typeof O[k] !== "undefined" && (o[k] = O[k]), o), {}); -export const bip21 = (address, { amount, memo, tip, type }) => { +export let bip21 = (address, { amount, memo, tip, type }) => { if (!(amount || memo)) return address; let network = { liquid: "liquidnetwork", bitcoin: "bitcoin" }[type]; @@ -44,7 +45,7 @@ export const bip21 = (address, { amount, memo, tip, type }) => { return `${network}:${address}?${url.toString()}`; }; -export const fields = [ +export let fields = [ "cipher", "pubkey", "password", @@ -64,9 +65,6 @@ export const fields = [ "banner", ]; -export const getUser = async (username) => { - username = username.replace(/\s/g, "").toLowerCase(); - let uid = await g(`user:${username}`); - if (!uid) await migrate(username); - return g(`user:${uid}`); +export let getUser = async (username) => { + return migrate(username); }; |
