genbox 1.0.77 → 1.0.79
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/create.js +5 -0
- package/dist/commands/extend.js +45 -4
- package/dist/commands/rebuild.js +11 -0
- package/dist/commands/scan.js +1162 -0
- package/dist/db-utils.js +18 -0
- package/dist/index.js +0 -0
- package/dist/migration.js +335 -0
- package/dist/schema-v3.js +48 -0
- package/package.json +2 -1
package/dist/commands/create.js
CHANGED
|
@@ -555,6 +555,10 @@ exports.createCommand = new commander_1.Command('create')
|
|
|
555
555
|
// Build payload
|
|
556
556
|
const payloadResolved = { ...resolved };
|
|
557
557
|
if (snapshotId && snapshotS3Key) {
|
|
558
|
+
// Extract database name from source URL for restore
|
|
559
|
+
const sourceDatabase = resolved.database?.url
|
|
560
|
+
? (0, db_utils_1.extractDatabaseName)(resolved.database.url)
|
|
561
|
+
: undefined;
|
|
558
562
|
// Use S3 snapshot mode
|
|
559
563
|
payloadResolved.database = {
|
|
560
564
|
...resolved.database,
|
|
@@ -562,6 +566,7 @@ exports.createCommand = new commander_1.Command('create')
|
|
|
562
566
|
mode: 'snapshot',
|
|
563
567
|
snapshotId,
|
|
564
568
|
s3Key: snapshotS3Key,
|
|
569
|
+
sourceDatabase, // Pass the database name for correct restore
|
|
565
570
|
};
|
|
566
571
|
}
|
|
567
572
|
const payload = buildPayload(payloadResolved, config, publicKey, privateKeyContent, configLoader);
|
package/dist/commands/extend.js
CHANGED
|
@@ -7,17 +7,18 @@ exports.extendCommand = void 0;
|
|
|
7
7
|
const commander_1 = require("commander");
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
9
|
const ora_1 = __importDefault(require("ora"));
|
|
10
|
+
const select_1 = __importDefault(require("@inquirer/select"));
|
|
11
|
+
const input_1 = __importDefault(require("@inquirer/input"));
|
|
10
12
|
const api_1 = require("../api");
|
|
11
13
|
const genbox_selector_1 = require("../genbox-selector");
|
|
12
14
|
exports.extendCommand = new commander_1.Command('extend')
|
|
13
15
|
.description('Extend genbox and reset inactivity timer')
|
|
14
16
|
.argument('[name]', 'Name of the Genbox (optional - will auto-select or prompt)')
|
|
15
|
-
.
|
|
17
|
+
.option('-h, --hours <hours>', 'Hours to extend (skip prompt)')
|
|
16
18
|
.option('--no-auto-destroy', 'Disable auto-destroy on inactivity')
|
|
17
19
|
.option('--enable-auto-destroy', 'Re-enable auto-destroy on inactivity')
|
|
18
|
-
.action(async (name,
|
|
20
|
+
.action(async (name, options) => {
|
|
19
21
|
try {
|
|
20
|
-
const hours = parseInt(hoursArg, 10) || 1;
|
|
21
22
|
// Select genbox
|
|
22
23
|
const { genbox: target, cancelled } = await (0, genbox_selector_1.selectGenbox)(name, {
|
|
23
24
|
selectMessage: 'Select a genbox to extend:',
|
|
@@ -33,6 +34,45 @@ exports.extendCommand = new commander_1.Command('extend')
|
|
|
33
34
|
console.error(chalk_1.default.red(`Error: Genbox '${target.name}' is not running (status: ${target.status})`));
|
|
34
35
|
return;
|
|
35
36
|
}
|
|
37
|
+
// Determine hours - from option or prompt
|
|
38
|
+
let hours;
|
|
39
|
+
if (options.hours) {
|
|
40
|
+
hours = parseInt(options.hours, 10);
|
|
41
|
+
if (isNaN(hours) || hours < 1) {
|
|
42
|
+
console.error(chalk_1.default.red('Error: Hours must be a positive number'));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
// Show selection prompt
|
|
48
|
+
const choice = await (0, select_1.default)({
|
|
49
|
+
message: 'How long do you want to extend?',
|
|
50
|
+
choices: [
|
|
51
|
+
{ name: '1 hour', value: 1 },
|
|
52
|
+
{ name: '2 hours', value: 2 },
|
|
53
|
+
{ name: '4 hours', value: 4 },
|
|
54
|
+
{ name: '8 hours', value: 8 },
|
|
55
|
+
{ name: 'Custom...', value: 0 },
|
|
56
|
+
],
|
|
57
|
+
});
|
|
58
|
+
if (choice === 0) {
|
|
59
|
+
const customHours = await (0, input_1.default)({
|
|
60
|
+
message: 'Enter number of hours:',
|
|
61
|
+
validate: (val) => {
|
|
62
|
+
const num = parseInt(val, 10);
|
|
63
|
+
if (isNaN(num) || num < 1)
|
|
64
|
+
return 'Please enter a positive number';
|
|
65
|
+
if (num > 24)
|
|
66
|
+
return 'Maximum 24 hours';
|
|
67
|
+
return true;
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
hours = parseInt(customHours, 10);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
hours = choice;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
36
76
|
// Determine disableAutoDestroy value
|
|
37
77
|
let disableAutoDestroy;
|
|
38
78
|
if (options.autoDestroy === false) {
|
|
@@ -41,7 +81,7 @@ exports.extendCommand = new commander_1.Command('extend')
|
|
|
41
81
|
else if (options.enableAutoDestroy) {
|
|
42
82
|
disableAutoDestroy = false; // --enable-auto-destroy flag
|
|
43
83
|
}
|
|
44
|
-
const spinner = (0, ora_1.default)(`Extending ${target.name}...`).start();
|
|
84
|
+
const spinner = (0, ora_1.default)(`Extending ${target.name} by ${hours} hour${hours > 1 ? 's' : ''}...`).start();
|
|
45
85
|
const result = await (0, api_1.fetchApi)(`/genboxes/${target._id}/extend`, {
|
|
46
86
|
method: 'POST',
|
|
47
87
|
body: JSON.stringify({
|
|
@@ -58,6 +98,7 @@ exports.extendCommand = new commander_1.Command('extend')
|
|
|
58
98
|
console.log(chalk_1.default.dim(` Current hour ends in: ${minutesUntil} minutes`));
|
|
59
99
|
}
|
|
60
100
|
console.log(chalk_1.default.dim(` Auto-destroy: ${result.autoDestroyEnabled ? 'enabled' : 'disabled'}`));
|
|
101
|
+
console.log(chalk_1.default.dim(` Note: Credits charged at the end of each hour`));
|
|
61
102
|
}
|
|
62
103
|
else {
|
|
63
104
|
console.error(chalk_1.default.red(`Error: ${result.message}`));
|
package/dist/commands/rebuild.js
CHANGED
|
@@ -328,6 +328,17 @@ async function runSoftRebuild(options) {
|
|
|
328
328
|
}
|
|
329
329
|
else {
|
|
330
330
|
log('✓ Database restored', 'success');
|
|
331
|
+
// Update MONGODB_URI in app .env files to point to the correct database
|
|
332
|
+
const sourceDatabase = resolved.database?.url
|
|
333
|
+
? (0, db_utils_1.extractDatabaseName)(resolved.database.url)
|
|
334
|
+
: undefined;
|
|
335
|
+
if (sourceDatabase) {
|
|
336
|
+
log('Updating MONGODB_URI in app .env files...', 'info');
|
|
337
|
+
const newMongoUri = `mongodb://localhost:${mongoPort}/${sourceDatabase}`;
|
|
338
|
+
const updateCmd = `find /home/dev -name ".env" -type f -exec grep -l "^MONGODB_URI=" {} \\; | xargs -I{} sed -i 's|^MONGODB_URI=.*|MONGODB_URI=${newMongoUri}|' {}`;
|
|
339
|
+
await sshExec(ip, keyPath, updateCmd, 30);
|
|
340
|
+
log(`✓ MONGODB_URI updated to ${newMongoUri}`, 'success');
|
|
341
|
+
}
|
|
331
342
|
}
|
|
332
343
|
// Cleanup
|
|
333
344
|
await sshExec(ip, keyPath, 'rm -f /tmp/db-snapshot.gz', 10);
|