godprotocol 2.2.81 → 2.2.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "godprotocol",
3
- "version": "2.2.81",
3
+ "version": "2.2.84",
4
4
  "description": "A distributed computing environment for Web 4.0 — integrating AI, decentralisation, and virtual computation.",
5
5
  "main": "Index.js",
6
6
  "type": "module",
@@ -33,6 +33,7 @@
33
33
  "homepage": "https://github.com/immanuel-savvy/GodProtocol#readme",
34
34
  "dependencies": {
35
35
  "aircode4": "latest",
36
+ "busboy": "^1.6.0",
36
37
  "generalised-datastore": "latest",
37
38
  "@godprotocol/repositories": "^1.1.27"
38
39
  },
@@ -174,7 +174,7 @@ class Headers extends Services {
174
174
  headers["authorization"] = `Bearer ${authorization}`;
175
175
  }
176
176
 
177
- let third_party = xplatform === this.platform_uri;
177
+ let third_party = xplatform !== this.platform_uri;
178
178
  let res = await fetch(
179
179
  `${gp_services.profile}/${third_party ? "third_party_me" : "me"}`,
180
180
  {
@@ -0,0 +1,42 @@
1
+ import Busboy from "busboy";
2
+ import fs from "fs";
3
+ import path from "path";
4
+
5
+ const parseMultipart = (req, gp) => {
6
+ return new Promise((resolve, reject) => {
7
+ const busboy = Busboy({ headers: req.headers });
8
+
9
+ const fields = {};
10
+ let filePath = null;
11
+
12
+ const uploadDir = `./${gp.static_path.slice(1)}/uploads`;
13
+ if (!fs.existsSync(uploadDir)) {
14
+ fs.mkdirSync(uploadDir, { recursive: true });
15
+ }
16
+
17
+ busboy.on("file", (name, file, info) => {
18
+ const filename = `${Date.now()}-${info.filename}`;
19
+ filePath = path.join(uploadDir, filename);
20
+
21
+ const stream = fs.createWriteStream(filePath);
22
+ file.pipe(stream);
23
+ });
24
+
25
+ busboy.on("field", (name, value) => {
26
+ fields[name] = value;
27
+ });
28
+
29
+ busboy.on("finish", () => {
30
+ resolve({
31
+ ...fields,
32
+ file_path: filePath,
33
+ });
34
+ });
35
+
36
+ busboy.on("error", reject);
37
+
38
+ req.pipe(busboy);
39
+ });
40
+ };
41
+
42
+ export default parseMultipart;
@@ -1,3 +1,4 @@
1
+ import parseMultipart from "godprotocol/server/parse_multipart_data.js";
1
2
  import serveStaticFile from "godprotocol/server/serve_static_file.js";
2
3
 
3
4
  const getBody = (req) => {
@@ -131,8 +132,14 @@ const version_middleware = async (req, res, routers) => {
131
132
 
132
133
  body = Object.fromEntries(url.searchParams.entries());
133
134
  } else {
134
- error_stage = "Body Parser";
135
- body = await getBody(req);
135
+ const contentType = req.headers["content-type"] || "";
136
+
137
+ if (contentType.includes("multipart/form-data")) {
138
+ body = await parseMultipart(req, routers.gp);
139
+ } else {
140
+ error_stage = "Body Parser";
141
+ body = await getBody(req);
142
+ }
136
143
  }
137
144
 
138
145
  if (versionRouter.config?.is_old) {