Fix fs references in server.js
- 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 <noreply@anthropic.com>
This commit is contained in:
parent
dd08278e28
commit
c0a7362226
30
server.js
30
server.js
@ -216,7 +216,7 @@ async function loadConfig() {
|
|||||||
try {
|
try {
|
||||||
// Try to read existing config from primary location
|
// Try to read existing config from primary location
|
||||||
console.log(`Trying to load config from: ${DEFAULT_CONFIG_PATH}`);
|
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);
|
const loadedConfig = JSON.parse(configData);
|
||||||
|
|
||||||
// Use recursive merge function to merge configs
|
// 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...`);
|
console.log(`Config not found at ${DEFAULT_CONFIG_PATH}, trying fallback location...`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const fallbackData = await fs.readFile(FALLBACK_CONFIG_PATH, 'utf8');
|
const fallbackData = await fsPromises.readFile(FALLBACK_CONFIG_PATH, 'utf8');
|
||||||
const fallbackConfig = JSON.parse(fallbackData);
|
const fallbackConfig = JSON.parse(fallbackData);
|
||||||
|
|
||||||
// Merge configs
|
// Merge configs
|
||||||
@ -252,8 +252,8 @@ async function loadConfig() {
|
|||||||
// Try to save to primary location, but don't fail if we can't
|
// Try to save to primary location, but don't fail if we can't
|
||||||
try {
|
try {
|
||||||
// Create directory if it doesn't exist
|
// Create directory if it doesn't exist
|
||||||
await fs.mkdir(path.dirname(DEFAULT_CONFIG_PATH), { recursive: true });
|
await fsPromises.mkdir(path.dirname(DEFAULT_CONFIG_PATH), { recursive: true });
|
||||||
await fs.writeFile(DEFAULT_CONFIG_PATH, JSON.stringify(mergedConfig, null, 2), 'utf8');
|
await fsPromises.writeFile(DEFAULT_CONFIG_PATH, JSON.stringify(mergedConfig, null, 2), 'utf8');
|
||||||
console.log(`Migrated config from ${FALLBACK_CONFIG_PATH} to ${DEFAULT_CONFIG_PATH}`);
|
console.log(`Migrated config from ${FALLBACK_CONFIG_PATH} to ${DEFAULT_CONFIG_PATH}`);
|
||||||
} catch (saveError) {
|
} catch (saveError) {
|
||||||
console.warn(`Could not save config to ${DEFAULT_CONFIG_PATH}: ${saveError.message}`);
|
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 to save to primary location first
|
||||||
try {
|
try {
|
||||||
await fs.mkdir(path.dirname(DEFAULT_CONFIG_PATH), { recursive: true });
|
await fsPromises.mkdir(path.dirname(DEFAULT_CONFIG_PATH), { recursive: true });
|
||||||
await fs.writeFile(DEFAULT_CONFIG_PATH, JSON.stringify(defaultConfig, null, 2), 'utf8');
|
await fsPromises.writeFile(DEFAULT_CONFIG_PATH, JSON.stringify(defaultConfig, null, 2), 'utf8');
|
||||||
console.log(`Created default config at ${DEFAULT_CONFIG_PATH}`);
|
console.log(`Created default config at ${DEFAULT_CONFIG_PATH}`);
|
||||||
} catch (saveError) {
|
} catch (saveError) {
|
||||||
console.warn(`Could not save config to ${DEFAULT_CONFIG_PATH}: ${saveError.message}`);
|
console.warn(`Could not save config to ${DEFAULT_CONFIG_PATH}: ${saveError.message}`);
|
||||||
console.warn('Saving to fallback location instead');
|
console.warn('Saving to fallback location instead');
|
||||||
|
|
||||||
// Save 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}`);
|
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
|
// Always try to save to the primary config location first
|
||||||
try {
|
try {
|
||||||
// Make sure directory exists
|
// Make sure directory exists
|
||||||
await fs.mkdir(path.dirname(DEFAULT_CONFIG_PATH), { recursive: true });
|
await fsPromises.mkdir(path.dirname(DEFAULT_CONFIG_PATH), { recursive: true });
|
||||||
await fs.writeFile(DEFAULT_CONFIG_PATH, JSON.stringify(config, null, 2), 'utf8');
|
await fsPromises.writeFile(DEFAULT_CONFIG_PATH, JSON.stringify(config, null, 2), 'utf8');
|
||||||
console.log(`Configuration saved to ${DEFAULT_CONFIG_PATH}`);
|
console.log(`Configuration saved to ${DEFAULT_CONFIG_PATH}`);
|
||||||
return;
|
return;
|
||||||
} catch (primaryError) {
|
} catch (primaryError) {
|
||||||
@ -361,7 +361,7 @@ async function saveConfig(config) {
|
|||||||
console.warn('Trying fallback location...');
|
console.warn('Trying fallback location...');
|
||||||
|
|
||||||
// If we couldn't save to the primary location, try the fallback
|
// 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}`);
|
console.log(`Configuration saved to fallback location: ${FALLBACK_CONFIG_PATH}`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -387,8 +387,8 @@ async function startServer() {
|
|||||||
config.securitySettings?.sslKeyPath) {
|
config.securitySettings?.sslKeyPath) {
|
||||||
try {
|
try {
|
||||||
const sslOptions = {
|
const sslOptions = {
|
||||||
key: await fs.readFile(config.securitySettings.sslKeyPath),
|
key: await fsPromises.readFile(config.securitySettings.sslKeyPath),
|
||||||
cert: await fs.readFile(config.securitySettings.sslCertPath)
|
cert: await fsPromises.readFile(config.securitySettings.sslCertPath)
|
||||||
};
|
};
|
||||||
|
|
||||||
server = https.createServer(sslOptions, app);
|
server = https.createServer(sslOptions, app);
|
||||||
@ -1087,17 +1087,17 @@ async function getMediaLibrary(searchQuery) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Check if directory exists
|
// Check if directory exists
|
||||||
await fs.access(destinationPath);
|
await fsPromises.access(destinationPath);
|
||||||
|
|
||||||
// Get directory listing
|
// Get directory listing
|
||||||
const files = await fs.readdir(destinationPath, { withFileTypes: true });
|
const files = await fsPromises.readdir(destinationPath, { withFileTypes: true });
|
||||||
|
|
||||||
// Process each file/directory
|
// Process each file/directory
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const fullPath = path.join(destinationPath, file.name);
|
const fullPath = path.join(destinationPath, file.name);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const stats = await fs.stat(fullPath);
|
const stats = await fsPromises.stat(fullPath);
|
||||||
|
|
||||||
// Create an item object
|
// Create an item object
|
||||||
const item = {
|
const item = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user