Spaces:
Paused
Paused
File size: 2,302 Bytes
a84b07b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | 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();
|