Merge pull request 'Fix #10: Replace sync fs calls with async in fileUtils.js' (#15) from fix/async-fs into main

Reviewed-on: https://git.home.ms/jarianc/MovieMapper/pulls/15
This commit is contained in:
jarianc 2026-07-05 02:38:32 -05:00
commit edadfe20dd

View File

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