Skip to content

Commit

Permalink
fix 502 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
codeSTACKr committed Mar 31, 2022
1 parent 01ecc7c commit 5aaa628
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minter-dapp-backend",
"version": "0.0.1",
"version": "0.0.2",
"description": "Generate an NFT collection and deploy a minting dapp easy!!",
"main": "index.js",
"bin": "index.js",
Expand Down Expand Up @@ -46,6 +46,7 @@
"dotenv": "^16.0.0",
"form-data": "^4.0.0",
"gif-encoder-2": "^1.0.5",
"graceful-fs": "^4.2.9",
"node-fetch": "^2.6.6",
"puppeteer": "^13.4.1",
"puppeteer-extra": "^3.2.3",
Expand Down
36 changes: 22 additions & 14 deletions backend/utils/nftport/uploadMetas.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const FormData = require("form-data");
const path = require("path");
const basePath = process.cwd();
const fs = require("fs");
const fs = require("graceful-fs");

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

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

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

async function main() {
console.log(`Starting upload of metadata...`);
function getFileStreamForJSONFiles() {
const jsonArray = [];
const files = fs.readdirSync(readDir);
files.sort(function (a, b) {
return a.split(".")[0] - b.split(".")[0];
});
const formData = new FormData();

for (const file of files) {
if (regex.test(file)) {
const fileStream = fs.createReadStream(`${readDir}/${file}`);
formData.append("metadata_files", fileStream);
}
}
files.forEach((file) => {
if (!regex.test(file)) return;
const fileData = fs.createReadStream(path.join(readDir, file));
jsonArray.push(fileData);
});
return jsonArray;
}

async function main() {
console.log(`Starting upload of metadata...`);
try {
const metadataFileStreams = getFileStreamForJSONFiles();
const formData = new FormData();
metadataFileStreams.forEach((file) => {
formData.append("metadata_files", file);
});

const url = "https://api.nftport.xyz/v0/metadata/directory";
const options = {
method: "POST",
headers: {},
body: formData,
};
const response = await fetchWithRetry(url, options);
const response = await fetchNoRetry(url, options);

fs.writeFileSync(
`${writeDir}/_ipfsMetasResponse.json`,
JSON.stringify(response, null, 2)
Expand Down Expand Up @@ -81,7 +89,7 @@ async function main() {
},
body: JSON.stringify(genericObject),
};
const response = await fetchWithRetry(url, options);
const response = await fetchNoRetry(url, options);
fs.writeFileSync(uploadedMeta, JSON.stringify(response, null, 2));
console.log(`Generic metadata uploaded!`);
} catch (err) {
Expand Down
11 changes: 3 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
{
"name": "minter-dapp",
"version": "0.0.1",
"version": "0.0.2",
"description": "Generate an NFT collection and deploy a minting dapp easy!!",
"scripts": {

},
"scripts": {},
"author": "Jesse Hall (codeSTACKr)",
"license": "MIT",
"dependencies": {

}
"license": "MIT"
}

0 comments on commit 5aaa628

Please sign in to comment.