Skip to content

Commit 5aaa628

Browse files
committed
fix 502 errors
1 parent 01ecc7c commit 5aaa628

File tree

3 files changed

+27
-23
lines changed

3 files changed

+27
-23
lines changed

backend/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "minter-dapp-backend",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "Generate an NFT collection and deploy a minting dapp easy!!",
55
"main": "index.js",
66
"bin": "index.js",
@@ -46,6 +46,7 @@
4646
"dotenv": "^16.0.0",
4747
"form-data": "^4.0.0",
4848
"gif-encoder-2": "^1.0.5",
49+
"graceful-fs": "^4.2.9",
4950
"node-fetch": "^2.6.6",
5051
"puppeteer": "^13.4.1",
5152
"puppeteer-extra": "^3.2.3",

backend/utils/nftport/uploadMetas.js

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const FormData = require("form-data");
22
const path = require("path");
33
const basePath = process.cwd();
4-
const fs = require("fs");
4+
const fs = require("graceful-fs");
55

6-
const { fetchWithRetry } = require(`${basePath}/utils/functions/fetchWithRetry.js`);
6+
const { fetchNoRetry } = require(`${basePath}/utils/functions/fetchWithRetry.js`);
77

88
const { GENERIC } = require(`${basePath}/src/config.js`);
99

@@ -16,29 +16,37 @@ if (!fs.existsSync(path.join(`${basePath}/build`, "/ipfsMetas"))) {
1616
let readDir = `${basePath}/build/json`;
1717
let writeDir = `${basePath}/build/ipfsMetas`;
1818

19-
async function main() {
20-
console.log(`Starting upload of metadata...`);
19+
function getFileStreamForJSONFiles() {
20+
const jsonArray = [];
2121
const files = fs.readdirSync(readDir);
2222
files.sort(function (a, b) {
2323
return a.split(".")[0] - b.split(".")[0];
2424
});
25-
const formData = new FormData();
26-
27-
for (const file of files) {
28-
if (regex.test(file)) {
29-
const fileStream = fs.createReadStream(`${readDir}/${file}`);
30-
formData.append("metadata_files", fileStream);
31-
}
32-
}
25+
files.forEach((file) => {
26+
if (!regex.test(file)) return;
27+
const fileData = fs.createReadStream(path.join(readDir, file));
28+
jsonArray.push(fileData);
29+
});
30+
return jsonArray;
31+
}
3332

33+
async function main() {
34+
console.log(`Starting upload of metadata...`);
3435
try {
36+
const metadataFileStreams = getFileStreamForJSONFiles();
37+
const formData = new FormData();
38+
metadataFileStreams.forEach((file) => {
39+
formData.append("metadata_files", file);
40+
});
41+
3542
const url = "https://api.nftport.xyz/v0/metadata/directory";
3643
const options = {
3744
method: "POST",
3845
headers: {},
3946
body: formData,
4047
};
41-
const response = await fetchWithRetry(url, options);
48+
const response = await fetchNoRetry(url, options);
49+
4250
fs.writeFileSync(
4351
`${writeDir}/_ipfsMetasResponse.json`,
4452
JSON.stringify(response, null, 2)
@@ -81,7 +89,7 @@ async function main() {
8189
},
8290
body: JSON.stringify(genericObject),
8391
};
84-
const response = await fetchWithRetry(url, options);
92+
const response = await fetchNoRetry(url, options);
8593
fs.writeFileSync(uploadedMeta, JSON.stringify(response, null, 2));
8694
console.log(`Generic metadata uploaded!`);
8795
} catch (err) {

package.json

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
{
22
"name": "minter-dapp",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "Generate an NFT collection and deploy a minting dapp easy!!",
5-
"scripts": {
6-
7-
},
5+
"scripts": {},
86
"author": "Jesse Hall (codeSTACKr)",
9-
"license": "MIT",
10-
"dependencies": {
11-
12-
}
7+
"license": "MIT"
138
}

0 commit comments

Comments
 (0)