From b85b84f4b97ff3c6a539ced9db0e455e0fb46ae1 Mon Sep 17 00:00:00 2001 From: Lightemerald Date: Fri, 19 May 2023 18:27:56 +0200 Subject: [PATCH] Fix file path issue. --- modules/accountManager.js | 9 +++++---- modules/microsoftHandler.js | 5 +++-- package-lock.json | 11 ++++++++++- package.json | 1 + 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/modules/accountManager.js b/modules/accountManager.js index bf97081..95ba8a8 100644 --- a/modules/accountManager.js +++ b/modules/accountManager.js @@ -1,20 +1,21 @@ const fs = require('fs'); +const path = require('path'); function batchAccounts(accounts, batchSize) { const sortedDir = '../accounts/sorted'; - if (!fs.existsSync(sortedDir)) { - fs.mkdirSync(sortedDir); + if (!fs.existsSync(path.join(__dirname, sortedDir))) { + fs.mkdirSync(path.join(__dirname, sortedDir)); } for (let i = 0; i < accounts.length; i += batchSize) { const batch = accounts.slice(i, i + batchSize); const batchNumber = Math.ceil((i + 1) / batchSize); const batchFilename = `${sortedDir}/batch${batchNumber}.json`; - fs.writeFileSync(batchFilename, JSON.stringify(batch, null, 2)); + fs.writeFileSync(path.join(__dirname, batchFilename), JSON.stringify(batch, null, 2)); } } -const accounts = require('../accounts/accounts.json'); +const accounts = require(path.join(__dirname, '../accounts/accounts.json')); batchAccounts(accounts, 6); module.exports = { batchAccounts }; \ No newline at end of file diff --git a/modules/microsoftHandler.js b/modules/microsoftHandler.js index 49027f4..9a23c1e 100644 --- a/modules/microsoftHandler.js +++ b/modules/microsoftHandler.js @@ -1,4 +1,5 @@ const fs = require('fs'); +const path = require('path'); const { By, Key, until } = require('selenium-webdriver'); const { createIdentity } = require('./identityHandler'); @@ -100,13 +101,13 @@ async function createAccount(driver) { let accounts = []; - if (fs.existsSync('../accounts/accounts.json')) { + if (fs.existsSync(path.join(__dirname, '../accounts/accounts.json'))) { const content = fs.readFileSync('accounts.json', 'utf8'); accounts = JSON.parse(content); } accounts.push(account); - fs.writeFileSync('../accounts/accounts.json', JSON.stringify(accounts)); + fs.writeFileSync(path.join(__dirname, '../accounts/accounts.json'), JSON.stringify(accounts)); console.log('Account saved to accounts.json, there are currently ' + accounts.length + ' accounts'); diff --git a/package-lock.json b/package-lock.json index 704816d..90c4a32 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "accountCreator", + "name": "mcr-account-creator-bot", "lockfileVersion": 3, "requires": true, "packages": { @@ -7,6 +7,7 @@ "dependencies": { "bluebird": "^3.7.2", "cron": "^2.3.0", + "dotenv": "^16.0.3", "faker": "^6.6.6", "imap": "^0.8.19", "mail-listener2": "^0.3.1", @@ -430,6 +431,14 @@ "url": "https://github.com/fb55/domutils?sponsor=1" } }, + "node_modules/dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", + "engines": { + "node": ">=12" + } + }, "node_modules/encoding": { "version": "0.1.13", "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.13.tgz", diff --git a/package.json b/package.json index 04d7f30..160a2f3 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "dependencies": { "bluebird": "^3.7.2", "cron": "^2.3.0", + "dotenv": "^16.0.3", "faker": "^6.6.6", "imap": "^0.8.19", "mail-listener2": "^0.3.1",