diff --git a/backend/package.json b/backend/package.json index 45763179c9..c207c37c03 100644 --- a/backend/package.json +++ b/backend/package.json @@ -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", @@ -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", diff --git a/backend/utils/nftport/uploadMetas.js b/backend/utils/nftport/uploadMetas.js index aafd1158f5..6f4248fe04 100644 --- a/backend/utils/nftport/uploadMetas.js +++ b/backend/utils/nftport/uploadMetas.js @@ -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`); @@ -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) @@ -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) { diff --git a/package.json b/package.json index 456f2c6f98..9fd381adfa 100644 --- a/package.json +++ b/package.json @@ -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" }