Spaces:
Paused
Paused
| import * as dotenv from 'dotenv'; | |
| import * as path from 'path'; | |
| import { ingestRepository } from '../services/GraphIngestor.js'; | |
| import { neo4jAdapter } from '../adapters/Neo4jAdapter.js'; | |
| dotenv.config({ path: path.resolve(process.cwd(), 'apps/backend/.env') }); | |
| const FORBIDDEN_PATHS = [ | |
| /^c:[\/\\]?$/i, // C:, C:\, C:/ | |
| /^c:[\/\\]windows/i, | |
| /^c:[\/\\]program files/i, | |
| /^c:[\/\\]program files \(x86\)/i, | |
| /^c:[\/\\]users[\/\\][^\\\/]+[\/\\]appdata/i // AppData | |
| ]; | |
| async function main() { | |
| const args = process.argv.slice(2); | |
| const targetPath = args[0]; | |
| if (!targetPath) { | |
| console.error('β Usage: npm run ingest-drive -- <path>'); | |
| console.error('Example: npm run ingest-drive -- "C:\\Users\\claus\\Documents"'); | |
| process.exit(1); | |
| } | |
| // Safety checks | |
| const normalizedPath = path.normalize(targetPath); | |
| for (const forbidden of FORBIDDEN_PATHS) { | |
| if (forbidden.test(normalizedPath)) { | |
| console.error(`β DENIED: Ingesting '${normalizedPath}' is restricted for safety reasons.`); | |
| console.error('Please point to a specific subdirectory (e.g., Documents, Projects).'); | |
| process.exit(1); | |
| } | |
| } | |
| console.log(`π Starting ingestion of: ${normalizedPath}`); | |
| console.log('NOTE: This may take a while depending on drive size.'); | |
| try { | |
| const result = await ingestRepository({ | |
| rootPath: normalizedPath, | |
| maxDepth: 10, | |
| parseContent: true, // Read file content | |
| generateEmbeddings: true, // Generate vectors | |
| includePatterns: ['*'], | |
| excludePatterns: [ | |
| 'node_modules', '.git', 'dist', 'build', 'coverage', | |
| '$Recycle.Bin', 'System Volume Information', 'pagefile.sys', 'swapfile.sys', | |
| '.vscode', '.idea' | |
| ] | |
| }); | |
| if (result.success) { | |
| console.log('β Ingestion completed successfully!'); | |
| console.log('Stats:', result.stats); | |
| } else { | |
| console.error('β Ingestion finished with errors:', result.errors); | |
| } | |
| } catch (error) { | |
| console.error('π₯ Fatal error:', error); | |
| } finally { | |
| await neo4jAdapter.close(); | |
| process.exit(0); | |
| } | |
| } | |
| main(); | |