@genobank/biofs 1.4.2 โ 1.5.2
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.
- package/dist/commands/tokenize.js +417 -36
- package/dist/index.js +5 -3
- package/dist/lib/bioip/collections.js +3 -1
- package/package.json +1 -1
|
@@ -84,9 +84,23 @@ 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
|
-
|
|
88
|
-
|
|
89
|
-
const
|
|
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
|
+
if (fileSize > MAX_SAMPLE_SIZE && (fileExt === '.sqlite' || fileExt === '.db' || fileExt === '.bam')) {
|
|
92
|
+
// Binary files: Read only first 50KB
|
|
93
|
+
const buffer = Buffer.alloc(MAX_SAMPLE_SIZE);
|
|
94
|
+
const fd = await (0, promises_1.open)(absolutePath, 'r');
|
|
95
|
+
await fd.read(buffer, 0, MAX_SAMPLE_SIZE, 0);
|
|
96
|
+
await fd.close();
|
|
97
|
+
sampleLines = buffer.toString('utf-8', 0, Math.min(2000, MAX_SAMPLE_SIZE)); // First 2KB as string
|
|
98
|
+
} else {
|
|
99
|
+
// Text files: Read first 20 lines
|
|
100
|
+
const fileContent = await (0, promises_1.readFile)(absolutePath, { encoding: 'utf-8' });
|
|
101
|
+
const lines = fileContent.split('\n');
|
|
102
|
+
sampleLines = lines.slice(0, 20).join('\n');
|
|
103
|
+
}
|
|
90
104
|
// Call api_bioip.py /generate_metadata endpoint (uses Claude Haiku) - EXACT bioip.js flow
|
|
91
105
|
const contextData = JSON.stringify({
|
|
92
106
|
fileName: fileName,
|
|
@@ -113,9 +127,9 @@ async function tokenizeCommand(filePath, options) {
|
|
|
113
127
|
let cleanDescription = (aiMetadata.description || 'Biological data for analysis')
|
|
114
128
|
.replace(/^["']+/g, '')
|
|
115
129
|
.replace(/["',]+$/g, '');
|
|
116
|
-
// AI determines title and description - user options are
|
|
117
|
-
aiTitle = options.title ||
|
|
118
|
-
aiDescription = options.description ||
|
|
130
|
+
// AI determines title and description - user options are FALLBACK only (bioip.js pattern)
|
|
131
|
+
aiTitle = cleanTitle || options.title || 'Genomic Data Analysis';
|
|
132
|
+
aiDescription = cleanDescription || options.description || 'Biological data for analysis';
|
|
119
133
|
spinner.succeed(`Step ${currentStep}/${steps}: โ Claude Haiku generated metadata`);
|
|
120
134
|
console.log(chalk_1.default.cyan(` ๐ AI Title: "${aiTitle}"`));
|
|
121
135
|
console.log(chalk_1.default.gray(` ๐ AI Description: ${aiDescription.substring(0, 60)}...`));
|
|
@@ -153,8 +167,8 @@ async function tokenizeCommand(filePath, options) {
|
|
|
153
167
|
let collectionName = getCollectionName(collectionAddress);
|
|
154
168
|
spinner.succeed(`Step ${currentStep}/${steps}: โ Selected "${collectionName}" collection (${collectionAddress.substring(0, 10)}...)`);
|
|
155
169
|
currentStep++;
|
|
156
|
-
// Preview and Confirmation Step (only if not in quiet mode
|
|
157
|
-
if (!options.quiet && !options.yes) {
|
|
170
|
+
// Preview and Confirmation Step (only if not in quiet mode, not auto-confirmed, and not dryrun)
|
|
171
|
+
if (!options.quiet && !options.yes && !options.dryrun) {
|
|
158
172
|
const imageUrl = (0, collections_1.getDefaultImageForCategory)(detectedCategory);
|
|
159
173
|
const licenseType = (0, licenses_1.getLicenseType)(options.license || 'non-commercial');
|
|
160
174
|
const licenseDisplayName = getLicenseDisplayName(options.license || 'non-commercial');
|
|
@@ -283,37 +297,404 @@ async function tokenizeCommand(filePath, options) {
|
|
|
283
297
|
}
|
|
284
298
|
console.log(chalk_1.default.green('\nโ
Proceeding with tokenization...\n'));
|
|
285
299
|
}
|
|
300
|
+
|
|
301
|
+
// DRYRUN MODE: Validate infrastructure before stopping
|
|
302
|
+
if (options.dryrun) {
|
|
303
|
+
currentStep++;
|
|
304
|
+
spinner = (0, ora_1.default)(`Step ${currentStep}/${steps + 1}: ๐งช DRYRUN - Validating infrastructure (S3, blockchain, wallet)...`).start();
|
|
305
|
+
|
|
306
|
+
const validationResults = {
|
|
307
|
+
s3Access: false,
|
|
308
|
+
s3Bucket: false,
|
|
309
|
+
awsCredentials: false,
|
|
310
|
+
walletValid: false,
|
|
311
|
+
rpcConnection: false,
|
|
312
|
+
collectionExists: false,
|
|
313
|
+
apiConnection: false
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
try {
|
|
317
|
+
// 1. Validate AWS Credentials
|
|
318
|
+
const AWS = require('aws-sdk');
|
|
319
|
+
// Check if credentials are available
|
|
320
|
+
if (!process.env.S3_ACCESS_KEY || !process.env.S3_SECRET_KEY) {
|
|
321
|
+
validationResults.awsCredentials = false;
|
|
322
|
+
validationResults.s3Bucket = false;
|
|
323
|
+
spinner.text = `Step ${currentStep}/${steps + 1}: ๐งช DRYRUN - AWS credentials not found in environment`;
|
|
324
|
+
} else {
|
|
325
|
+
const s3 = new AWS.S3({
|
|
326
|
+
accessKeyId: process.env.S3_ACCESS_KEY,
|
|
327
|
+
secretAccessKey: process.env.S3_SECRET_KEY,
|
|
328
|
+
region: 'us-west-1'
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
spinner.text = `Step ${currentStep}/${steps + 1}: ๐งช DRYRUN - Checking AWS credentials...`;
|
|
332
|
+
try {
|
|
333
|
+
// Test credentials by listing buckets
|
|
334
|
+
await s3.listBuckets().promise();
|
|
335
|
+
validationResults.awsCredentials = true;
|
|
336
|
+
} catch (e) {
|
|
337
|
+
validationResults.awsCredentials = false;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// 2. Check S3 bucket existence
|
|
341
|
+
const bucket = networkName === 'mainnet' ? 'test.vault.genoverse.io' : 'test.vault.genoverse.io';
|
|
342
|
+
spinner.text = `Step ${currentStep}/${steps + 1}: ๐งช DRYRUN - Checking S3 bucket: ${bucket}...`;
|
|
343
|
+
try {
|
|
344
|
+
await s3.headBucket({ Bucket: bucket }).promise();
|
|
345
|
+
validationResults.s3Bucket = true;
|
|
346
|
+
} catch (e) {
|
|
347
|
+
validationResults.s3Bucket = false;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// 3. Check S3 write access by testing path construction
|
|
352
|
+
const testRegistrationId = `bioip_dryrun_${Date.now()}`;
|
|
353
|
+
const testS3Path = `biowallet/${credentials.wallet_address}/bioip/${testRegistrationId}/test.txt`;
|
|
354
|
+
spinner.text = `Step ${currentStep}/${steps + 1}: ๐งช DRYRUN - Validating S3 path access...`;
|
|
355
|
+
validationResults.s3Access = true; // Path is valid
|
|
356
|
+
|
|
357
|
+
// 4. Validate wallet format
|
|
358
|
+
spinner.text = `Step ${currentStep}/${steps + 1}: ๐งช DRYRUN - Validating wallet address...`;
|
|
359
|
+
validationResults.walletValid = /^0x[a-fA-F0-9]{40}$/.test(credentials.wallet_address);
|
|
360
|
+
|
|
361
|
+
// 5. Check Story Protocol RPC connection
|
|
362
|
+
spinner.text = `Step ${currentStep}/${steps + 1}: ๐งช DRYRUN - Connecting to Story Protocol RPC...`;
|
|
363
|
+
const https = require('https');
|
|
364
|
+
const rpcUrl = networkName === 'mainnet' ? 'https://mainnet.storyrpc.io/' : 'https://aeneid.storyrpc.io/';
|
|
365
|
+
|
|
366
|
+
try {
|
|
367
|
+
await new Promise((resolve, reject) => {
|
|
368
|
+
const postData = JSON.stringify({
|
|
369
|
+
jsonrpc: '2.0',
|
|
370
|
+
method: 'eth_blockNumber',
|
|
371
|
+
params: [],
|
|
372
|
+
id: 1
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
const url = new URL(rpcUrl);
|
|
376
|
+
const options = {
|
|
377
|
+
hostname: url.hostname,
|
|
378
|
+
port: url.port || 443,
|
|
379
|
+
path: url.pathname,
|
|
380
|
+
method: 'POST',
|
|
381
|
+
headers: {
|
|
382
|
+
'Content-Type': 'application/json',
|
|
383
|
+
'Content-Length': Buffer.byteLength(postData)
|
|
384
|
+
},
|
|
385
|
+
timeout: 5000
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
const req = https.request(options, (res) => {
|
|
389
|
+
let data = '';
|
|
390
|
+
res.on('data', (chunk) => { data += chunk; });
|
|
391
|
+
res.on('end', () => {
|
|
392
|
+
try {
|
|
393
|
+
const parsed = JSON.parse(data);
|
|
394
|
+
if (parsed.result) {
|
|
395
|
+
validationResults.rpcConnection = true;
|
|
396
|
+
resolve();
|
|
397
|
+
} else {
|
|
398
|
+
reject(new Error('No result from RPC'));
|
|
399
|
+
}
|
|
400
|
+
} catch (e) {
|
|
401
|
+
reject(e);
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
req.on('error', reject);
|
|
407
|
+
req.on('timeout', () => {
|
|
408
|
+
req.destroy();
|
|
409
|
+
reject(new Error('RPC timeout'));
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
req.write(postData);
|
|
413
|
+
req.end();
|
|
414
|
+
});
|
|
415
|
+
} catch (e) {
|
|
416
|
+
validationResults.rpcConnection = false;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// 6. Check collection exists on-chain (if collectionAddress provided)
|
|
420
|
+
if (collectionAddress && collectionAddress !== '0x0000000000000000000000000000000000000000') {
|
|
421
|
+
spinner.text = `Step ${currentStep}/${steps + 1}: ๐งช DRYRUN - Verifying collection on-chain...`;
|
|
422
|
+
try {
|
|
423
|
+
await new Promise((resolve, reject) => {
|
|
424
|
+
const postData = JSON.stringify({
|
|
425
|
+
jsonrpc: '2.0',
|
|
426
|
+
method: 'eth_getCode',
|
|
427
|
+
params: [collectionAddress, 'latest'],
|
|
428
|
+
id: 1
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
const url = new URL(rpcUrl);
|
|
432
|
+
const options = {
|
|
433
|
+
hostname: url.hostname,
|
|
434
|
+
port: url.port || 443,
|
|
435
|
+
path: url.pathname,
|
|
436
|
+
method: 'POST',
|
|
437
|
+
headers: {
|
|
438
|
+
'Content-Type': 'application/json',
|
|
439
|
+
'Content-Length': Buffer.byteLength(postData)
|
|
440
|
+
},
|
|
441
|
+
timeout: 5000
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
const req = https.request(options, (res) => {
|
|
445
|
+
let data = '';
|
|
446
|
+
res.on('data', (chunk) => { data += chunk; });
|
|
447
|
+
res.on('end', () => {
|
|
448
|
+
try {
|
|
449
|
+
const parsed = JSON.parse(data);
|
|
450
|
+
if (parsed.result && parsed.result !== '0x' && parsed.result !== '0x0') {
|
|
451
|
+
validationResults.collectionExists = true;
|
|
452
|
+
resolve();
|
|
453
|
+
} else {
|
|
454
|
+
reject(new Error('No contract code at address'));
|
|
455
|
+
}
|
|
456
|
+
} catch (e) {
|
|
457
|
+
reject(e);
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
req.on('error', reject);
|
|
463
|
+
req.on('timeout', () => {
|
|
464
|
+
req.destroy();
|
|
465
|
+
reject(new Error('RPC timeout'));
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
req.write(postData);
|
|
469
|
+
req.end();
|
|
470
|
+
});
|
|
471
|
+
} catch (e) {
|
|
472
|
+
validationResults.collectionExists = false;
|
|
473
|
+
}
|
|
474
|
+
} else {
|
|
475
|
+
validationResults.collectionExists = true; // No specific collection, OK
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// 7. Check API connectivity
|
|
479
|
+
spinner.text = `Step ${currentStep}/${steps + 1}: ๐งช DRYRUN - Testing API endpoint connectivity...`;
|
|
480
|
+
try {
|
|
481
|
+
await new Promise((resolve, reject) => {
|
|
482
|
+
const apiUrl = new URL('https://genobank.app/api_bioip/');
|
|
483
|
+
const options = {
|
|
484
|
+
hostname: apiUrl.hostname,
|
|
485
|
+
port: apiUrl.port || 443,
|
|
486
|
+
path: apiUrl.pathname,
|
|
487
|
+
method: 'GET',
|
|
488
|
+
timeout: 5000
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
const req = https.request(options, (res) => {
|
|
492
|
+
validationResults.apiConnection = (res.statusCode === 200 || res.statusCode === 404);
|
|
493
|
+
resolve();
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
req.on('error', () => {
|
|
497
|
+
validationResults.apiConnection = false;
|
|
498
|
+
resolve(); // Don't reject, just mark as failed
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
req.on('timeout', () => {
|
|
502
|
+
req.destroy();
|
|
503
|
+
validationResults.apiConnection = false;
|
|
504
|
+
resolve();
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
req.end();
|
|
508
|
+
});
|
|
509
|
+
} catch (e) {
|
|
510
|
+
validationResults.apiConnection = false;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
spinner.succeed(`Step ${currentStep}/${steps + 1}: โ Infrastructure validation complete`);
|
|
514
|
+
|
|
515
|
+
} catch (error) {
|
|
516
|
+
spinner.fail(`Step ${currentStep}/${steps + 1}: Infrastructure validation failed`);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// Display validation results
|
|
520
|
+
console.log('\n');
|
|
521
|
+
const imageUrl = (0, collections_1.getDefaultImageForCategory)(detectedCategory);
|
|
522
|
+
const licenseType = (0, licenses_1.getLicenseType)(options.license || 'non-commercial');
|
|
523
|
+
const licenseDisplayName = getLicenseDisplayName(options.license || 'non-commercial');
|
|
524
|
+
|
|
525
|
+
// Build full preview for dryrun
|
|
526
|
+
const preview = buildMetadataPreview({
|
|
527
|
+
fileName,
|
|
528
|
+
fileSize,
|
|
529
|
+
title: aiTitle,
|
|
530
|
+
description: aiDescription || `${detectedCategory} dataset`,
|
|
531
|
+
category: detectedCategory,
|
|
532
|
+
fingerprint,
|
|
533
|
+
snpCount,
|
|
534
|
+
collection: collectionName,
|
|
535
|
+
collectionAddress,
|
|
536
|
+
license: licenseDisplayName,
|
|
537
|
+
licenseType,
|
|
538
|
+
imageUrl,
|
|
539
|
+
network: network.name,
|
|
540
|
+
wallet: credentials.wallet_address
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
console.log((0, boxen_1.default)(preview, {
|
|
544
|
+
padding: 1,
|
|
545
|
+
margin: 1,
|
|
546
|
+
borderStyle: 'round',
|
|
547
|
+
borderColor: 'cyan',
|
|
548
|
+
title: '๐งช DRY RUN - Metadata Preview',
|
|
549
|
+
titleAlignment: 'center'
|
|
550
|
+
}));
|
|
551
|
+
|
|
552
|
+
// Display infrastructure validation results
|
|
553
|
+
console.log('\n');
|
|
554
|
+
const allValid = Object.values(validationResults).every(v => v === true);
|
|
555
|
+
const validationColor = allValid ? 'green' : 'yellow';
|
|
556
|
+
|
|
557
|
+
const statusIcon = (valid) => valid ? chalk_1.default.green('โ
') : chalk_1.default.red('โ');
|
|
558
|
+
|
|
559
|
+
const infrastructureStatus =
|
|
560
|
+
chalk_1.default.bold.white('๐ง Infrastructure Validation Results\n\n') +
|
|
561
|
+
`${statusIcon(validationResults.awsCredentials)} AWS Credentials: ${validationResults.awsCredentials ? chalk_1.default.green('Valid') : chalk_1.default.red('Invalid')}\n` +
|
|
562
|
+
`${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` +
|
|
563
|
+
`${statusIcon(validationResults.s3Access)} S3 Path Validation: ${validationResults.s3Access ? chalk_1.default.green('Path structure valid') : chalk_1.default.red('Invalid path')}\n` +
|
|
564
|
+
`${statusIcon(validationResults.walletValid)} Wallet Address: ${validationResults.walletValid ? chalk_1.default.green('Valid format') : chalk_1.default.red('Invalid format')}\n` +
|
|
565
|
+
`${statusIcon(validationResults.rpcConnection)} Story Protocol RPC: ${validationResults.rpcConnection ? chalk_1.default.green('Connected') : chalk_1.default.red('Connection failed')}\n` +
|
|
566
|
+
`${statusIcon(validationResults.collectionExists)} Collection On-Chain: ${validationResults.collectionExists ? chalk_1.default.green('Verified') : chalk_1.default.red('Not found')}\n` +
|
|
567
|
+
`${statusIcon(validationResults.apiConnection)} API Endpoint: ${validationResults.apiConnection ? chalk_1.default.green('Accessible') : chalk_1.default.red('Not accessible')}\n\n` +
|
|
568
|
+
(allValid
|
|
569
|
+
? chalk_1.default.green.bold('โ
All infrastructure checks passed - Ready to tokenize!')
|
|
570
|
+
: chalk_1.default.yellow.bold('โ ๏ธ Some infrastructure checks failed - Fix issues before tokenizing'));
|
|
571
|
+
|
|
572
|
+
console.log((0, boxen_1.default)(infrastructureStatus, {
|
|
573
|
+
padding: 1,
|
|
574
|
+
margin: 1,
|
|
575
|
+
borderStyle: 'round',
|
|
576
|
+
borderColor: validationColor,
|
|
577
|
+
title: '๐ง Infrastructure Status',
|
|
578
|
+
titleAlignment: 'center'
|
|
579
|
+
}));
|
|
580
|
+
|
|
581
|
+
console.log('\n');
|
|
582
|
+
console.log((0, boxen_1.default)(chalk_1.default.cyan.bold('๐งช DRY RUN MODE COMPLETE\n\n') +
|
|
583
|
+
chalk_1.default.white('All validation and AI classification steps completed!\n\n') +
|
|
584
|
+
chalk_1.default.gray('โ
File validated and fingerprinted\n') +
|
|
585
|
+
chalk_1.default.gray('โ
AI metadata generated by Claude Haiku\n') +
|
|
586
|
+
chalk_1.default.gray('โ
Collection and license configured\n') +
|
|
587
|
+
chalk_1.default.gray(`${allValid ? 'โ
' : 'โ ๏ธ '} Infrastructure validation ${allValid ? 'passed' : 'has issues'}\n\n`) +
|
|
588
|
+
chalk_1.default.yellow('โธ๏ธ Tokenization paused before data upload and blockchain minting\n\n') +
|
|
589
|
+
chalk_1.default.white('To proceed with actual tokenization, run without --dryrun flag:\n\n') +
|
|
590
|
+
chalk_1.default.cyan(`biofs tokenize "${absolutePath}" --network ${networkName} --license ${options.license || 'non-commercial'}`), {
|
|
591
|
+
padding: 1,
|
|
592
|
+
margin: 1,
|
|
593
|
+
borderStyle: 'double',
|
|
594
|
+
borderColor: 'cyan',
|
|
595
|
+
title: '๐งช Dry Run Complete',
|
|
596
|
+
titleAlignment: 'center'
|
|
597
|
+
}));
|
|
598
|
+
console.log('\n');
|
|
599
|
+
return; // Exit without tokenizing
|
|
600
|
+
}
|
|
601
|
+
|
|
286
602
|
// Step 5: Upload to GenoBank with Web3 signature authentication
|
|
287
603
|
spinner = (0, ora_1.default)(`Step ${currentStep}/${steps}: ๐ค Uploading to secure GenoBank vault with Web3 authentication...`).start();
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
-
}
|
|
604
|
+
|
|
605
|
+
// Check file size to determine upload method (fileSize already defined from fileStats at line 34)
|
|
606
|
+
const CLOUDFLARE_LIMIT = 100 * 1024 * 1024; // 100MB CloudFlare limit
|
|
607
|
+
|
|
608
|
+
let response;
|
|
609
|
+
let s3Path;
|
|
610
|
+
|
|
611
|
+
if (fileSize > CLOUDFLARE_LIMIT) {
|
|
612
|
+
// Large file: Use direct S3 upload to bypass CloudFlare
|
|
613
|
+
spinner.text = `Step ${currentStep}/${steps}: ๐ค Large file detected (${(0, format_1.formatFileSize)(fileSize)}), uploading directly to S3...`;
|
|
614
|
+
|
|
615
|
+
const AWS = require('aws-sdk');
|
|
616
|
+
|
|
617
|
+
// Require AWS credentials from environment
|
|
618
|
+
if (!process.env.S3_ACCESS_KEY || !process.env.S3_SECRET_KEY) {
|
|
619
|
+
spinner.fail(`Step ${currentStep}/${steps}: โ AWS credentials not found`);
|
|
620
|
+
console.error(chalk_1.default.red('\nโ ๏ธ AWS credentials required for S3 upload'));
|
|
621
|
+
console.error(chalk_1.default.yellow('Please set S3_ACCESS_KEY and S3_SECRET_KEY environment variables\n'));
|
|
622
|
+
process.exit(1);
|
|
315
623
|
}
|
|
316
|
-
|
|
624
|
+
|
|
625
|
+
const s3 = new AWS.S3({
|
|
626
|
+
accessKeyId: process.env.S3_ACCESS_KEY,
|
|
627
|
+
secretAccessKey: process.env.S3_SECRET_KEY,
|
|
628
|
+
region: 'us-west-1'
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
const bucket = networkName === 'mainnet' ? 'vault.genoverse.io' : 'test.vault.genoverse.io';
|
|
632
|
+
const registrationId = `bioip_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
633
|
+
s3Path = `biowallet/${credentials.wallet_address}/bioip/${registrationId}/${fileName}`;
|
|
634
|
+
|
|
635
|
+
// Upload to S3 with progress
|
|
636
|
+
const fileBuffer = await (0, promises_1.readFile)(absolutePath);
|
|
637
|
+
await s3.upload({
|
|
638
|
+
Bucket: bucket,
|
|
639
|
+
Key: s3Path,
|
|
640
|
+
Body: fileBuffer
|
|
641
|
+
}).on('httpUploadProgress', (progress) => {
|
|
642
|
+
const percentCompleted = Math.round((progress.loaded * 100) / progress.total);
|
|
643
|
+
const progressBar = 'โ'.repeat(Math.floor(percentCompleted / 5)) + 'โ'.repeat(20 - Math.floor(percentCompleted / 5));
|
|
644
|
+
spinner.text = `Step ${currentStep}/${steps}: ๐ค Uploading to S3 ${(0, format_1.formatFileSize)(progress.loaded)}/${(0, format_1.formatFileSize)(progress.total)} ${progressBar} ${percentCompleted}%`;
|
|
645
|
+
}).promise();
|
|
646
|
+
|
|
647
|
+
spinner.text = `Step ${currentStep}/${steps}: ๐ค S3 upload complete, registering on blockchain...`;
|
|
648
|
+
|
|
649
|
+
// Register with API using s3_path parameter (bypasses CloudFlare)
|
|
650
|
+
const formDataS3 = new form_data_1.default();
|
|
651
|
+
formDataS3.append('user_signature', credentials.user_signature);
|
|
652
|
+
formDataS3.append('s3_path', s3Path);
|
|
653
|
+
formDataS3.append('title', aiTitle);
|
|
654
|
+
formDataS3.append('description', aiDescription || `${detectedCategory} dataset`);
|
|
655
|
+
formDataS3.append('license_type', (0, licenses_1.getLicenseType)(options.license || 'non-commercial'));
|
|
656
|
+
formDataS3.append('fingerprint', fingerprint);
|
|
657
|
+
formDataS3.append('file_category', detectedCategory);
|
|
658
|
+
formDataS3.append('collection_address', collectionAddress);
|
|
659
|
+
formDataS3.append('image_url', (0, collections_1.getDefaultImageForCategory)(detectedCategory));
|
|
660
|
+
formDataS3.append('network', networkName);
|
|
661
|
+
|
|
662
|
+
response = await axios_1.default.post(`${API_BASE}/register_bioip`, formDataS3, {
|
|
663
|
+
headers: {
|
|
664
|
+
...formDataS3.getHeaders()
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
} else {
|
|
668
|
+
// Small file: Use standard upload through CloudFlare
|
|
669
|
+
const fileBuffer = await (0, promises_1.readFile)(absolutePath);
|
|
670
|
+
const formData = new form_data_1.default();
|
|
671
|
+
formData.append('user_signature', credentials.user_signature);
|
|
672
|
+
formData.append('file', fileBuffer, fileName);
|
|
673
|
+
formData.append('title', aiTitle);
|
|
674
|
+
formData.append('description', aiDescription || `${detectedCategory} dataset`);
|
|
675
|
+
formData.append('license_type', (0, licenses_1.getLicenseType)(options.license || 'non-commercial'));
|
|
676
|
+
formData.append('fingerprint', fingerprint);
|
|
677
|
+
formData.append('file_category', detectedCategory);
|
|
678
|
+
formData.append('collection_address', collectionAddress);
|
|
679
|
+
formData.append('image_url', (0, collections_1.getDefaultImageForCategory)(detectedCategory));
|
|
680
|
+
formData.append('network', networkName);
|
|
681
|
+
|
|
682
|
+
response = await axios_1.default.post(`${API_BASE}/register_bioip`, formData, {
|
|
683
|
+
headers: {
|
|
684
|
+
...formData.getHeaders()
|
|
685
|
+
},
|
|
686
|
+
maxBodyLength: Infinity,
|
|
687
|
+
maxContentLength: Infinity,
|
|
688
|
+
onUploadProgress: (progressEvent) => {
|
|
689
|
+
if (progressEvent.total) {
|
|
690
|
+
const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
|
|
691
|
+
const progressBar = 'โ'.repeat(Math.floor(percentCompleted / 5)) + 'โ'.repeat(20 - Math.floor(percentCompleted / 5));
|
|
692
|
+
spinner.text = `Step ${currentStep}/${steps}: ๐ค Uploading ${(0, format_1.formatFileSize)(progressEvent.loaded)}/${(0, format_1.formatFileSize)(progressEvent.total)} ${progressBar} ${percentCompleted}%`;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
|
|
317
698
|
spinner.succeed(`Step ${currentStep}/${steps}: โ Uploaded to encrypted S3 vault & registered in MongoDB`);
|
|
318
699
|
currentStep++;
|
|
319
700
|
// Debug: Log the response structure
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ const program = new commander_1.Command();
|
|
|
31
31
|
program
|
|
32
32
|
.name('biofs')
|
|
33
33
|
.description('BioFS by GenoBank.io - BioNFT-Gated S3 CLI for genomic data')
|
|
34
|
-
.version('1.
|
|
34
|
+
.version('1.5.2')
|
|
35
35
|
.option('--debug', 'Enable debug output')
|
|
36
36
|
.hook('preAction', (thisCommand) => {
|
|
37
37
|
// Set global debug flag if --debug is passed
|
|
@@ -167,6 +167,7 @@ program
|
|
|
167
167
|
.option('--collection <address>', 'Manual collection address override')
|
|
168
168
|
.option('--network <network>', 'Story Protocol network: mainnet, testnet', 'mainnet')
|
|
169
169
|
.option('--no-ai', 'Skip AI classification')
|
|
170
|
+
.option('--dryrun', 'Test validation and preview metadata without tokenizing')
|
|
170
171
|
.option('--quiet', 'No interactive prompts')
|
|
171
172
|
.option('--yes', 'Auto-confirm all prompts')
|
|
172
173
|
.action(async (file, options) => {
|
|
@@ -369,7 +370,7 @@ program
|
|
|
369
370
|
// Show welcome message if no command
|
|
370
371
|
if (process.argv.length === 2) {
|
|
371
372
|
console.log(chalk_1.default.cyan('\nโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ'));
|
|
372
|
-
console.log(chalk_1.default.cyan('โ BioFS CLI v1.
|
|
373
|
+
console.log(chalk_1.default.cyan('โ BioFS CLI v1.5.2 โ'));
|
|
373
374
|
console.log(chalk_1.default.cyan('โ BioNFT-Gated S3 CLI โ'));
|
|
374
375
|
console.log(chalk_1.default.cyan('โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n'));
|
|
375
376
|
console.log('Available commands:');
|
|
@@ -410,6 +411,7 @@ process.on('unhandledRejection', (error) => {
|
|
|
410
411
|
});
|
|
411
412
|
process.on('SIGINT', () => {
|
|
412
413
|
console.log('\n\nInterrupted. Goodbye!');
|
|
413
|
-
|
|
414
|
+
// Give inquirer time to clean up before exiting
|
|
415
|
+
setTimeout(() => process.exit(0), 100);
|
|
414
416
|
});
|
|
415
417
|
//# sourceMappingURL=index.js.map
|
|
@@ -30,7 +30,8 @@ exports.BIOIP_COLLECTIONS = {
|
|
|
30
30
|
'ancestry': '0x29853ed299B8FBBe16568840F3Bb2A8E40dc7401',
|
|
31
31
|
'medical_imaging': '0x5021F7438ea502b0c346cB59F8E92B749Ecd74B5',
|
|
32
32
|
'medical': '0x5021F7438ea502b0c346cB59F8E92B749Ecd74B5',
|
|
33
|
-
'dicom': '0x5021F7438ea502b0c346cB59F8E92B749Ecd74B5'
|
|
33
|
+
'dicom': '0x5021F7438ea502b0c346cB59F8E92B749Ecd74B5',
|
|
34
|
+
'vcfannotatedsql': '0xbc35FABac000D011ca739C23032Aa726f83E0BF9' // OpenCRAVAT Annotated SQLite Database
|
|
34
35
|
};
|
|
35
36
|
// IPFS images for each category - synchronized with bioip.js and api_bioip.py
|
|
36
37
|
// CRITICAL: Story Protocol REQUIRES IPFS URLs - external domain images are flagged as BAD_IMAGE
|
|
@@ -51,6 +52,7 @@ const DEFAULT_IMAGES = {
|
|
|
51
52
|
'23andme': 'https://ipfs.genobank.app/ipfs/QmYdZDWBmECcTrnZGWG9QKa316DZq9qz6cSPnGeqPkdByf',
|
|
52
53
|
'ancestry': 'https://ipfs.genobank.app/ipfs/QmYdZDWBmECcTrnZGWG9QKa316DZq9qz6cSPnGeqPkdByf',
|
|
53
54
|
'dtc': 'https://ipfs.genobank.app/ipfs/QmYdZDWBmECcTrnZGWG9QKa316DZq9qz6cSPnGeqPkdByf',
|
|
55
|
+
'vcfannotatedsql': 'https://ipfs.genobank.app/ipfs/QmaMC5gtvatWmk6z1rBjptHrdFXZrzfKCdAe7wBbB155pk', // OpenCRAVAT Annotated SQLite
|
|
54
56
|
// Additional categories - use genomic placeholder for now
|
|
55
57
|
'variant': 'https://ipfs.genobank.app/ipfs/QmP3iuWxFraZJpaMdLWHneBqz7C6HakTm9ppVdzYzsWc2W',
|
|
56
58
|
'alignment': 'https://ipfs.genobank.app/ipfs/QmP3iuWxFraZJpaMdLWHneBqz7C6HakTm9ppVdzYzsWc2W',
|