fix #10: replace sync fs calls with async in fileUtils.js

This commit is contained in:
Jarian Cottingham 2026-07-05 07:36:50 +00:00
parent 723b6b23ec
commit 1904e4478f

View File

@ -23,7 +23,7 @@ function isMediaFile(filePath) {
*/ */
async function scanDirectory(directoryPath, progressCallback = null) { async function scanDirectory(directoryPath, progressCallback = null) {
try { try {
const files = fs.readdirSync(directoryPath); const files = await fs.promises.readdir(directoryPath);
const items = []; const items = [];
// First pass: collect folders and media files to process // First pass: collect folders and media files to process
@ -36,7 +36,7 @@ async function scanDirectory(directoryPath, progressCallback = null) {
const filePath = path.join(directoryPath, file); const filePath = path.join(directoryPath, file);
try { try {
const stat = fs.statSync(filePath); const stat = await fs.promises.stat(filePath);
if (stat.isDirectory()) { if (stat.isDirectory()) {
folders.push({ folders.push({
@ -142,8 +142,7 @@ async function extractFileDuration(filePath) {
console.warn(`ffprobe error for ${filePath}:`, err.message); console.warn(`ffprobe error for ${filePath}:`, err.message);
// Try alternative approach - attempt to get duration from file stats or use fallback // Try alternative approach - attempt to get duration from file stats or use fallback
try { try {
const fs = require('fs'); const stats = await fs.promises.stat(filePath);
const stats = fs.statSync(filePath);
console.log(`File size for ${filePath}: ${stats.size} bytes`); console.log(`File size for ${filePath}: ${stats.size} bytes`);
// For now, return 00:00 as fallback for problematic files // For now, return 00:00 as fallback for problematic files
resolve({ duration: '00:00', isProblematic: true }); resolve({ duration: '00:00', isProblematic: true });