Jelajahi Sumber

fix(watcher): correct dataset name extraction from file paths

- Fix getDatasetFromPath to return actual dataset key name instead of directory basename
- Iterate through dataset config to match file paths with correct dataset
- Resolves issue where files in /TV and /Sports directories were not being saved to database
Timothy Pomeroy 1 bulan lalu
induk
melakukan
728400db81
1 mengubah file dengan 24 tambahan dan 1 penghapusan
  1. 24 1
      apps/service/src/datasets.service.ts

+ 24 - 1
apps/service/src/datasets.service.ts

@@ -1,10 +1,33 @@
 import { Injectable } from '@nestjs/common';
 import Database from 'better-sqlite3';
+import fs from 'fs';
 import path from 'path';
 
 @Injectable()
 export class DatasetsService {
-  private dbPath = path.resolve(process.cwd(), 'data/database.db');
+  private dbPath: string;
+
+  constructor() {
+    // Find project root by traversing up from current directory until we find the root package.json
+    let projectRoot = process.cwd();
+    while (projectRoot !== path.dirname(projectRoot)) {
+      if (fs.existsSync(path.join(projectRoot, 'package.json'))) {
+        try {
+          const pkg = JSON.parse(
+            fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf-8'),
+          );
+          if (pkg.name === 'watch-finished-turbo') {
+            break;
+          }
+        } catch (e) {
+          // ignore
+        }
+      }
+      projectRoot = path.dirname(projectRoot);
+    }
+
+    this.dbPath = path.resolve(projectRoot, 'data/database.db');
+  }
 
   /**
    * Returns all enabled dataset paths from the settings.datasets key in the database