Jelajahi Sumber

Fix Chokidar extension filtering - correct path-level exts lookup

- Update shouldWatchFile and handleFileAdded to find exts in specific path configs
- Previously looked for exts at dataset level, but they're configured per-path
- Ensure .nfo and other unwanted files are properly ignored by Chokidar
- Update tests to match the corrected logic
Timothy Pomeroy 4 minggu lalu
induk
melakukan
e223a4176a

+ 9 - 6
apps/service/src/watcher.service.spec.ts

@@ -145,8 +145,9 @@ describe('WatcherService', () => {
       const mockConfig = {
         movies: {
           enabled: true,
-          exts: ['.mkv', '.mp4'],
-          '/path/to/movies': {},
+          '/path/to/movies': {
+            exts: ['mkv', 'mp4'],
+          },
         },
       };
 
@@ -263,8 +264,9 @@ describe('WatcherService', () => {
       const mockConfig = {
         movies: {
           enabled: true,
-          exts: ['.mkv', '.mp4'],
-          '/path/to/movies': {},
+          '/path/to/movies': {
+            exts: ['mkv', 'mp4'],
+          },
         },
       };
 
@@ -291,8 +293,9 @@ describe('WatcherService', () => {
       const mockConfig = {
         movies: {
           enabled: true,
-          exts: ['.mkv', '.mp4'],
-          '/path/to/movies': {},
+          '/path/to/movies': {
+            exts: ['mkv', 'mp4'],
+          },
         },
       };
 

+ 33 - 4
apps/service/src/watcher.service.ts

@@ -85,8 +85,21 @@ export class WatcherService {
         return false;
       }
 
-      // Get the exts array for this dataset
-      const exts = datasetSettings.exts;
+      // Find the specific path configuration that matches this file
+      let pathConfig = null;
+      for (const pathKey of Object.keys(datasetSettings)) {
+        if (pathKey !== 'enabled' && filePath.startsWith(pathKey)) {
+          pathConfig = datasetSettings[pathKey];
+          break;
+        }
+      }
+
+      if (!pathConfig) {
+        return false; // File path doesn't match any configured path in the dataset
+      }
+
+      // Get the exts array for this path
+      const exts = pathConfig.exts;
       if (!exts || !Array.isArray(exts) || exts.length === 0) {
         // If no exts specified, watch all files (backward compatibility)
         return true;
@@ -158,8 +171,24 @@ export class WatcherService {
       return;
     }
 
-    // Check if file extension matches the dataset's exts array
-    const exts = datasetSettings.exts;
+    // Find the specific path configuration that matches this file
+    let pathConfig = null;
+    for (const pathKey of Object.keys(datasetSettings)) {
+      if (pathKey !== 'enabled' && file.startsWith(pathKey)) {
+        pathConfig = datasetSettings[pathKey];
+        break;
+      }
+    }
+
+    if (!pathConfig) {
+      this.logger.warn(
+        `File path ${file} doesn't match any configured path in dataset ${dataset}`,
+      );
+      return;
+    }
+
+    // Check if file extension matches the path's exts array
+    const exts = pathConfig.exts;
     if (exts && Array.isArray(exts) && exts.length > 0) {
       const fileExt = path.extname(file).toLowerCase();
       const extensionMatches = exts.some((ext: string) => {