@genobank/biofs 1.4.2 โ†’ 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -84,9 +84,62 @@ async function tokenizeCommand(filePath, options) {
84
84
  spinner = (0, ora_1.default)(`Step ${currentStep}/${steps}: ๐Ÿค– Analyzing content with Claude 3 Haiku for intelligent metadata generation...`).start();
85
85
  try {
86
86
  // Read file sample for Claude analysis (bioip.js sends first 20 lines)
87
- const fileContent = await (0, promises_1.readFile)(absolutePath, { encoding: 'utf-8' });
88
- const lines = fileContent.split('\n');
89
- const sampleLines = lines.slice(0, 20).join('\n');
87
+ // For large binary files (SQLite, BAM, etc.), read only first 50KB to avoid memory issues
88
+ let sampleLines;
89
+ const MAX_SAMPLE_SIZE = 50 * 1024; // 50KB sample for AI analysis
90
+
91
+ // Video files: Extract metadata using ffprobe instead of file contents
92
+ if (fileCategory === 'medical_video') {
93
+ const { exec } = require('child_process');
94
+ const util = require('util');
95
+ const execPromise = util.promisify(exec);
96
+
97
+ try {
98
+ const { stdout } = await execPromise(`ffprobe -v quiet -print_format json -show_format -show_streams "${absolutePath}"`);
99
+ const metadata = JSON.parse(stdout);
100
+
101
+ // Extract relevant video metadata
102
+ const videoStream = metadata.streams?.find(s => s.codec_type === 'video');
103
+ const audioStream = metadata.streams?.find(s => s.codec_type === 'audio');
104
+ const format = metadata.format;
105
+
106
+ sampleLines = JSON.stringify({
107
+ video: videoStream ? {
108
+ codec: videoStream.codec_name,
109
+ resolution: `${videoStream.width}x${videoStream.height}`,
110
+ fps: eval(videoStream.r_frame_rate),
111
+ duration: parseFloat(videoStream.duration || format.duration),
112
+ bitrate: parseInt(videoStream.bit_rate || format.bit_rate)
113
+ } : null,
114
+ audio: audioStream ? {
115
+ codec: audioStream.codec_name,
116
+ sampleRate: audioStream.sample_rate,
117
+ channels: audioStream.channels
118
+ } : null,
119
+ format: {
120
+ format: format.format_name,
121
+ duration: parseFloat(format.duration),
122
+ size: parseInt(format.size),
123
+ bitrate: parseInt(format.bit_rate)
124
+ }
125
+ }, null, 2);
126
+ } catch (ffprobeError) {
127
+ // If ffprobe fails, fall back to basic file info
128
+ sampleLines = `Video file: ${fileName}\nSize: ${(0, format_1.formatFileSize)(fileSize)}\nFormat: ${fileExt}\nNote: Could not extract video metadata (ffprobe not available or failed)`;
129
+ }
130
+ } else if (fileSize > MAX_SAMPLE_SIZE && (fileExt === '.sqlite' || fileExt === '.db' || fileExt === '.bam')) {
131
+ // Binary files: Read only first 50KB
132
+ const buffer = Buffer.alloc(MAX_SAMPLE_SIZE);
133
+ const fd = await (0, promises_1.open)(absolutePath, 'r');
134
+ await fd.read(buffer, 0, MAX_SAMPLE_SIZE, 0);
135
+ await fd.close();
136
+ sampleLines = buffer.toString('utf-8', 0, Math.min(2000, MAX_SAMPLE_SIZE)); // First 2KB as string
137
+ } else {
138
+ // Text files: Read first 20 lines
139
+ const fileContent = await (0, promises_1.readFile)(absolutePath, { encoding: 'utf-8' });
140
+ const lines = fileContent.split('\n');
141
+ sampleLines = lines.slice(0, 20).join('\n');
142
+ }
90
143
  // Call api_bioip.py /generate_metadata endpoint (uses Claude Haiku) - EXACT bioip.js flow
91
144
  const contextData = JSON.stringify({
92
145
  fileName: fileName,
@@ -113,9 +166,9 @@ async function tokenizeCommand(filePath, options) {
113
166
  let cleanDescription = (aiMetadata.description || 'Biological data for analysis')
114
167
  .replace(/^["']+/g, '')
115
168
  .replace(/["',]+$/g, '');
116
- // AI determines title and description - user options are OVERRIDES only (bioip.js pattern)
117
- aiTitle = options.title || cleanTitle;
118
- aiDescription = options.description || cleanDescription;
169
+ // AI determines title and description - user options are FALLBACK only (bioip.js pattern)
170
+ aiTitle = cleanTitle || options.title || 'Genomic Data Analysis';
171
+ aiDescription = cleanDescription || options.description || 'Biological data for analysis';
119
172
  spinner.succeed(`Step ${currentStep}/${steps}: โœ“ Claude Haiku generated metadata`);
120
173
  console.log(chalk_1.default.cyan(` ๐Ÿ“ AI Title: "${aiTitle}"`));
121
174
  console.log(chalk_1.default.gray(` ๐Ÿ“„ AI Description: ${aiDescription.substring(0, 60)}...`));
@@ -153,8 +206,8 @@ async function tokenizeCommand(filePath, options) {
153
206
  let collectionName = getCollectionName(collectionAddress);
154
207
  spinner.succeed(`Step ${currentStep}/${steps}: โœ“ Selected "${collectionName}" collection (${collectionAddress.substring(0, 10)}...)`);
155
208
  currentStep++;
156
- // Preview and Confirmation Step (only if not in quiet mode and not auto-confirmed)
157
- if (!options.quiet && !options.yes) {
209
+ // Preview and Confirmation Step (only if not in quiet mode, not auto-confirmed, and not dryrun)
210
+ if (!options.quiet && !options.yes && !options.dryrun) {
158
211
  const imageUrl = (0, collections_1.getDefaultImageForCategory)(detectedCategory);
159
212
  const licenseType = (0, licenses_1.getLicenseType)(options.license || 'non-commercial');
160
213
  const licenseDisplayName = getLicenseDisplayName(options.license || 'non-commercial');
@@ -283,37 +336,404 @@ async function tokenizeCommand(filePath, options) {
283
336
  }
284
337
  console.log(chalk_1.default.green('\nโœ… Proceeding with tokenization...\n'));
285
338
  }
339
+
340
+ // DRYRUN MODE: Validate infrastructure before stopping
341
+ if (options.dryrun) {
342
+ currentStep++;
343
+ spinner = (0, ora_1.default)(`Step ${currentStep}/${steps + 1}: ๐Ÿงช DRYRUN - Validating infrastructure (S3, blockchain, wallet)...`).start();
344
+
345
+ const validationResults = {
346
+ s3Access: false,
347
+ s3Bucket: false,
348
+ awsCredentials: false,
349
+ walletValid: false,
350
+ rpcConnection: false,
351
+ collectionExists: false,
352
+ apiConnection: false
353
+ };
354
+
355
+ try {
356
+ // 1. Validate AWS Credentials
357
+ const AWS = require('aws-sdk');
358
+ // Check if credentials are available
359
+ if (!process.env.S3_ACCESS_KEY || !process.env.S3_SECRET_KEY) {
360
+ validationResults.awsCredentials = false;
361
+ validationResults.s3Bucket = false;
362
+ spinner.text = `Step ${currentStep}/${steps + 1}: ๐Ÿงช DRYRUN - AWS credentials not found in environment`;
363
+ } else {
364
+ const s3 = new AWS.S3({
365
+ accessKeyId: process.env.S3_ACCESS_KEY,
366
+ secretAccessKey: process.env.S3_SECRET_KEY,
367
+ region: 'us-west-1'
368
+ });
369
+
370
+ spinner.text = `Step ${currentStep}/${steps + 1}: ๐Ÿงช DRYRUN - Checking AWS credentials...`;
371
+ try {
372
+ // Test credentials by listing buckets
373
+ await s3.listBuckets().promise();
374
+ validationResults.awsCredentials = true;
375
+ } catch (e) {
376
+ validationResults.awsCredentials = false;
377
+ }
378
+
379
+ // 2. Check S3 bucket existence
380
+ const bucket = networkName === 'mainnet' ? 'test.vault.genoverse.io' : 'test.vault.genoverse.io';
381
+ spinner.text = `Step ${currentStep}/${steps + 1}: ๐Ÿงช DRYRUN - Checking S3 bucket: ${bucket}...`;
382
+ try {
383
+ await s3.headBucket({ Bucket: bucket }).promise();
384
+ validationResults.s3Bucket = true;
385
+ } catch (e) {
386
+ validationResults.s3Bucket = false;
387
+ }
388
+ }
389
+
390
+ // 3. Check S3 write access by testing path construction
391
+ const testRegistrationId = `bioip_dryrun_${Date.now()}`;
392
+ const testS3Path = `biowallet/${credentials.wallet_address}/bioip/${testRegistrationId}/test.txt`;
393
+ spinner.text = `Step ${currentStep}/${steps + 1}: ๐Ÿงช DRYRUN - Validating S3 path access...`;
394
+ validationResults.s3Access = true; // Path is valid
395
+
396
+ // 4. Validate wallet format
397
+ spinner.text = `Step ${currentStep}/${steps + 1}: ๐Ÿงช DRYRUN - Validating wallet address...`;
398
+ validationResults.walletValid = /^0x[a-fA-F0-9]{40}$/.test(credentials.wallet_address);
399
+
400
+ // 5. Check Story Protocol RPC connection
401
+ spinner.text = `Step ${currentStep}/${steps + 1}: ๐Ÿงช DRYRUN - Connecting to Story Protocol RPC...`;
402
+ const https = require('https');
403
+ const rpcUrl = networkName === 'mainnet' ? 'https://mainnet.storyrpc.io/' : 'https://aeneid.storyrpc.io/';
404
+
405
+ try {
406
+ await new Promise((resolve, reject) => {
407
+ const postData = JSON.stringify({
408
+ jsonrpc: '2.0',
409
+ method: 'eth_blockNumber',
410
+ params: [],
411
+ id: 1
412
+ });
413
+
414
+ const url = new URL(rpcUrl);
415
+ const options = {
416
+ hostname: url.hostname,
417
+ port: url.port || 443,
418
+ path: url.pathname,
419
+ method: 'POST',
420
+ headers: {
421
+ 'Content-Type': 'application/json',
422
+ 'Content-Length': Buffer.byteLength(postData)
423
+ },
424
+ timeout: 5000
425
+ };
426
+
427
+ const req = https.request(options, (res) => {
428
+ let data = '';
429
+ res.on('data', (chunk) => { data += chunk; });
430
+ res.on('end', () => {
431
+ try {
432
+ const parsed = JSON.parse(data);
433
+ if (parsed.result) {
434
+ validationResults.rpcConnection = true;
435
+ resolve();
436
+ } else {
437
+ reject(new Error('No result from RPC'));
438
+ }
439
+ } catch (e) {
440
+ reject(e);
441
+ }
442
+ });
443
+ });
444
+
445
+ req.on('error', reject);
446
+ req.on('timeout', () => {
447
+ req.destroy();
448
+ reject(new Error('RPC timeout'));
449
+ });
450
+
451
+ req.write(postData);
452
+ req.end();
453
+ });
454
+ } catch (e) {
455
+ validationResults.rpcConnection = false;
456
+ }
457
+
458
+ // 6. Check collection exists on-chain (if collectionAddress provided)
459
+ if (collectionAddress && collectionAddress !== '0x0000000000000000000000000000000000000000') {
460
+ spinner.text = `Step ${currentStep}/${steps + 1}: ๐Ÿงช DRYRUN - Verifying collection on-chain...`;
461
+ try {
462
+ await new Promise((resolve, reject) => {
463
+ const postData = JSON.stringify({
464
+ jsonrpc: '2.0',
465
+ method: 'eth_getCode',
466
+ params: [collectionAddress, 'latest'],
467
+ id: 1
468
+ });
469
+
470
+ const url = new URL(rpcUrl);
471
+ const options = {
472
+ hostname: url.hostname,
473
+ port: url.port || 443,
474
+ path: url.pathname,
475
+ method: 'POST',
476
+ headers: {
477
+ 'Content-Type': 'application/json',
478
+ 'Content-Length': Buffer.byteLength(postData)
479
+ },
480
+ timeout: 5000
481
+ };
482
+
483
+ const req = https.request(options, (res) => {
484
+ let data = '';
485
+ res.on('data', (chunk) => { data += chunk; });
486
+ res.on('end', () => {
487
+ try {
488
+ const parsed = JSON.parse(data);
489
+ if (parsed.result && parsed.result !== '0x' && parsed.result !== '0x0') {
490
+ validationResults.collectionExists = true;
491
+ resolve();
492
+ } else {
493
+ reject(new Error('No contract code at address'));
494
+ }
495
+ } catch (e) {
496
+ reject(e);
497
+ }
498
+ });
499
+ });
500
+
501
+ req.on('error', reject);
502
+ req.on('timeout', () => {
503
+ req.destroy();
504
+ reject(new Error('RPC timeout'));
505
+ });
506
+
507
+ req.write(postData);
508
+ req.end();
509
+ });
510
+ } catch (e) {
511
+ validationResults.collectionExists = false;
512
+ }
513
+ } else {
514
+ validationResults.collectionExists = true; // No specific collection, OK
515
+ }
516
+
517
+ // 7. Check API connectivity
518
+ spinner.text = `Step ${currentStep}/${steps + 1}: ๐Ÿงช DRYRUN - Testing API endpoint connectivity...`;
519
+ try {
520
+ await new Promise((resolve, reject) => {
521
+ const apiUrl = new URL('https://genobank.app/api_bioip/');
522
+ const options = {
523
+ hostname: apiUrl.hostname,
524
+ port: apiUrl.port || 443,
525
+ path: apiUrl.pathname,
526
+ method: 'GET',
527
+ timeout: 5000
528
+ };
529
+
530
+ const req = https.request(options, (res) => {
531
+ validationResults.apiConnection = (res.statusCode === 200 || res.statusCode === 404);
532
+ resolve();
533
+ });
534
+
535
+ req.on('error', () => {
536
+ validationResults.apiConnection = false;
537
+ resolve(); // Don't reject, just mark as failed
538
+ });
539
+
540
+ req.on('timeout', () => {
541
+ req.destroy();
542
+ validationResults.apiConnection = false;
543
+ resolve();
544
+ });
545
+
546
+ req.end();
547
+ });
548
+ } catch (e) {
549
+ validationResults.apiConnection = false;
550
+ }
551
+
552
+ spinner.succeed(`Step ${currentStep}/${steps + 1}: โœ“ Infrastructure validation complete`);
553
+
554
+ } catch (error) {
555
+ spinner.fail(`Step ${currentStep}/${steps + 1}: Infrastructure validation failed`);
556
+ }
557
+
558
+ // Display validation results
559
+ console.log('\n');
560
+ const imageUrl = (0, collections_1.getDefaultImageForCategory)(detectedCategory);
561
+ const licenseType = (0, licenses_1.getLicenseType)(options.license || 'non-commercial');
562
+ const licenseDisplayName = getLicenseDisplayName(options.license || 'non-commercial');
563
+
564
+ // Build full preview for dryrun
565
+ const preview = buildMetadataPreview({
566
+ fileName,
567
+ fileSize,
568
+ title: aiTitle,
569
+ description: aiDescription || `${detectedCategory} dataset`,
570
+ category: detectedCategory,
571
+ fingerprint,
572
+ snpCount,
573
+ collection: collectionName,
574
+ collectionAddress,
575
+ license: licenseDisplayName,
576
+ licenseType,
577
+ imageUrl,
578
+ network: network.name,
579
+ wallet: credentials.wallet_address
580
+ });
581
+
582
+ console.log((0, boxen_1.default)(preview, {
583
+ padding: 1,
584
+ margin: 1,
585
+ borderStyle: 'round',
586
+ borderColor: 'cyan',
587
+ title: '๐Ÿงช DRY RUN - Metadata Preview',
588
+ titleAlignment: 'center'
589
+ }));
590
+
591
+ // Display infrastructure validation results
592
+ console.log('\n');
593
+ const allValid = Object.values(validationResults).every(v => v === true);
594
+ const validationColor = allValid ? 'green' : 'yellow';
595
+
596
+ const statusIcon = (valid) => valid ? chalk_1.default.green('โœ…') : chalk_1.default.red('โŒ');
597
+
598
+ const infrastructureStatus =
599
+ chalk_1.default.bold.white('๐Ÿ”ง Infrastructure Validation Results\n\n') +
600
+ `${statusIcon(validationResults.awsCredentials)} AWS Credentials: ${validationResults.awsCredentials ? chalk_1.default.green('Valid') : chalk_1.default.red('Invalid')}\n` +
601
+ `${statusIcon(validationResults.s3Bucket)} S3 Bucket Access: ${validationResults.s3Bucket ? chalk_1.default.green('test.vault.genoverse.io exists') : chalk_1.default.red('Bucket not found')}\n` +
602
+ `${statusIcon(validationResults.s3Access)} S3 Path Validation: ${validationResults.s3Access ? chalk_1.default.green('Path structure valid') : chalk_1.default.red('Invalid path')}\n` +
603
+ `${statusIcon(validationResults.walletValid)} Wallet Address: ${validationResults.walletValid ? chalk_1.default.green('Valid format') : chalk_1.default.red('Invalid format')}\n` +
604
+ `${statusIcon(validationResults.rpcConnection)} Story Protocol RPC: ${validationResults.rpcConnection ? chalk_1.default.green('Connected') : chalk_1.default.red('Connection failed')}\n` +
605
+ `${statusIcon(validationResults.collectionExists)} Collection On-Chain: ${validationResults.collectionExists ? chalk_1.default.green('Verified') : chalk_1.default.red('Not found')}\n` +
606
+ `${statusIcon(validationResults.apiConnection)} API Endpoint: ${validationResults.apiConnection ? chalk_1.default.green('Accessible') : chalk_1.default.red('Not accessible')}\n\n` +
607
+ (allValid
608
+ ? chalk_1.default.green.bold('โœ… All infrastructure checks passed - Ready to tokenize!')
609
+ : chalk_1.default.yellow.bold('โš ๏ธ Some infrastructure checks failed - Fix issues before tokenizing'));
610
+
611
+ console.log((0, boxen_1.default)(infrastructureStatus, {
612
+ padding: 1,
613
+ margin: 1,
614
+ borderStyle: 'round',
615
+ borderColor: validationColor,
616
+ title: '๐Ÿ”ง Infrastructure Status',
617
+ titleAlignment: 'center'
618
+ }));
619
+
620
+ console.log('\n');
621
+ console.log((0, boxen_1.default)(chalk_1.default.cyan.bold('๐Ÿงช DRY RUN MODE COMPLETE\n\n') +
622
+ chalk_1.default.white('All validation and AI classification steps completed!\n\n') +
623
+ chalk_1.default.gray('โœ… File validated and fingerprinted\n') +
624
+ chalk_1.default.gray('โœ… AI metadata generated by Claude Haiku\n') +
625
+ chalk_1.default.gray('โœ… Collection and license configured\n') +
626
+ chalk_1.default.gray(`${allValid ? 'โœ…' : 'โš ๏ธ '} Infrastructure validation ${allValid ? 'passed' : 'has issues'}\n\n`) +
627
+ chalk_1.default.yellow('โธ๏ธ Tokenization paused before data upload and blockchain minting\n\n') +
628
+ chalk_1.default.white('To proceed with actual tokenization, run without --dryrun flag:\n\n') +
629
+ chalk_1.default.cyan(`biofs tokenize "${absolutePath}" --network ${networkName} --license ${options.license || 'non-commercial'}`), {
630
+ padding: 1,
631
+ margin: 1,
632
+ borderStyle: 'double',
633
+ borderColor: 'cyan',
634
+ title: '๐Ÿงช Dry Run Complete',
635
+ titleAlignment: 'center'
636
+ }));
637
+ console.log('\n');
638
+ return; // Exit without tokenizing
639
+ }
640
+
286
641
  // Step 5: Upload to GenoBank with Web3 signature authentication
287
642
  spinner = (0, ora_1.default)(`Step ${currentStep}/${steps}: ๐Ÿ“ค Uploading to secure GenoBank vault with Web3 authentication...`).start();
288
- // Read file
289
- const fileBuffer = await (0, promises_1.readFile)(absolutePath);
290
- // Prepare form data with file upload
291
- const formData = new form_data_1.default();
292
- formData.append('user_signature', credentials.user_signature);
293
- formData.append('file', fileBuffer, fileName);
294
- formData.append('title', aiTitle);
295
- formData.append('description', aiDescription || `${detectedCategory} dataset`);
296
- formData.append('license_type', (0, licenses_1.getLicenseType)(options.license || 'non-commercial'));
297
- formData.append('fingerprint', fingerprint);
298
- formData.append('file_category', detectedCategory);
299
- formData.append('collection_address', collectionAddress);
300
- formData.append('image_url', (0, collections_1.getDefaultImageForCategory)(detectedCategory));
301
- formData.append('network', networkName);
302
- // Submit to API
303
- const response = await axios_1.default.post(`${API_BASE}/register_bioip`, formData, {
304
- headers: {
305
- ...formData.getHeaders()
306
- },
307
- maxBodyLength: Infinity,
308
- maxContentLength: Infinity,
309
- onUploadProgress: (progressEvent) => {
310
- if (progressEvent.total) {
311
- const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
312
- const progressBar = 'โ–“'.repeat(Math.floor(percentCompleted / 5)) + 'โ–‘'.repeat(20 - Math.floor(percentCompleted / 5));
313
- spinner.text = `Step ${currentStep}/${steps}: ๐Ÿ“ค Uploading ${(0, format_1.formatFileSize)(progressEvent.loaded)}/${(0, format_1.formatFileSize)(progressEvent.total)} ${progressBar} ${percentCompleted}%`;
314
- }
643
+
644
+ // Check file size to determine upload method (fileSize already defined from fileStats at line 34)
645
+ const CLOUDFLARE_LIMIT = 100 * 1024 * 1024; // 100MB CloudFlare limit
646
+
647
+ let response;
648
+ let s3Path;
649
+
650
+ if (fileSize > CLOUDFLARE_LIMIT) {
651
+ // Large file: Use direct S3 upload to bypass CloudFlare
652
+ spinner.text = `Step ${currentStep}/${steps}: ๐Ÿ“ค Large file detected (${(0, format_1.formatFileSize)(fileSize)}), uploading directly to S3...`;
653
+
654
+ const AWS = require('aws-sdk');
655
+
656
+ // Require AWS credentials from environment
657
+ if (!process.env.S3_ACCESS_KEY || !process.env.S3_SECRET_KEY) {
658
+ spinner.fail(`Step ${currentStep}/${steps}: โŒ AWS credentials not found`);
659
+ console.error(chalk_1.default.red('\nโš ๏ธ AWS credentials required for S3 upload'));
660
+ console.error(chalk_1.default.yellow('Please set S3_ACCESS_KEY and S3_SECRET_KEY environment variables\n'));
661
+ process.exit(1);
315
662
  }
316
- });
663
+
664
+ const s3 = new AWS.S3({
665
+ accessKeyId: process.env.S3_ACCESS_KEY,
666
+ secretAccessKey: process.env.S3_SECRET_KEY,
667
+ region: 'us-west-1'
668
+ });
669
+
670
+ const bucket = networkName === 'mainnet' ? 'vault.genoverse.io' : 'test.vault.genoverse.io';
671
+ const registrationId = `bioip_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
672
+ s3Path = `biowallet/${credentials.wallet_address}/bioip/${registrationId}/${fileName}`;
673
+
674
+ // Upload to S3 with progress
675
+ const fileBuffer = await (0, promises_1.readFile)(absolutePath);
676
+ await s3.upload({
677
+ Bucket: bucket,
678
+ Key: s3Path,
679
+ Body: fileBuffer
680
+ }).on('httpUploadProgress', (progress) => {
681
+ const percentCompleted = Math.round((progress.loaded * 100) / progress.total);
682
+ const progressBar = 'โ–“'.repeat(Math.floor(percentCompleted / 5)) + 'โ–‘'.repeat(20 - Math.floor(percentCompleted / 5));
683
+ spinner.text = `Step ${currentStep}/${steps}: ๐Ÿ“ค Uploading to S3 ${(0, format_1.formatFileSize)(progress.loaded)}/${(0, format_1.formatFileSize)(progress.total)} ${progressBar} ${percentCompleted}%`;
684
+ }).promise();
685
+
686
+ spinner.text = `Step ${currentStep}/${steps}: ๐Ÿ“ค S3 upload complete, registering on blockchain...`;
687
+
688
+ // Register with API using s3_path parameter (bypasses CloudFlare)
689
+ const formDataS3 = new form_data_1.default();
690
+ formDataS3.append('user_signature', credentials.user_signature);
691
+ formDataS3.append('s3_path', s3Path);
692
+ formDataS3.append('title', aiTitle);
693
+ formDataS3.append('description', aiDescription || `${detectedCategory} dataset`);
694
+ formDataS3.append('license_type', (0, licenses_1.getLicenseType)(options.license || 'non-commercial'));
695
+ formDataS3.append('fingerprint', fingerprint);
696
+ formDataS3.append('file_category', detectedCategory);
697
+ formDataS3.append('collection_address', collectionAddress);
698
+ formDataS3.append('image_url', (0, collections_1.getDefaultImageForCategory)(detectedCategory));
699
+ formDataS3.append('network', networkName);
700
+
701
+ response = await axios_1.default.post(`${API_BASE}/register_bioip`, formDataS3, {
702
+ headers: {
703
+ ...formDataS3.getHeaders()
704
+ }
705
+ });
706
+ } else {
707
+ // Small file: Use standard upload through CloudFlare
708
+ const fileBuffer = await (0, promises_1.readFile)(absolutePath);
709
+ const formData = new form_data_1.default();
710
+ formData.append('user_signature', credentials.user_signature);
711
+ formData.append('file', fileBuffer, fileName);
712
+ formData.append('title', aiTitle);
713
+ formData.append('description', aiDescription || `${detectedCategory} dataset`);
714
+ formData.append('license_type', (0, licenses_1.getLicenseType)(options.license || 'non-commercial'));
715
+ formData.append('fingerprint', fingerprint);
716
+ formData.append('file_category', detectedCategory);
717
+ formData.append('collection_address', collectionAddress);
718
+ formData.append('image_url', (0, collections_1.getDefaultImageForCategory)(detectedCategory));
719
+ formData.append('network', networkName);
720
+
721
+ response = await axios_1.default.post(`${API_BASE}/register_bioip`, formData, {
722
+ headers: {
723
+ ...formData.getHeaders()
724
+ },
725
+ maxBodyLength: Infinity,
726
+ maxContentLength: Infinity,
727
+ onUploadProgress: (progressEvent) => {
728
+ if (progressEvent.total) {
729
+ const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
730
+ const progressBar = 'โ–“'.repeat(Math.floor(percentCompleted / 5)) + 'โ–‘'.repeat(20 - Math.floor(percentCompleted / 5));
731
+ spinner.text = `Step ${currentStep}/${steps}: ๐Ÿ“ค Uploading ${(0, format_1.formatFileSize)(progressEvent.loaded)}/${(0, format_1.formatFileSize)(progressEvent.total)} ${progressBar} ${percentCompleted}%`;
732
+ }
733
+ }
734
+ });
735
+ }
736
+
317
737
  spinner.succeed(`Step ${currentStep}/${steps}: โœ“ Uploaded to encrypted S3 vault & registered in MongoDB`);
318
738
  currentStep++;
319
739
  // Debug: Log the response structure
@@ -423,7 +843,12 @@ function detectFileCategory(fileName, fileExt) {
423
843
  '.gff': 'annotation',
424
844
  '.gtf': 'annotation',
425
845
  '.dcm': 'medical_imaging',
426
- '.dicom': 'medical_imaging'
846
+ '.dicom': 'medical_imaging',
847
+ '.mov': 'medical_video',
848
+ '.mp4': 'medical_video',
849
+ '.webm': 'medical_video',
850
+ '.avi': 'medical_video',
851
+ '.mkv': 'medical_video'
427
852
  };
428
853
  // Check compound extensions first
429
854
  for (const [ext, category] of Object.entries(extMap)) {