plsgivemeachane commited on
Commit
c273984
·
1 Parent(s): 9787a3e

Update database requests

Browse files
Files changed (5) hide show
  1. README.md +45 -1
  2. index.js +33 -91
  3. package-lock.json +61 -32
  4. package.json +3 -2
  5. prisma/bruh.txt +0 -22
README.md CHANGED
@@ -8,4 +8,48 @@ pinned: false
8
  license: mit
9
  ---
10
 
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  license: mit
9
  ---
10
 
11
+ # Bee3HiveAPI
12
+
13
+ 🏢 A robust API for managing and interacting with the Bee3Hive system.
14
+
15
+ ## Overview
16
+
17
+ Bee3HiveAPI is a Docker-based application that provides a comprehensive interface for the Bee3Hive ecosystem. It offers functionalities for data management, user interactions, and system operations within the Bee3Hive platform.
18
+
19
+ ## Features
20
+
21
+ - Docker-based deployment for easy setup and scalability
22
+ - RESTful API endpoints for Bee3Hive operations
23
+ - Secure authentication and authorization
24
+ - Data management and retrieval capabilities
25
+ - Integration with Bee3Hive core functionalities
26
+
27
+ ## Getting Started
28
+
29
+ 1. Clone the repository
30
+ 2. Install Docker and Docker Compose
31
+ 3. Build and run the Docker container:
32
+ ```
33
+ docker-compose up --build
34
+ ```
35
+ 4. Access the API at `http://localhost:<port>`
36
+
37
+ ## API Documentation
38
+
39
+ Detailed API documentation is available at `/docs` endpoint after starting the server.
40
+
41
+ ## License
42
+
43
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
44
+
45
+ ## Contributing
46
+
47
+ Contributions are welcome! Please read our [Contributing Guidelines](CONTRIBUTING.md) for more information.
48
+
49
+ ## Support
50
+
51
+ For support or questions, please open an issue in the GitHub repository or contact the maintainers.
52
+
53
+ ---
54
+
55
+ Powered by [Hugging Face](https://huggingface.co/)
index.js CHANGED
@@ -4,27 +4,14 @@ const { sha } = require("sha256quanvn");
4
  const { PrismaClient } = require("@prisma/client");
5
  const multer = require("multer");
6
  const fs = require("fs");
7
- const path = require("path");
8
- const streamToBlob = require("stream-to-blob");
9
  const statusMonitor = require("express-status-monitor")({
10
  path: "/bee3hivestatuspagethatnoonewillrememberthisurl",
11
  title: "Bee3Hive API Status",
12
  });
13
  const cors = require("cors");
14
- const { resolveSoa } = require("dns");
15
- const prisma = new PrismaClient();
16
  const app = express();
17
- // const http = require("http");
18
- // const server = http.createServer(app);
19
- // const { type } = require("os");
20
- // const io = require("socket.io")(server, {
21
- // maxHttpBufferSize: 1e8,
22
- // rejectUnauthorized: false,
23
- // cors: {
24
- // origin: "*",
25
- // methods: ["GET", "POST"],
26
- // },
27
- // });
28
 
29
  const SALT = process.env.PRIVATE_KEY;
30
 
@@ -63,6 +50,14 @@ function uniq(a) {
63
  }
64
 
65
 
 
 
 
 
 
 
 
 
66
  const generateJWT = async (id) => {
67
  const header = {
68
  alg: "SHA256QUANVN",
@@ -71,7 +66,7 @@ const generateJWT = async (id) => {
71
 
72
  const payload = {
73
  id: id,
74
- exp: Date.now() + 3600000 * 24, // 1 days
75
  };
76
 
77
  await prisma.users.update({
@@ -158,81 +153,6 @@ const upload = multer({
158
 
159
  const current_connections = [];
160
 
161
- // io.on("connection", (socket) => {
162
- // info("A IPFS Services connected id=" + socket.id);
163
-
164
- // socket.on("availible", () => {
165
- // info("Services id=" + socket.id + " availible");
166
- // current_connections.push(socket.id);
167
- // });
168
-
169
- // socket.emit("health_check");
170
-
171
- // const interval = setInterval(() => {
172
- // //* Health check
173
- // info("Send health_check");
174
- // socket.emit("health_check");
175
- // }, 60000);
176
-
177
- // socket.on("health", (data) => {
178
- // info(
179
- // "Services id=" +
180
- // socket.id +
181
- // " " +
182
- // data.healthy +
183
- // " availible=" +
184
- // data.availible +
185
- // " ping=" +
186
- // Math.abs(Date.now() - data.now) +
187
- // "ms"
188
- // ); //* Check if services is healthy
189
- // });
190
-
191
- // socket.on("unavailible", () => {
192
- // info("Services id=" + socket.id + " unavailible");
193
- // for (let i = 0; i < current_connections.length; i++) {
194
- // if (current_connections[i] === socket.id) {
195
- // current_connections.splice(i, 1);
196
- // break;
197
- // }
198
- // }
199
- // });
200
-
201
- // socket.on("delete", async (data) => {
202
- // info("File Successfully uploaded, writing record");
203
- // console.log(data); //* The data is comsumed by the IPFS services
204
-
205
- // try {
206
- // await prisma.storage.create({
207
- // data: {
208
- // handle: data.handle,
209
- // username: data.username,
210
- // CID: data.ipfs[0].Hash,
211
- // dir: data.directory,
212
- // },
213
- // });
214
- // } catch (e) {
215
- // warn("Creating record fail");
216
- // }
217
-
218
- // //* Remove the initial file
219
- // fs.unlinkSync("uploads/" + data.relative_path);
220
- // info(`File ${data.relative_path} deleted`);
221
- // });
222
-
223
- // socket.on("disconnect", () => {
224
- // info("A IPFS Services disconnected");
225
- // clearInterval(interval);
226
- // //* Removing services when disconnected (died)
227
- // for (let i = 0; i < current_connections.length; i++) {
228
- // if (current_connections[i] === socket.id) {
229
- // current_connections.splice(i, 1);
230
- // break;
231
- // }
232
- // }
233
- // });
234
- // });
235
-
236
  app.use(
237
  cors({
238
  origin: "*",
@@ -251,6 +171,28 @@ app.get(
251
  statusMonitor.pageRoute
252
  );
253
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
  app.post("/auth/email/register", async (req, res) => {
255
  let { username, email, password } = req.body;
256
 
 
4
  const { PrismaClient } = require("@prisma/client");
5
  const multer = require("multer");
6
  const fs = require("fs");
 
 
7
  const statusMonitor = require("express-status-monitor")({
8
  path: "/bee3hivestatuspagethatnoonewillrememberthisurl",
9
  title: "Bee3Hive API Status",
10
  });
11
  const cors = require("cors");
12
+ const { withAccelerate } = require("@prisma/extension-accelerate")
13
+ const prisma = new PrismaClient().$extends(withAccelerate())
14
  const app = express();
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  const SALT = process.env.PRIVATE_KEY;
17
 
 
50
  }
51
 
52
 
53
+ /**
54
+ * Generates a new JSON Web Token for the given user ID, and returns it as a string.
55
+ *
56
+ * The token is valid for 1 day, and is signed with the server's private key.
57
+ *
58
+ * @param {number} id - The user's ID.
59
+ * @return {string} A new JSON Web Token, as a string.
60
+ */
61
  const generateJWT = async (id) => {
62
  const header = {
63
  alg: "SHA256QUANVN",
 
66
 
67
  const payload = {
68
  id: id,
69
+ exp: Date.now() + 3600000 * 24 * 7, // 7 days
70
  };
71
 
72
  await prisma.users.update({
 
153
 
154
  const current_connections = [];
155
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  app.use(
157
  cors({
158
  origin: "*",
 
171
  statusMonitor.pageRoute
172
  );
173
 
174
+ app.get("/bee3hive/internal/files/:node_id", async (req, res) => {
175
+ // TODO: Make database query for services
176
+ const node_id = req.params.node_id;
177
+ const record = await prisma.storage.findMany({
178
+ where: {
179
+ handle: node_id,
180
+ },
181
+ cacheStrategy: {
182
+ ttl: 60, //* 1 min
183
+ },
184
+ })
185
+
186
+ if(!record) {
187
+ res.sendStatus(404);
188
+ return;
189
+ }
190
+
191
+ res.send(record);
192
+ })
193
+
194
+ // TODO: Make database query for services
195
+
196
  app.post("/auth/email/register", async (req, res) => {
197
  let { username, email, password } = req.body;
198
 
package-lock.json CHANGED
@@ -10,7 +10,8 @@
10
  "license": "ISC",
11
  "dependencies": {
12
  "@huggingface/hub": "^0.15.1",
13
- "@prisma/client": "^5.18.0",
 
14
  "cors": "^2.8.5",
15
  "express": "^4.19.2",
16
  "express-status-monitor": "^1.3.4",
@@ -20,7 +21,7 @@
20
  "stream-to-blob": "^2.0.1"
21
  },
22
  "devDependencies": {
23
- "prisma": "^5.18.0"
24
  }
25
  },
26
  "node_modules/@huggingface/hub": {
@@ -41,9 +42,9 @@
41
  "integrity": "sha512-sCtp+A6sq6NXoUU7NXuXWoVNNjKddk1GTQIh3cJ6illF8S4zmFoerCVRvFf19BdgICGvF+RVZiv9sGGK9KRDTg=="
42
  },
43
  "node_modules/@prisma/client": {
44
- "version": "5.18.0",
45
- "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.18.0.tgz",
46
- "integrity": "sha512-BWivkLh+af1kqC89zCJYkHsRcyWsM8/JHpsDMM76DjP3ZdEquJhXa4IeX+HkWPnwJ5FanxEJFZZDTWiDs/Kvyw==",
47
  "hasInstallScript": true,
48
  "engines": {
49
  "node": ">=16.13"
@@ -58,48 +59,59 @@
58
  }
59
  },
60
  "node_modules/@prisma/debug": {
61
- "version": "5.18.0",
62
- "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.18.0.tgz",
63
- "integrity": "sha512-f+ZvpTLidSo3LMJxQPVgAxdAjzv5OpzAo/eF8qZqbwvgi2F5cTOI9XCpdRzJYA0iGfajjwjOKKrVq64vkxEfUw==",
64
  "devOptional": true
65
  },
66
  "node_modules/@prisma/engines": {
67
- "version": "5.18.0",
68
- "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.18.0.tgz",
69
- "integrity": "sha512-ofmpGLeJ2q2P0wa/XaEgTnX/IsLnvSp/gZts0zjgLNdBhfuj2lowOOPmDcfKljLQUXMvAek3lw5T01kHmCG8rg==",
70
  "devOptional": true,
71
  "hasInstallScript": true,
72
  "dependencies": {
73
- "@prisma/debug": "5.18.0",
74
- "@prisma/engines-version": "5.18.0-25.4c784e32044a8a016d99474bd02a3b6123742169",
75
- "@prisma/fetch-engine": "5.18.0",
76
- "@prisma/get-platform": "5.18.0"
77
  }
78
  },
79
  "node_modules/@prisma/engines-version": {
80
- "version": "5.18.0-25.4c784e32044a8a016d99474bd02a3b6123742169",
81
- "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.18.0-25.4c784e32044a8a016d99474bd02a3b6123742169.tgz",
82
- "integrity": "sha512-a/+LpJj8vYU3nmtkg+N3X51ddbt35yYrRe8wqHTJtYQt7l1f8kjIBcCs6sHJvodW/EK5XGvboOiwm47fmNrbgg==",
83
  "devOptional": true
84
  },
 
 
 
 
 
 
 
 
 
 
 
85
  "node_modules/@prisma/fetch-engine": {
86
- "version": "5.18.0",
87
- "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.18.0.tgz",
88
- "integrity": "sha512-I/3u0x2n31rGaAuBRx2YK4eB7R/1zCuayo2DGwSpGyrJWsZesrV7QVw7ND0/Suxeo/vLkJ5OwuBqHoCxvTHpOg==",
89
  "devOptional": true,
90
  "dependencies": {
91
- "@prisma/debug": "5.18.0",
92
- "@prisma/engines-version": "5.18.0-25.4c784e32044a8a016d99474bd02a3b6123742169",
93
- "@prisma/get-platform": "5.18.0"
94
  }
95
  },
96
  "node_modules/@prisma/get-platform": {
97
- "version": "5.18.0",
98
- "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.18.0.tgz",
99
- "integrity": "sha512-Tk+m7+uhqcKDgnMnFN0lRiH7Ewea0OEsZZs9pqXa7i3+7svS3FSCqDBCaM9x5fmhhkufiG0BtunJVDka+46DlA==",
100
  "devOptional": true,
101
  "dependencies": {
102
- "@prisma/debug": "5.18.0"
103
  }
104
  },
105
  "node_modules/@socket.io/component-emitter": {
@@ -781,6 +793,20 @@
781
  "node": ">= 0.6"
782
  }
783
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
784
  "node_modules/function-bind": {
785
  "version": "1.1.2",
786
  "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
@@ -1138,19 +1164,22 @@
1138
  }
1139
  },
1140
  "node_modules/prisma": {
1141
- "version": "5.18.0",
1142
- "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.18.0.tgz",
1143
- "integrity": "sha512-+TrSIxZsh64OPOmaSgVPH7ALL9dfU0jceYaMJXsNrTkFHO7/3RANi5K2ZiPB1De9+KDxCWn7jvRq8y8pvk+o9g==",
1144
  "devOptional": true,
1145
  "hasInstallScript": true,
1146
  "dependencies": {
1147
- "@prisma/engines": "5.18.0"
1148
  },
1149
  "bin": {
1150
  "prisma": "build/index.js"
1151
  },
1152
  "engines": {
1153
  "node": ">=16.13"
 
 
 
1154
  }
1155
  },
1156
  "node_modules/process-nextick-args": {
 
10
  "license": "ISC",
11
  "dependencies": {
12
  "@huggingface/hub": "^0.15.1",
13
+ "@prisma/client": "^5.19.0",
14
+ "@prisma/extension-accelerate": "^1.1.0",
15
  "cors": "^2.8.5",
16
  "express": "^4.19.2",
17
  "express-status-monitor": "^1.3.4",
 
21
  "stream-to-blob": "^2.0.1"
22
  },
23
  "devDependencies": {
24
+ "prisma": "^5.19.0"
25
  }
26
  },
27
  "node_modules/@huggingface/hub": {
 
42
  "integrity": "sha512-sCtp+A6sq6NXoUU7NXuXWoVNNjKddk1GTQIh3cJ6illF8S4zmFoerCVRvFf19BdgICGvF+RVZiv9sGGK9KRDTg=="
43
  },
44
  "node_modules/@prisma/client": {
45
+ "version": "5.19.0",
46
+ "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.19.0.tgz",
47
+ "integrity": "sha512-CzOpau+q1kEWQyoQMvlnXIHqPvwmWbh48xZ4n8KWbAql0p8PC0BIgSTYW5ncxXa4JSEff0tcoxSZB874wDstdg==",
48
  "hasInstallScript": true,
49
  "engines": {
50
  "node": ">=16.13"
 
59
  }
60
  },
61
  "node_modules/@prisma/debug": {
62
+ "version": "5.19.0",
63
+ "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.19.0.tgz",
64
+ "integrity": "sha512-+b/G0ubAZlrS+JSiDhXnYV5DF/aTJ3pinktkiV/L4TtLRLZO6SVGyFELgxBsicCTWJ2ZMu5vEV/jTtYCdjFTRA==",
65
  "devOptional": true
66
  },
67
  "node_modules/@prisma/engines": {
68
+ "version": "5.19.0",
69
+ "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.19.0.tgz",
70
+ "integrity": "sha512-UtW+0m4HYoRSSR3LoDGKF3Ud4BSMWYlLEt4slTnuP1mI+vrV3zaDoiAPmejdAT76vCN5UqnWURbkXxf66nSylQ==",
71
  "devOptional": true,
72
  "hasInstallScript": true,
73
  "dependencies": {
74
+ "@prisma/debug": "5.19.0",
75
+ "@prisma/engines-version": "5.19.0-31.5fe21811a6ba0b952a3bc71400666511fe3b902f",
76
+ "@prisma/fetch-engine": "5.19.0",
77
+ "@prisma/get-platform": "5.19.0"
78
  }
79
  },
80
  "node_modules/@prisma/engines-version": {
81
+ "version": "5.19.0-31.5fe21811a6ba0b952a3bc71400666511fe3b902f",
82
+ "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.19.0-31.5fe21811a6ba0b952a3bc71400666511fe3b902f.tgz",
83
+ "integrity": "sha512-GimI9aZIFy/yvvR11KfXRn3pliFn1QAkdebVlsXlnoh5uk0YhLblVmeYiHfsu+wDA7BeKqYT4sFfzg8mutzuWw==",
84
  "devOptional": true
85
  },
86
+ "node_modules/@prisma/extension-accelerate": {
87
+ "version": "1.1.0",
88
+ "resolved": "https://registry.npmjs.org/@prisma/extension-accelerate/-/extension-accelerate-1.1.0.tgz",
89
+ "integrity": "sha512-sESjhBZ4ywQjAVpKzsfhxyNu+9txIM5I6M1MPBaJBq/xDlqmniIAhlwIEt9KLtO80zqPxqbZYes18zrkgYqNiQ==",
90
+ "engines": {
91
+ "node": ">=16"
92
+ },
93
+ "peerDependencies": {
94
+ "@prisma/client": ">=4.16.1"
95
+ }
96
+ },
97
  "node_modules/@prisma/fetch-engine": {
98
+ "version": "5.19.0",
99
+ "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.19.0.tgz",
100
+ "integrity": "sha512-oOiPNtmJX0cP/ebu7BBEouJvCw8T84/MFD/Hf2zlqjxkK4ojl38bB9i9J5LAxotL6WlYVThKdxc7HqoWnPOhqQ==",
101
  "devOptional": true,
102
  "dependencies": {
103
+ "@prisma/debug": "5.19.0",
104
+ "@prisma/engines-version": "5.19.0-31.5fe21811a6ba0b952a3bc71400666511fe3b902f",
105
+ "@prisma/get-platform": "5.19.0"
106
  }
107
  },
108
  "node_modules/@prisma/get-platform": {
109
+ "version": "5.19.0",
110
+ "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.19.0.tgz",
111
+ "integrity": "sha512-s9DWkZKnuP4Y8uy6yZfvqQ/9X3/+2KYf3IZUVZz5OstJdGBJrBlbmIuMl81917wp5TuK/1k2TpHNCEdpYLPKmg==",
112
  "devOptional": true,
113
  "dependencies": {
114
+ "@prisma/debug": "5.19.0"
115
  }
116
  },
117
  "node_modules/@socket.io/component-emitter": {
 
793
  "node": ">= 0.6"
794
  }
795
  },
796
+ "node_modules/fsevents": {
797
+ "version": "2.3.3",
798
+ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
799
+ "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
800
+ "dev": true,
801
+ "hasInstallScript": true,
802
+ "optional": true,
803
+ "os": [
804
+ "darwin"
805
+ ],
806
+ "engines": {
807
+ "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
808
+ }
809
+ },
810
  "node_modules/function-bind": {
811
  "version": "1.1.2",
812
  "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
 
1164
  }
1165
  },
1166
  "node_modules/prisma": {
1167
+ "version": "5.19.0",
1168
+ "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.19.0.tgz",
1169
+ "integrity": "sha512-Pu7lUKpVyTx8cVwM26dYh8NdvMOkMnJXzE8L6cikFuR4JwyMU5NKofQkWyxJKlTT4fNjmcnibTvklV8oVMrn+g==",
1170
  "devOptional": true,
1171
  "hasInstallScript": true,
1172
  "dependencies": {
1173
+ "@prisma/engines": "5.19.0"
1174
  },
1175
  "bin": {
1176
  "prisma": "build/index.js"
1177
  },
1178
  "engines": {
1179
  "node": ">=16.13"
1180
+ },
1181
+ "optionalDependencies": {
1182
+ "fsevents": "2.3.3"
1183
  }
1184
  },
1185
  "node_modules/process-nextick-args": {
package.json CHANGED
@@ -11,7 +11,8 @@
11
  "description": "",
12
  "dependencies": {
13
  "@huggingface/hub": "^0.15.1",
14
- "@prisma/client": "^5.18.0",
 
15
  "cors": "^2.8.5",
16
  "express": "^4.19.2",
17
  "express-status-monitor": "^1.3.4",
@@ -21,6 +22,6 @@
21
  "stream-to-blob": "^2.0.1"
22
  },
23
  "devDependencies": {
24
- "prisma": "^5.18.0"
25
  }
26
  }
 
11
  "description": "",
12
  "dependencies": {
13
  "@huggingface/hub": "^0.15.1",
14
+ "@prisma/client": "^5.19.0",
15
+ "@prisma/extension-accelerate": "^1.1.0",
16
  "cors": "^2.8.5",
17
  "express": "^4.19.2",
18
  "express-status-monitor": "^1.3.4",
 
22
  "stream-to-blob": "^2.0.1"
23
  },
24
  "devDependencies": {
25
+ "prisma": "^5.19.0"
26
  }
27
  }
prisma/bruh.txt DELETED
@@ -1,22 +0,0 @@
1
- /// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
2
- /// This model contains row level security and requires additional setup for migrations. Visit https://pris.ly/d/row-level-security for more info.
3
- model Users {
4
- id BigInt @id @default(autoincrement())
5
- created_at DateTime @default(now()) @db.Timestamptz(6)
6
- username String @unique
7
- password_hash String
8
- email String? @unique
9
- phone String?
10
- last_login DateTime? @db.Time(6)
11
- }
12
-
13
- /// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
14
- /// This model contains row level security and requires additional setup for migrations. Visit https://pris.ly/d/row-level-security for more info.
15
- model Storage {
16
- id BigInt @id @default(autoincrement())
17
- created_at DateTime @default(now()) @db.Timestamptz(6)
18
- CID String @unique @default("CID")
19
- username String
20
- handle String
21
- dir String? @default("/")
22
- }