Fix: Use fs.promises for async file ops in admin domains route

Replaced callback-based fs methods with promise-based fsp methods to fix
the "cb argument must be of type function" error when adding domains.
This commit is contained in:
Raven Scott
2025-12-28 00:59:50 -05:00
parent 62ac5a4b50
commit 425b968db5
2 changed files with 5 additions and 3 deletions
@@ -1,4 +1,5 @@
const fs = require('fs');
const fsp = require('fs').promises;
const path = require('path');
const state = require('../../../infrastructure/state');
const { getAllEntries, getHashForDomain, doAutoVotes, getConsensusState, invalidateEntriesCache, removeOwnClaimAndVotes } = require('../../../core/core');
@@ -122,8 +123,8 @@ async function handleDomainsRoutes(req, res) {
}
let domains = [];
if (await fs.access(domainsFile).then(() => true).catch(() => false)) {
const parsed = JSON.parse(await fs.readFile(domainsFile, 'utf8'));
if (await fsp.access(domainsFile).then(() => true).catch(() => false)) {
const parsed = JSON.parse(await fsp.readFile(domainsFile, 'utf8'));
if (!Array.isArray(parsed)) {
logError('Admin', `Domains file does not contain an array, resetting to empty array`);
domains = [];
@@ -138,7 +139,7 @@ async function handleDomainsRoutes(req, res) {
} else {
domains.push({ domain: validation.domain, hash: validation.hash, ssl: ssl });
}
await fs.writeFile(domainsFile, JSON.stringify(domains, null, 2));
await fsp.writeFile(domainsFile, JSON.stringify(domains, null, 2));
// Note: IP assignment now happens automatically after consensus resolution
// See assignAllIPs() function for automatic IP assignment logic
logDebug('Admin', `Domain ${validation.domain} added - IP will be assigned automatically after consensus resolution`);
+1
View File
@@ -72,3 +72,4 @@ module.exports = {