Spaces:
Paused
Paused
Download apps/backend/src/scripts/ingest-drive.ts from Kraft102/widgettdc-api: direct link, hf CLI and curl.
- Browser
- Download file 2.37 kB
-
https://huggingface.co/spaces/Kraft102/widgettdc-api/resolve/main/apps/backend/src/scripts/ingest-drive.ts
- Command line
-
hf download hf://spaces/Kraft102/widgettdc-api/apps/backend/src/scripts/ingest-drive.ts
-
curl -L -o ingest-drive.ts https://huggingface.co/spaces/Kraft102/widgettdc-api/resolve/main/apps/backend/src/scripts/ingest-drive.ts
2.37 kB
| 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(); | |