aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Barratt <[email protected]>2023-02-28 12:20:10 -0800
committerJohn Barratt <[email protected]>2023-02-28 12:20:10 -0800
commit58e996a4ac227162f171e84530fe898cb504e045 (patch)
treeebc59d724acfcca6298bddb540811b7413d15980
parent6f5ffb59b83fb57546c46df6a610b8efaf1252cf (diff)
downloadcoinos-server-58e996a4ac227162f171e84530fe898cb504e045.tar.gz
coinos-server-58e996a4ac227162f171e84530fe898cb504e045.zip
add db connect try catch and commit before pull
-rw-r--r--index.js1
-rw-r--r--lib/db.js7
-rw-r--r--lib/locations.js2
-rw-r--r--package.json2
-rw-r--r--pnpm-lock.yaml31
-rw-r--r--routes/email.js1
-rw-r--r--routes/requests.js4
-rw-r--r--routes/users.js10
8 files changed, 34 insertions, 24 deletions
diff --git a/index.js b/index.js
index 51866cda..f1d35cc5 100644
--- a/index.js
+++ b/index.js
@@ -1,3 +1,4 @@
+
import app from "$lib/app";
import { auth, optional } from "$lib/auth";
diff --git a/lib/db.js b/lib/db.js
index 94538abb..7b7fefdb 100644
--- a/lib/db.js
+++ b/lib/db.js
@@ -3,7 +3,12 @@ import { sleep } from "$lib/utils";
import { createClient } from "redis";
export const db = createClient({ url: config.db });
-await db.connect();
+try {
+ await db.connect();
+ console.log("CONNECTED")
+} catch (e) {
+ console.log("FAILED CONNECTION")
+}
export default db;
export let g = async k => {
diff --git a/lib/locations.js b/lib/locations.js
index 39883555..be2df811 100644
--- a/lib/locations.js
+++ b/lib/locations.js
@@ -10,7 +10,7 @@ export let getLocations = async () => {
locations = locations.filter(
l => l["osm_json"].tags && l["osm_json"].tags["payment:coinos"] === "yes"
);
-
+
await s("locations", locations);
} catch (e) {}
diff --git a/package.json b/package.json
index 0ee4096e..10fe2401 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,7 @@
"@fastify/secure-session": "^5.2.0",
"@fastify/static": "^6.5.0",
"@fastify/websocket": "^7.0.1",
- "bcrypt": "^5.0.0",
+ "bcrypt": "^5.1.0",
"bech32": "^2.0.0",
"clightning-client": "^0.1.2",
"date-fns": "^2.21.3",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 9715cbc5..a44b2cbe 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -6,7 +6,7 @@ specifiers:
'@fastify/secure-session': ^5.2.0
'@fastify/static': ^6.5.0
'@fastify/websocket': ^7.0.1
- bcrypt: ^5.0.0
+ bcrypt: ^5.1.0
bech32: ^2.0.0
clightning-client: ^0.1.2
date-fns: ^2.21.3
@@ -184,12 +184,12 @@ packages:
detect-libc: 2.0.1
https-proxy-agent: 5.0.1
make-dir: 3.1.0
- node-fetch: 2.6.7
+ node-fetch: 2.6.9
nopt: 5.0.0
npmlog: 5.0.1
rimraf: 3.0.2
semver: 7.3.8
- tar: 6.1.11
+ tar: 6.1.13
transitivePeerDependencies:
- encoding
- supports-color
@@ -1153,7 +1153,7 @@ packages:
resolution: {integrity: sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==}
engines: {node: '>= 8'}
dependencies:
- minipass: 3.3.4
+ minipass: 3.3.6
dev: false
/fs.realpath/1.0.0:
@@ -1672,18 +1672,23 @@ packages:
resolution: {integrity: sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==}
dev: false
- /minipass/3.3.4:
- resolution: {integrity: sha512-I9WPbWHCGu8W+6k1ZiGpPu0GkoKBeorkfKNuAFBNS1HNFJvke82sxvI5bzcCNpWPorkOO5QQ+zomzzwRxejXiw==}
+ /minipass/3.3.6:
+ resolution: {integrity: sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==}
engines: {node: '>=8'}
dependencies:
yallist: 4.0.0
dev: false
+ /minipass/4.2.0:
+ resolution: {integrity: sha512-ExlilAIS7zJ2EWUMaVXi14H+FnZ18kr17kFkGemMqBx6jW0m8P6XfqwYVPEG53ENlgsED+alVP9ZxC3JzkK23Q==}
+ engines: {node: '>=8'}
+ dev: false
+
/minizlib/2.1.2:
resolution: {integrity: sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==}
engines: {node: '>= 8'}
dependencies:
- minipass: 3.3.4
+ minipass: 3.3.6
yallist: 4.0.0
dev: false
@@ -1747,8 +1752,8 @@ packages:
resolution: {integrity: sha512-CvkDw2OEnme7ybCykJpVcKH+uAOLV2qLqiyla128dN9TkEWfrYmxG6C2boDe5KcNQqZF3orkqzGgOMvZ/JNekA==}
dev: false
- /node-fetch/2.6.7:
- resolution: {integrity: sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==}
+ /node-fetch/2.6.9:
+ resolution: {integrity: sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==}
engines: {node: 4.x || >=6.0.0}
peerDependencies:
encoding: ^0.1.0
@@ -2495,13 +2500,13 @@ packages:
readable-stream: 3.6.0
dev: false
- /tar/6.1.11:
- resolution: {integrity: sha512-an/KZQzQUkZCkuoAA64hM92X0Urb6VpRhAFllDzz44U2mcD5scmT3zBc4VgVpkugF580+DQn8eAFSyoQt0tznA==}
- engines: {node: '>= 10'}
+ /tar/6.1.13:
+ resolution: {integrity: sha512-jdIBIN6LTIe2jqzay/2vtYLlBHa3JF42ot3h1dW8Q0PaAG4v8rm0cvpVePtau5C6OKXGGcgO9q2AMNSWxiLqKw==}
+ engines: {node: '>=10'}
dependencies:
chownr: 2.0.0
fs-minipass: 2.1.0
- minipass: 3.3.4
+ minipass: 4.2.0
minizlib: 2.1.2
mkdirp: 1.0.4
yallist: 4.0.0
diff --git a/routes/email.js b/routes/email.js
index 529307e6..6b2806a4 100644
--- a/routes/email.js
+++ b/routes/email.js
@@ -2,6 +2,7 @@ import config from "$config";
export default {
async send({ body }, res) {
+
try {
let postmark = await import("postmark");
let client = new postmark.ServerClient(config.postmark);
diff --git a/routes/requests.js b/routes/requests.js
index 11bf9a36..1b758dc3 100644
--- a/routes/requests.js
+++ b/routes/requests.js
@@ -16,11 +16,9 @@ export default {
async list({ user: { id } }, res) {
try {
const day = new Date(new Date().setDate(new Date().getDate() - 1));
-
let requests = await db.lRange(`${id}:requests`, 0, -1);
-
requests = await Promise.all(requests.map(id => g(`request:${id}`)));
-
+
requests = await Promise.all(
requests.map(async r => {
r.requester = await g(`user:${r.requester_id}`);
diff --git a/routes/users.js b/routes/users.js
index 2b8be4ab..c399b286 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -21,8 +21,9 @@ let { classic } = config;
export default {
upload,
-
+
async me({ user }, res) {
+
try {
user.balance = await g(`balance:${user.id}`);
user.prompt = !!user.prompt;
@@ -196,6 +197,7 @@ export default {
let user = await g(`user:${uid}`);
if (classic && !(user && user.migrated)) {
+
uid = user ? user.id : v4();
try {
@@ -262,7 +264,6 @@ export default {
if (!(u && u.id)) continue;
n.ref = u.id;
}
-
await s(`payment:${n.id}`, n);
await db.lPush(`${uid}:payments`, n.id);
}
@@ -272,7 +273,6 @@ export default {
console.log(e);
}
}
-
if (
!user ||
(user.password &&
@@ -284,7 +284,7 @@ export default {
warn("invalid username or password attempt", username);
return res.code(401).send({});
}
-
+
if (
user.twofa &&
(typeof twofa === "undefined" ||
@@ -292,7 +292,7 @@ export default {
) {
return res.code(401).send("2fa required");
}
-
+
l(
"login",
username,