pal-explorer-cli 0.4.11 → 0.4.13
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/README.md +149 -149
- package/bin/pal.js +63 -2
- package/extensions/@palexplorer/analytics/extension.json +20 -1
- package/extensions/@palexplorer/analytics/index.js +19 -9
- package/extensions/@palexplorer/audit/extension.json +14 -0
- package/extensions/@palexplorer/auth-email/extension.json +15 -0
- package/extensions/@palexplorer/auth-oauth/extension.json +15 -0
- package/extensions/@palexplorer/chat/extension.json +14 -0
- package/extensions/@palexplorer/discovery/extension.json +17 -0
- package/extensions/@palexplorer/discovery/index.js +1 -1
- package/extensions/@palexplorer/email-notifications/extension.json +23 -0
- package/extensions/@palexplorer/groups/extension.json +15 -0
- package/extensions/@palexplorer/share-links/extension.json +15 -0
- package/extensions/@palexplorer/sync/extension.json +16 -0
- package/extensions/@palexplorer/user-mgmt/extension.json +15 -0
- package/lib/capabilities.js +24 -24
- package/lib/commands/analytics.js +175 -175
- package/lib/commands/api-keys.js +131 -131
- package/lib/commands/audit.js +235 -235
- package/lib/commands/auth.js +137 -137
- package/lib/commands/backup.js +76 -76
- package/lib/commands/billing.js +148 -148
- package/lib/commands/chat.js +217 -217
- package/lib/commands/cloud-backup.js +231 -231
- package/lib/commands/comment.js +99 -99
- package/lib/commands/completion.js +203 -203
- package/lib/commands/compliance.js +218 -218
- package/lib/commands/config.js +136 -136
- package/lib/commands/connect.js +44 -44
- package/lib/commands/dept.js +294 -294
- package/lib/commands/device.js +146 -146
- package/lib/commands/download.js +240 -226
- package/lib/commands/explorer.js +178 -178
- package/lib/commands/extension.js +1060 -970
- package/lib/commands/favorite.js +90 -90
- package/lib/commands/federation.js +270 -270
- package/lib/commands/file.js +533 -533
- package/lib/commands/group.js +271 -271
- package/lib/commands/gui-share.js +29 -29
- package/lib/commands/init.js +61 -61
- package/lib/commands/invite.js +59 -59
- package/lib/commands/list.js +58 -58
- package/lib/commands/log.js +116 -116
- package/lib/commands/nearby.js +108 -108
- package/lib/commands/network.js +251 -251
- package/lib/commands/notify.js +198 -198
- package/lib/commands/org.js +273 -273
- package/lib/commands/pal.js +403 -180
- package/lib/commands/permissions.js +216 -216
- package/lib/commands/pin.js +97 -97
- package/lib/commands/protocol.js +357 -357
- package/lib/commands/rbac.js +147 -147
- package/lib/commands/recover.js +36 -36
- package/lib/commands/register.js +171 -171
- package/lib/commands/relay.js +131 -131
- package/lib/commands/remote.js +368 -368
- package/lib/commands/revoke.js +50 -50
- package/lib/commands/scanner.js +280 -280
- package/lib/commands/schedule.js +344 -344
- package/lib/commands/scim.js +203 -203
- package/lib/commands/search.js +181 -181
- package/lib/commands/serve.js +438 -438
- package/lib/commands/server.js +350 -350
- package/lib/commands/share-link.js +199 -199
- package/lib/commands/share.js +336 -323
- package/lib/commands/sso.js +200 -200
- package/lib/commands/status.js +145 -145
- package/lib/commands/stream.js +562 -562
- package/lib/commands/su.js +187 -187
- package/lib/commands/sync.js +979 -979
- package/lib/commands/transfers.js +152 -152
- package/lib/commands/uninstall.js +188 -188
- package/lib/commands/update.js +204 -204
- package/lib/commands/user.js +276 -276
- package/lib/commands/vfs.js +84 -84
- package/lib/commands/web-login.js +79 -79
- package/lib/commands/web.js +52 -52
- package/lib/commands/webhook.js +180 -180
- package/lib/commands/whoami.js +59 -59
- package/lib/commands/workspace.js +121 -121
- package/lib/core/billing.js +16 -5
- package/lib/core/dhtDiscovery.js +9 -2
- package/lib/core/discoveryClient.js +13 -7
- package/lib/core/extensions.js +142 -1
- package/lib/core/identity.js +33 -2
- package/lib/core/imageProcessor.js +109 -0
- package/lib/core/imageTorrent.js +167 -0
- package/lib/core/permissions.js +1 -1
- package/lib/core/pro.js +11 -4
- package/lib/core/serverList.js +4 -1
- package/lib/core/shares.js +12 -1
- package/lib/core/signalingServer.js +14 -2
- package/lib/core/su.js +1 -1
- package/lib/core/users.js +1 -1
- package/lib/protocol/messages.js +12 -3
- package/lib/utils/explorer.js +1 -1
- package/lib/utils/help.js +357 -357
- package/lib/utils/torrent.js +1 -0
- package/package.json +4 -3
package/lib/commands/auth.js
CHANGED
|
@@ -1,137 +1,137 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import readline from 'readline';
|
|
3
|
-
import { getExtension, loadExtension, deployBundledExtensions, BUNDLED_DIR } from '../core/extensions.js';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import fs from 'fs';
|
|
6
|
-
|
|
7
|
-
export default function authCommand(program) {
|
|
8
|
-
const auth = program
|
|
9
|
-
.command('auth')
|
|
10
|
-
.description('manage account linking and identity verification');
|
|
11
|
-
|
|
12
|
-
auth
|
|
13
|
-
.command('login [email]')
|
|
14
|
-
.description('login with email OTP to link your account')
|
|
15
|
-
.action(async (email) => {
|
|
16
|
-
// 1. Ensure extension is loaded
|
|
17
|
-
let ext = getExtension('@palexplorer/auth-email');
|
|
18
|
-
if (!ext) {
|
|
19
|
-
console.log(chalk.blue('Loading auth-email extension...'));
|
|
20
|
-
deployBundledExtensions();
|
|
21
|
-
const appDir = path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Z]:)/, '$1'));
|
|
22
|
-
const extPath = path.resolve(appDir, '../../extensions/@palexplorer/auth-email');
|
|
23
|
-
const manifest = JSON.parse(fs.readFileSync(path.join(extPath, 'extension.json'), 'utf8'));
|
|
24
|
-
await loadExtension(extPath, { ...manifest, bundled: true });
|
|
25
|
-
ext = getExtension('@palexplorer/auth-email');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (!ext || !ext.ctx?.auth) {
|
|
29
|
-
console.log(chalk.red('Error: auth-email extension not available.'));
|
|
30
|
-
process.exitCode = 1;
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const authExt = ext.ctx.auth;
|
|
35
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
36
|
-
const ask = (q) => new Promise(r => rl.question(q, r));
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
let targetEmail = email;
|
|
40
|
-
if (!targetEmail) {
|
|
41
|
-
targetEmail = await ask('Enter your email address: ');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (!targetEmail || !targetEmail.includes('@')) {
|
|
45
|
-
console.log(chalk.red('Invalid email address.'));
|
|
46
|
-
rl.close();
|
|
47
|
-
process.exitCode = 1;
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
console.log(chalk.blue(`Sending verification code to ${targetEmail}...`));
|
|
52
|
-
await authExt.requestVerificationCode(targetEmail);
|
|
53
|
-
console.log(chalk.green('✔ Code sent! Please check your inbox.'));
|
|
54
|
-
|
|
55
|
-
const code = await ask('Enter the 6-digit code: ');
|
|
56
|
-
if (!code || code.length !== 6) {
|
|
57
|
-
console.log(chalk.red('Invalid code format.'));
|
|
58
|
-
rl.close();
|
|
59
|
-
process.exitCode = 1;
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
console.log(chalk.blue('Verifying...'));
|
|
64
|
-
await authExt.confirmCode(targetEmail, code);
|
|
65
|
-
console.log(chalk.green(`✔ Email ${targetEmail} verified successfully!`));
|
|
66
|
-
|
|
67
|
-
console.log(chalk.blue('Linking your Palexplorer identity...'));
|
|
68
|
-
await authExt.linkIdentity();
|
|
69
|
-
console.log(chalk.green('✔ Identity linked! You now have a verified badge.'));
|
|
70
|
-
|
|
71
|
-
rl.close();
|
|
72
|
-
} catch (err) {
|
|
73
|
-
rl.close();
|
|
74
|
-
console.log(chalk.red(`Login failed: ${err.message}`));
|
|
75
|
-
process.exitCode = 1;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
auth
|
|
80
|
-
.command('google')
|
|
81
|
-
.description('link your account using Google')
|
|
82
|
-
.action(async () => {
|
|
83
|
-
const { getIdentity } = await import('../core/identity.js');
|
|
84
|
-
const { getPrimaryServer } = await import('../core/discoveryClient.js');
|
|
85
|
-
const identity = await getIdentity();
|
|
86
|
-
if (!identity?.publicKey) {
|
|
87
|
-
console.log(chalk.red('No identity found. Run `
|
|
88
|
-
process.exitCode = 1; return;
|
|
89
|
-
}
|
|
90
|
-
const baseUrl = getPrimaryServer();
|
|
91
|
-
const returnUrl = encodeURIComponent('palexplorer://auth-callback');
|
|
92
|
-
const url = `${baseUrl}/auth/google?publicKey=${encodeURIComponent(identity.publicKey)}&return_url=${returnUrl}`;
|
|
93
|
-
console.log(chalk.blue('Opening browser for Google login...'));
|
|
94
|
-
console.log(chalk.gray(`URL: ${url}`));
|
|
95
|
-
const { default: open } = await import('open');
|
|
96
|
-
await open(url);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
auth
|
|
100
|
-
.command('github')
|
|
101
|
-
.description('link your account using GitHub')
|
|
102
|
-
.action(async () => {
|
|
103
|
-
const { getIdentity } = await import('../core/identity.js');
|
|
104
|
-
const { getPrimaryServer } = await import('../core/discoveryClient.js');
|
|
105
|
-
const identity = await getIdentity();
|
|
106
|
-
if (!identity?.publicKey) {
|
|
107
|
-
console.log(chalk.red('No identity found. Run `
|
|
108
|
-
process.exitCode = 1; return;
|
|
109
|
-
}
|
|
110
|
-
const baseUrl = getPrimaryServer();
|
|
111
|
-
const returnUrl = encodeURIComponent('palexplorer://auth-callback');
|
|
112
|
-
const url = `${baseUrl}/auth/github?publicKey=${encodeURIComponent(identity.publicKey)}&return_url=${returnUrl}`;
|
|
113
|
-
console.log(chalk.blue('Opening browser for GitHub login...'));
|
|
114
|
-
console.log(chalk.gray(`URL: ${url}`));
|
|
115
|
-
const { default: open } = await import('open');
|
|
116
|
-
await open(url);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
auth
|
|
120
|
-
.command('status')
|
|
121
|
-
.description('show current authentication status')
|
|
122
|
-
.action(async () => {
|
|
123
|
-
let ext = getExtension('@palexplorer/auth-email');
|
|
124
|
-
if (!ext || !ext.ctx?.config) {
|
|
125
|
-
console.log(chalk.gray('Authentication extension not loaded.'));
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const verifiedEmail = ext.ctx.config.get('verifiedEmail');
|
|
130
|
-
if (verifiedEmail) {
|
|
131
|
-
console.log(chalk.green(`✔ Verified: ${verifiedEmail}`));
|
|
132
|
-
console.log(chalk.gray(` Token: ${ext.ctx.config.get('verifiedToken').slice(0, 32)}...`));
|
|
133
|
-
} else {
|
|
134
|
-
console.log(chalk.yellow('! Not verified. Run `
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
}
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import readline from 'readline';
|
|
3
|
+
import { getExtension, loadExtension, deployBundledExtensions, BUNDLED_DIR } from '../core/extensions.js';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
|
|
7
|
+
export default function authCommand(program) {
|
|
8
|
+
const auth = program
|
|
9
|
+
.command('auth')
|
|
10
|
+
.description('manage account linking and identity verification');
|
|
11
|
+
|
|
12
|
+
auth
|
|
13
|
+
.command('login [email]')
|
|
14
|
+
.description('login with email OTP to link your account')
|
|
15
|
+
.action(async (email) => {
|
|
16
|
+
// 1. Ensure extension is loaded
|
|
17
|
+
let ext = getExtension('@palexplorer/auth-email');
|
|
18
|
+
if (!ext) {
|
|
19
|
+
console.log(chalk.blue('Loading auth-email extension...'));
|
|
20
|
+
deployBundledExtensions();
|
|
21
|
+
const appDir = path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Z]:)/, '$1'));
|
|
22
|
+
const extPath = path.resolve(appDir, '../../extensions/@palexplorer/auth-email');
|
|
23
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(extPath, 'extension.json'), 'utf8'));
|
|
24
|
+
await loadExtension(extPath, { ...manifest, bundled: true });
|
|
25
|
+
ext = getExtension('@palexplorer/auth-email');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!ext || !ext.ctx?.auth) {
|
|
29
|
+
console.log(chalk.red('Error: auth-email extension not available.'));
|
|
30
|
+
process.exitCode = 1;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const authExt = ext.ctx.auth;
|
|
35
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
36
|
+
const ask = (q) => new Promise(r => rl.question(q, r));
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
let targetEmail = email;
|
|
40
|
+
if (!targetEmail) {
|
|
41
|
+
targetEmail = await ask('Enter your email address: ');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!targetEmail || !targetEmail.includes('@')) {
|
|
45
|
+
console.log(chalk.red('Invalid email address.'));
|
|
46
|
+
rl.close();
|
|
47
|
+
process.exitCode = 1;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
console.log(chalk.blue(`Sending verification code to ${targetEmail}...`));
|
|
52
|
+
await authExt.requestVerificationCode(targetEmail);
|
|
53
|
+
console.log(chalk.green('✔ Code sent! Please check your inbox.'));
|
|
54
|
+
|
|
55
|
+
const code = await ask('Enter the 6-digit code: ');
|
|
56
|
+
if (!code || code.length !== 6) {
|
|
57
|
+
console.log(chalk.red('Invalid code format.'));
|
|
58
|
+
rl.close();
|
|
59
|
+
process.exitCode = 1;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
console.log(chalk.blue('Verifying...'));
|
|
64
|
+
await authExt.confirmCode(targetEmail, code);
|
|
65
|
+
console.log(chalk.green(`✔ Email ${targetEmail} verified successfully!`));
|
|
66
|
+
|
|
67
|
+
console.log(chalk.blue('Linking your Palexplorer identity...'));
|
|
68
|
+
await authExt.linkIdentity();
|
|
69
|
+
console.log(chalk.green('✔ Identity linked! You now have a verified badge.'));
|
|
70
|
+
|
|
71
|
+
rl.close();
|
|
72
|
+
} catch (err) {
|
|
73
|
+
rl.close();
|
|
74
|
+
console.log(chalk.red(`Login failed: ${err.message}`));
|
|
75
|
+
process.exitCode = 1;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
auth
|
|
80
|
+
.command('google')
|
|
81
|
+
.description('link your account using Google')
|
|
82
|
+
.action(async () => {
|
|
83
|
+
const { getIdentity } = await import('../core/identity.js');
|
|
84
|
+
const { getPrimaryServer } = await import('../core/discoveryClient.js');
|
|
85
|
+
const identity = await getIdentity();
|
|
86
|
+
if (!identity?.publicKey) {
|
|
87
|
+
console.log(chalk.red('No identity found. Run `pal init` first.'));
|
|
88
|
+
process.exitCode = 1; return;
|
|
89
|
+
}
|
|
90
|
+
const baseUrl = getPrimaryServer();
|
|
91
|
+
const returnUrl = encodeURIComponent('palexplorer://auth-callback');
|
|
92
|
+
const url = `${baseUrl}/auth/google?publicKey=${encodeURIComponent(identity.publicKey)}&return_url=${returnUrl}`;
|
|
93
|
+
console.log(chalk.blue('Opening browser for Google login...'));
|
|
94
|
+
console.log(chalk.gray(`URL: ${url}`));
|
|
95
|
+
const { default: open } = await import('open');
|
|
96
|
+
await open(url);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
auth
|
|
100
|
+
.command('github')
|
|
101
|
+
.description('link your account using GitHub')
|
|
102
|
+
.action(async () => {
|
|
103
|
+
const { getIdentity } = await import('../core/identity.js');
|
|
104
|
+
const { getPrimaryServer } = await import('../core/discoveryClient.js');
|
|
105
|
+
const identity = await getIdentity();
|
|
106
|
+
if (!identity?.publicKey) {
|
|
107
|
+
console.log(chalk.red('No identity found. Run `pal init` first.'));
|
|
108
|
+
process.exitCode = 1; return;
|
|
109
|
+
}
|
|
110
|
+
const baseUrl = getPrimaryServer();
|
|
111
|
+
const returnUrl = encodeURIComponent('palexplorer://auth-callback');
|
|
112
|
+
const url = `${baseUrl}/auth/github?publicKey=${encodeURIComponent(identity.publicKey)}&return_url=${returnUrl}`;
|
|
113
|
+
console.log(chalk.blue('Opening browser for GitHub login...'));
|
|
114
|
+
console.log(chalk.gray(`URL: ${url}`));
|
|
115
|
+
const { default: open } = await import('open');
|
|
116
|
+
await open(url);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
auth
|
|
120
|
+
.command('status')
|
|
121
|
+
.description('show current authentication status')
|
|
122
|
+
.action(async () => {
|
|
123
|
+
let ext = getExtension('@palexplorer/auth-email');
|
|
124
|
+
if (!ext || !ext.ctx?.config) {
|
|
125
|
+
console.log(chalk.gray('Authentication extension not loaded.'));
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const verifiedEmail = ext.ctx.config.get('verifiedEmail');
|
|
130
|
+
if (verifiedEmail) {
|
|
131
|
+
console.log(chalk.green(`✔ Verified: ${verifiedEmail}`));
|
|
132
|
+
console.log(chalk.gray(` Token: ${ext.ctx.config.get('verifiedToken').slice(0, 32)}...`));
|
|
133
|
+
} else {
|
|
134
|
+
console.log(chalk.yellow('! Not verified. Run `pal auth login` to link an email.'));
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
package/lib/commands/backup.js
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { createBackup, restoreBackup } from '../core/backup.js';
|
|
5
|
-
|
|
6
|
-
export default function backupCommand(program) {
|
|
7
|
-
const cmd = program
|
|
8
|
-
.command('backup')
|
|
9
|
-
.description('create and restore encrypted backups (Pro)')
|
|
10
|
-
.addHelpText('after', `
|
|
11
|
-
Examples:
|
|
12
|
-
$
|
|
13
|
-
$
|
|
14
|
-
$
|
|
15
|
-
$
|
|
16
|
-
`)
|
|
17
|
-
.action(() => {
|
|
18
|
-
cmd.outputHelp();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
cmd
|
|
22
|
-
.command('create')
|
|
23
|
-
.description('create an encrypted backup of identity, shares, pals, and settings')
|
|
24
|
-
.option('-o, --output <path>', 'Output file path')
|
|
25
|
-
.option('-p, --password <password>', 'Encryption password')
|
|
26
|
-
.action(async (opts) => {
|
|
27
|
-
try {
|
|
28
|
-
const password = opts.password || process.env.
|
|
29
|
-
if (!password) {
|
|
30
|
-
console.log(chalk.red('Password required. Use --password or
|
|
31
|
-
process.exitCode = 1;
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const backupData = await createBackup(password);
|
|
36
|
-
const outPath = opts.output || `palexplorer-backup-${new Date().toISOString().slice(0, 10)}.json`;
|
|
37
|
-
const resolved = path.resolve(outPath);
|
|
38
|
-
fs.writeFileSync(resolved, backupData, 'utf8');
|
|
39
|
-
console.log(chalk.green(`✔ Backup created: ${resolved}`));
|
|
40
|
-
} catch (err) {
|
|
41
|
-
console.log(chalk.red(`Backup failed: ${err.message}`));
|
|
42
|
-
process.exitCode = 1;
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
cmd
|
|
47
|
-
.command('restore <file>')
|
|
48
|
-
.description('restore from an encrypted backup file')
|
|
49
|
-
.option('-p, --password <password>', 'Decryption password')
|
|
50
|
-
.action(async (file, opts) => {
|
|
51
|
-
try {
|
|
52
|
-
const resolved = path.resolve(file);
|
|
53
|
-
if (!fs.existsSync(resolved)) {
|
|
54
|
-
console.log(chalk.red(`File not found: ${resolved}`));
|
|
55
|
-
process.exitCode = 1;
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const password = opts.password || process.env.
|
|
60
|
-
if (!password) {
|
|
61
|
-
console.log(chalk.red('Password required. Use --password or
|
|
62
|
-
process.exitCode = 1;
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const data = fs.readFileSync(resolved, 'utf8');
|
|
67
|
-
const result = await restoreBackup(data, password);
|
|
68
|
-
console.log(chalk.green('✔ Backup restored successfully.'));
|
|
69
|
-
if (result.sharesRestored) console.log(` Shares: ${chalk.white(result.sharesRestored)}`);
|
|
70
|
-
if (result.palsRestored) console.log(` Pals: ${chalk.white(result.palsRestored)}`);
|
|
71
|
-
} catch (err) {
|
|
72
|
-
console.log(chalk.red(`Restore failed: ${err.message}`));
|
|
73
|
-
process.exitCode = 1;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { createBackup, restoreBackup } from '../core/backup.js';
|
|
5
|
+
|
|
6
|
+
export default function backupCommand(program) {
|
|
7
|
+
const cmd = program
|
|
8
|
+
.command('backup')
|
|
9
|
+
.description('create and restore encrypted backups (Pro)')
|
|
10
|
+
.addHelpText('after', `
|
|
11
|
+
Examples:
|
|
12
|
+
$ pal backup create Create backup (prompted for password)
|
|
13
|
+
$ pal backup create --password "s3cret" Create with password
|
|
14
|
+
$ pal backup create -o ~/backup.json Custom output path
|
|
15
|
+
$ pal backup restore ./palexplorer-backup.json
|
|
16
|
+
`)
|
|
17
|
+
.action(() => {
|
|
18
|
+
cmd.outputHelp();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
cmd
|
|
22
|
+
.command('create')
|
|
23
|
+
.description('create an encrypted backup of identity, shares, pals, and settings')
|
|
24
|
+
.option('-o, --output <path>', 'Output file path')
|
|
25
|
+
.option('-p, --password <password>', 'Encryption password')
|
|
26
|
+
.action(async (opts) => {
|
|
27
|
+
try {
|
|
28
|
+
const password = opts.password || process.env.PAL_BACKUP_PASSWORD;
|
|
29
|
+
if (!password) {
|
|
30
|
+
console.log(chalk.red('Password required. Use --password or PAL_BACKUP_PASSWORD env var.'));
|
|
31
|
+
process.exitCode = 1;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const backupData = await createBackup(password);
|
|
36
|
+
const outPath = opts.output || `palexplorer-backup-${new Date().toISOString().slice(0, 10)}.json`;
|
|
37
|
+
const resolved = path.resolve(outPath);
|
|
38
|
+
fs.writeFileSync(resolved, backupData, 'utf8');
|
|
39
|
+
console.log(chalk.green(`✔ Backup created: ${resolved}`));
|
|
40
|
+
} catch (err) {
|
|
41
|
+
console.log(chalk.red(`Backup failed: ${err.message}`));
|
|
42
|
+
process.exitCode = 1;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
cmd
|
|
47
|
+
.command('restore <file>')
|
|
48
|
+
.description('restore from an encrypted backup file')
|
|
49
|
+
.option('-p, --password <password>', 'Decryption password')
|
|
50
|
+
.action(async (file, opts) => {
|
|
51
|
+
try {
|
|
52
|
+
const resolved = path.resolve(file);
|
|
53
|
+
if (!fs.existsSync(resolved)) {
|
|
54
|
+
console.log(chalk.red(`File not found: ${resolved}`));
|
|
55
|
+
process.exitCode = 1;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const password = opts.password || process.env.PAL_BACKUP_PASSWORD;
|
|
60
|
+
if (!password) {
|
|
61
|
+
console.log(chalk.red('Password required. Use --password or PAL_BACKUP_PASSWORD env var.'));
|
|
62
|
+
process.exitCode = 1;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const data = fs.readFileSync(resolved, 'utf8');
|
|
67
|
+
const result = await restoreBackup(data, password);
|
|
68
|
+
console.log(chalk.green('✔ Backup restored successfully.'));
|
|
69
|
+
if (result.sharesRestored) console.log(` Shares: ${chalk.white(result.sharesRestored)}`);
|
|
70
|
+
if (result.palsRestored) console.log(` Pals: ${chalk.white(result.palsRestored)}`);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
console.log(chalk.red(`Restore failed: ${err.message}`));
|
|
73
|
+
process.exitCode = 1;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|