From c0a7362226e57d81a57a03f531b8c16f3b9f661a Mon Sep 17 00:00:00 2001 From: MasterDraco Date: Mon, 10 Mar 2025 17:25:25 +0000 Subject: [PATCH] Fix fs references in server.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Updated all fs.readFile, fs.writeFile, fs.mkdir and other fs calls to use fsPromises instead - Resolved conflict between renamed fs import and function calls - Ensures consistent use of Promise-based fs API throughout the codebase 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- server.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/server.js b/server.js index 2fb0a24..56a442b 100644 --- a/server.js +++ b/server.js @@ -216,7 +216,7 @@ async function loadConfig() { try { // Try to read existing config from primary location console.log(`Trying to load config from: ${DEFAULT_CONFIG_PATH}`); - const configData = await fs.readFile(DEFAULT_CONFIG_PATH, 'utf8'); + const configData = await fsPromises.readFile(DEFAULT_CONFIG_PATH, 'utf8'); const loadedConfig = JSON.parse(configData); // Use recursive merge function to merge configs @@ -237,7 +237,7 @@ async function loadConfig() { console.log(`Config not found at ${DEFAULT_CONFIG_PATH}, trying fallback location...`); try { - const fallbackData = await fs.readFile(FALLBACK_CONFIG_PATH, 'utf8'); + const fallbackData = await fsPromises.readFile(FALLBACK_CONFIG_PATH, 'utf8'); const fallbackConfig = JSON.parse(fallbackData); // Merge configs @@ -252,8 +252,8 @@ async function loadConfig() { // Try to save to primary location, but don't fail if we can't try { // Create directory if it doesn't exist - await fs.mkdir(path.dirname(DEFAULT_CONFIG_PATH), { recursive: true }); - await fs.writeFile(DEFAULT_CONFIG_PATH, JSON.stringify(mergedConfig, null, 2), 'utf8'); + await fsPromises.mkdir(path.dirname(DEFAULT_CONFIG_PATH), { recursive: true }); + await fsPromises.writeFile(DEFAULT_CONFIG_PATH, JSON.stringify(mergedConfig, null, 2), 'utf8'); console.log(`Migrated config from ${FALLBACK_CONFIG_PATH} to ${DEFAULT_CONFIG_PATH}`); } catch (saveError) { console.warn(`Could not save config to ${DEFAULT_CONFIG_PATH}: ${saveError.message}`); @@ -269,15 +269,15 @@ async function loadConfig() { // Try to save to primary location first try { - await fs.mkdir(path.dirname(DEFAULT_CONFIG_PATH), { recursive: true }); - await fs.writeFile(DEFAULT_CONFIG_PATH, JSON.stringify(defaultConfig, null, 2), 'utf8'); + await fsPromises.mkdir(path.dirname(DEFAULT_CONFIG_PATH), { recursive: true }); + await fsPromises.writeFile(DEFAULT_CONFIG_PATH, JSON.stringify(defaultConfig, null, 2), 'utf8'); console.log(`Created default config at ${DEFAULT_CONFIG_PATH}`); } catch (saveError) { console.warn(`Could not save config to ${DEFAULT_CONFIG_PATH}: ${saveError.message}`); console.warn('Saving to fallback location instead'); // Save to fallback location instead - await fs.writeFile(FALLBACK_CONFIG_PATH, JSON.stringify(defaultConfig, null, 2), 'utf8'); + await fsPromises.writeFile(FALLBACK_CONFIG_PATH, JSON.stringify(defaultConfig, null, 2), 'utf8'); console.log(`Created default config at ${FALLBACK_CONFIG_PATH}`); } @@ -352,8 +352,8 @@ async function saveConfig(config) { // Always try to save to the primary config location first try { // Make sure directory exists - await fs.mkdir(path.dirname(DEFAULT_CONFIG_PATH), { recursive: true }); - await fs.writeFile(DEFAULT_CONFIG_PATH, JSON.stringify(config, null, 2), 'utf8'); + await fsPromises.mkdir(path.dirname(DEFAULT_CONFIG_PATH), { recursive: true }); + await fsPromises.writeFile(DEFAULT_CONFIG_PATH, JSON.stringify(config, null, 2), 'utf8'); console.log(`Configuration saved to ${DEFAULT_CONFIG_PATH}`); return; } catch (primaryError) { @@ -361,7 +361,7 @@ async function saveConfig(config) { console.warn('Trying fallback location...'); // If we couldn't save to the primary location, try the fallback - await fs.writeFile(FALLBACK_CONFIG_PATH, JSON.stringify(config, null, 2), 'utf8'); + await fsPromises.writeFile(FALLBACK_CONFIG_PATH, JSON.stringify(config, null, 2), 'utf8'); console.log(`Configuration saved to fallback location: ${FALLBACK_CONFIG_PATH}`); } } catch (error) { @@ -387,8 +387,8 @@ async function startServer() { config.securitySettings?.sslKeyPath) { try { const sslOptions = { - key: await fs.readFile(config.securitySettings.sslKeyPath), - cert: await fs.readFile(config.securitySettings.sslCertPath) + key: await fsPromises.readFile(config.securitySettings.sslKeyPath), + cert: await fsPromises.readFile(config.securitySettings.sslCertPath) }; server = https.createServer(sslOptions, app); @@ -1087,17 +1087,17 @@ async function getMediaLibrary(searchQuery) { try { // Check if directory exists - await fs.access(destinationPath); + await fsPromises.access(destinationPath); // Get directory listing - const files = await fs.readdir(destinationPath, { withFileTypes: true }); + const files = await fsPromises.readdir(destinationPath, { withFileTypes: true }); // Process each file/directory for (const file of files) { const fullPath = path.join(destinationPath, file.name); try { - const stats = await fs.stat(fullPath); + const stats = await fsPromises.stat(fullPath); // Create an item object const item = {