pal-explorer-cli 0.4.12 → 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.
Files changed (99) hide show
  1. package/README.md +149 -149
  2. package/bin/pal.js +63 -2
  3. package/extensions/@palexplorer/analytics/extension.json +20 -1
  4. package/extensions/@palexplorer/analytics/index.js +19 -9
  5. package/extensions/@palexplorer/audit/extension.json +14 -0
  6. package/extensions/@palexplorer/auth-email/extension.json +15 -0
  7. package/extensions/@palexplorer/auth-oauth/extension.json +15 -0
  8. package/extensions/@palexplorer/chat/extension.json +14 -0
  9. package/extensions/@palexplorer/discovery/extension.json +17 -0
  10. package/extensions/@palexplorer/discovery/index.js +1 -1
  11. package/extensions/@palexplorer/email-notifications/extension.json +23 -0
  12. package/extensions/@palexplorer/groups/extension.json +15 -0
  13. package/extensions/@palexplorer/share-links/extension.json +15 -0
  14. package/extensions/@palexplorer/sync/extension.json +16 -0
  15. package/extensions/@palexplorer/user-mgmt/extension.json +15 -0
  16. package/lib/capabilities.js +24 -24
  17. package/lib/commands/analytics.js +175 -175
  18. package/lib/commands/api-keys.js +131 -131
  19. package/lib/commands/audit.js +235 -235
  20. package/lib/commands/auth.js +137 -137
  21. package/lib/commands/backup.js +76 -76
  22. package/lib/commands/billing.js +148 -148
  23. package/lib/commands/chat.js +217 -217
  24. package/lib/commands/cloud-backup.js +231 -231
  25. package/lib/commands/comment.js +99 -99
  26. package/lib/commands/completion.js +203 -203
  27. package/lib/commands/compliance.js +218 -218
  28. package/lib/commands/config.js +136 -136
  29. package/lib/commands/connect.js +44 -44
  30. package/lib/commands/dept.js +294 -294
  31. package/lib/commands/device.js +146 -146
  32. package/lib/commands/download.js +240 -226
  33. package/lib/commands/explorer.js +178 -178
  34. package/lib/commands/extension.js +1060 -970
  35. package/lib/commands/favorite.js +90 -90
  36. package/lib/commands/federation.js +270 -270
  37. package/lib/commands/file.js +533 -533
  38. package/lib/commands/group.js +271 -271
  39. package/lib/commands/gui-share.js +29 -29
  40. package/lib/commands/init.js +61 -61
  41. package/lib/commands/invite.js +59 -59
  42. package/lib/commands/list.js +58 -58
  43. package/lib/commands/log.js +116 -116
  44. package/lib/commands/nearby.js +108 -108
  45. package/lib/commands/network.js +251 -251
  46. package/lib/commands/notify.js +198 -198
  47. package/lib/commands/org.js +273 -273
  48. package/lib/commands/pal.js +403 -180
  49. package/lib/commands/permissions.js +216 -216
  50. package/lib/commands/pin.js +97 -97
  51. package/lib/commands/protocol.js +357 -357
  52. package/lib/commands/rbac.js +147 -147
  53. package/lib/commands/recover.js +36 -36
  54. package/lib/commands/register.js +171 -171
  55. package/lib/commands/relay.js +131 -131
  56. package/lib/commands/remote.js +368 -368
  57. package/lib/commands/revoke.js +50 -50
  58. package/lib/commands/scanner.js +280 -280
  59. package/lib/commands/schedule.js +344 -344
  60. package/lib/commands/scim.js +203 -203
  61. package/lib/commands/search.js +181 -181
  62. package/lib/commands/serve.js +438 -438
  63. package/lib/commands/server.js +350 -350
  64. package/lib/commands/share-link.js +199 -199
  65. package/lib/commands/share.js +336 -323
  66. package/lib/commands/sso.js +200 -200
  67. package/lib/commands/status.js +145 -145
  68. package/lib/commands/stream.js +562 -562
  69. package/lib/commands/su.js +187 -187
  70. package/lib/commands/sync.js +979 -979
  71. package/lib/commands/transfers.js +152 -152
  72. package/lib/commands/uninstall.js +188 -188
  73. package/lib/commands/update.js +204 -204
  74. package/lib/commands/user.js +276 -276
  75. package/lib/commands/vfs.js +84 -84
  76. package/lib/commands/web-login.js +79 -79
  77. package/lib/commands/web.js +52 -52
  78. package/lib/commands/webhook.js +180 -180
  79. package/lib/commands/whoami.js +59 -59
  80. package/lib/commands/workspace.js +121 -121
  81. package/lib/core/billing.js +16 -5
  82. package/lib/core/dhtDiscovery.js +9 -2
  83. package/lib/core/discoveryClient.js +13 -7
  84. package/lib/core/extensions.js +142 -1
  85. package/lib/core/identity.js +33 -2
  86. package/lib/core/imageProcessor.js +109 -0
  87. package/lib/core/imageTorrent.js +167 -0
  88. package/lib/core/permissions.js +1 -1
  89. package/lib/core/pro.js +11 -4
  90. package/lib/core/serverList.js +4 -1
  91. package/lib/core/shares.js +12 -1
  92. package/lib/core/signalingServer.js +14 -2
  93. package/lib/core/su.js +1 -1
  94. package/lib/core/users.js +1 -1
  95. package/lib/protocol/messages.js +12 -3
  96. package/lib/utils/explorer.js +1 -1
  97. package/lib/utils/help.js +357 -357
  98. package/lib/utils/torrent.js +1 -0
  99. package/package.json +4 -3
@@ -1,199 +1,199 @@
1
- import chalk from 'chalk';
2
- import config from '../utils/config.js';
3
- import { getIdentity } from '../core/identity.js';
4
- import { listShares, getShareKey } from '../core/shares.js';
5
-
6
- const DISCOVERY_URL = process.env.PAL_DISCOVERY_URL || config.get('discoveryUrl') || 'https://discovery-1.palexplorer.com';
7
-
8
- export default function shareLinkCommand(program) {
9
- const cmd = program
10
- .command('share-link')
11
- .description('create and manage web share links')
12
- .addHelpText('after', `
13
- Examples:
14
- $ pe share-link create --magnet "magnet:..." --name "report.pdf"
15
- $ pe share-link create --share abc123 Auto-fill from share ID (includes E2EE key)
16
- $ pe share-link create --magnet "magnet:..." --name "report.pdf" --expires 3d --max-downloads 5
17
- $ pe share-link list
18
- `)
19
- .action(() => {
20
- cmd.outputHelp();
21
- });
22
-
23
- cmd
24
- .command('create')
25
- .description('create a web-accessible share link')
26
- .option('--share <id>', 'Share ID (auto-fills magnet + E2EE key)')
27
- .option('--magnet <uri>', 'Magnet URI of the shared content')
28
- .option('--name <name>', 'File/share name')
29
- .option('--message <msg>', 'Optional message for recipients')
30
- .option('--expires <duration>', 'Expiry (e.g. 1d, 7d, 30d)', '7d')
31
- .option('--max-downloads <n>', 'Max download count (0 = unlimited)', '0')
32
- .option('--password <pwd>', 'Optional password protection')
33
- .action(async (opts) => {
34
- try {
35
- const identity = await getIdentity();
36
- const fromHandle = identity?.handle || 'anonymous';
37
-
38
- let magnet = opts.magnet;
39
- let fileName = opts.name;
40
- let shareKeyHex = null;
41
- let encrypted = false;
42
-
43
- // Auto-fill from share ID
44
- if (opts.share) {
45
- const shares = listShares();
46
- const share = shares.find(s => s.id === opts.share);
47
- if (!share) {
48
- console.log(chalk.red(`Share '${opts.share}' not found. Use 'pe list' to see shares.`));
49
- process.exitCode = 1;
50
- return;
51
- }
52
- if (!share.magnet) {
53
- console.log(chalk.red('Share has no magnet URI yet. Start seeding first: pe serve'));
54
- process.exitCode = 1;
55
- return;
56
- }
57
- magnet = share.magnet;
58
- fileName = fileName || share.name;
59
- if (share.visibility === 'private') {
60
- shareKeyHex = await getShareKey(share.id);
61
- if (shareKeyHex) {
62
- encrypted = true;
63
- } else {
64
- console.log(chalk.yellow('Warning: Private share but no encryption key found. Link will not include decryption key.'));
65
- }
66
- }
67
- }
68
-
69
- if (!magnet) {
70
- console.log(chalk.red('Either --magnet or --share is required.'));
71
- process.exitCode = 1;
72
- return;
73
- }
74
- if (!fileName) {
75
- console.log(chalk.red('--name is required when not using --share.'));
76
- process.exitCode = 1;
77
- return;
78
- }
79
-
80
- const expiresMs = parseDuration(opts.expires);
81
- if (!expiresMs) {
82
- console.log(chalk.red('Invalid --expires format. Use: 1d, 7d, 30d'));
83
- process.exitCode = 1;
84
- return;
85
- }
86
-
87
- const res = await fetch(`${DISCOVERY_URL}/api/v1/share-links`, {
88
- method: 'POST',
89
- headers: { 'Content-Type': 'application/json' },
90
- body: JSON.stringify({
91
- magnet,
92
- fileName,
93
- fromHandle,
94
- message: opts.message || '',
95
- expiresIn: expiresMs,
96
- maxDownloads: parseInt(opts.maxDownloads) || 0,
97
- password: opts.password || null,
98
- encrypted,
99
- }),
100
- signal: AbortSignal.timeout(10000),
101
- });
102
-
103
- if (!res.ok) {
104
- const err = await res.json().catch(() => ({}));
105
- console.log(chalk.red(`Failed: ${err.error || res.statusText}`));
106
- process.exitCode = 1;
107
- return;
108
- }
109
-
110
- const data = await res.json();
111
- // Append E2EE key as URL fragment (never sent to server)
112
- const url = shareKeyHex ? `${data.url}#key=${shareKeyHex}` : data.url;
113
- console.log(chalk.green('✔ Share link created:'));
114
- console.log(` URL: ${chalk.cyan(url)}`);
115
- if (encrypted) console.log(chalk.red(' ⚠ This URL contains the decryption key. Share it securely!'));
116
- console.log(` ID: ${chalk.gray(data.id)}`);
117
- if (data.expiresAt) console.log(` Expires: ${chalk.gray(new Date(data.expiresAt).toLocaleString())}`);
118
- } catch (err) {
119
- console.log(chalk.red(`Error: ${err.message}`));
120
- process.exitCode = 1;
121
- }
122
- });
123
-
124
- cmd
125
- .command('list')
126
- .description('list your active share links')
127
- .action(async () => {
128
- try {
129
- const identity = await getIdentity();
130
- if (!identity?.handle) {
131
- console.log(chalk.red('You must register a handle first: pe register'));
132
- process.exitCode = 1;
133
- return;
134
- }
135
-
136
- const res = await fetch(`${DISCOVERY_URL}/api/v1/share-links?handle=${encodeURIComponent(identity.handle)}`, {
137
- signal: AbortSignal.timeout(10000),
138
- });
139
-
140
- if (!res.ok) {
141
- console.log(chalk.red('Failed to fetch share links.'));
142
- process.exitCode = 1;
143
- return;
144
- }
145
-
146
- const links = await res.json();
147
- if (!Array.isArray(links) || links.length === 0) {
148
- console.log(chalk.gray('No active share links.'));
149
- return;
150
- }
151
-
152
- console.log('');
153
- console.log(chalk.cyan('Share Links:'));
154
- for (const l of links) {
155
- console.log(` ${chalk.white(l.fileName || l.id)}`);
156
- console.log(` URL: ${chalk.cyan(l.url)}`);
157
- if (l.expiresAt) console.log(` Expires: ${chalk.gray(new Date(l.expiresAt).toLocaleString())}`);
158
- if (l.downloads !== undefined) console.log(` Downloads: ${chalk.gray(l.downloads)}`);
159
- }
160
- } catch (err) {
161
- console.log(chalk.red(`Error: ${err.message}`));
162
- process.exitCode = 1;
163
- }
164
- });
165
- cmd
166
- .command('delete <id>')
167
- .description('delete a share link')
168
- .action(async (id) => {
169
- try {
170
- const identity = await getIdentity();
171
- const res = await fetch(`${DISCOVERY_URL}/api/v1/share-links/${encodeURIComponent(id)}`, {
172
- method: 'DELETE',
173
- headers: { 'Content-Type': 'application/json' },
174
- body: JSON.stringify({ handle: identity?.handle }),
175
- signal: AbortSignal.timeout(10000),
176
- });
177
- if (!res.ok) {
178
- console.log(chalk.red('Failed to delete share link.'));
179
- process.exitCode = 1;
180
- return;
181
- }
182
- console.log(chalk.green('✔ Share link deleted.'));
183
- } catch (err) {
184
- console.log(chalk.red(`Error: ${err.message}`));
185
- process.exitCode = 1;
186
- }
187
- });
188
- }
189
-
190
- function parseDuration(str) {
191
- const match = str.match(/^(\d+)([dhm])$/);
192
- if (!match) return null;
193
- const n = parseInt(match[1]);
194
- const unit = match[2];
195
- if (unit === 'd') return n * 86400000;
196
- if (unit === 'h') return n * 3600000;
197
- if (unit === 'm') return n * 60000;
198
- return null;
199
- }
1
+ import chalk from 'chalk';
2
+ import config from '../utils/config.js';
3
+ import { getIdentity } from '../core/identity.js';
4
+ import { listShares, getShareKey } from '../core/shares.js';
5
+
6
+ const DISCOVERY_URL = process.env.PAL_DISCOVERY_URL || config.get('discoveryUrl') || 'https://discovery-1.palexplorer.com';
7
+
8
+ export default function shareLinkCommand(program) {
9
+ const cmd = program
10
+ .command('share-link')
11
+ .description('create and manage web share links')
12
+ .addHelpText('after', `
13
+ Examples:
14
+ $ pal share-link create --magnet "magnet:..." --name "report.pdf"
15
+ $ pal share-link create --share abc123 Auto-fill from share ID (includes E2EE key)
16
+ $ pal share-link create --magnet "magnet:..." --name "report.pdf" --expires 3d --max-downloads 5
17
+ $ pal share-link list
18
+ `)
19
+ .action(() => {
20
+ cmd.outputHelp();
21
+ });
22
+
23
+ cmd
24
+ .command('create')
25
+ .description('create a web-accessible share link')
26
+ .option('--share <id>', 'Share ID (auto-fills magnet + E2EE key)')
27
+ .option('--magnet <uri>', 'Magnet URI of the shared content')
28
+ .option('--name <name>', 'File/share name')
29
+ .option('--message <msg>', 'Optional message for recipients')
30
+ .option('--expires <duration>', 'Expiry (e.g. 1d, 7d, 30d)', '7d')
31
+ .option('--max-downloads <n>', 'Max download count (0 = unlimited)', '0')
32
+ .option('--password <pwd>', 'Optional password protection')
33
+ .action(async (opts) => {
34
+ try {
35
+ const identity = await getIdentity();
36
+ const fromHandle = identity?.handle || 'anonymous';
37
+
38
+ let magnet = opts.magnet;
39
+ let fileName = opts.name;
40
+ let shareKeyHex = null;
41
+ let encrypted = false;
42
+
43
+ // Auto-fill from share ID
44
+ if (opts.share) {
45
+ const shares = listShares();
46
+ const share = shares.find(s => s.id === opts.share);
47
+ if (!share) {
48
+ console.log(chalk.red(`Share '${opts.share}' not found. Use 'pal list' to see shares.`));
49
+ process.exitCode = 1;
50
+ return;
51
+ }
52
+ if (!share.magnet) {
53
+ console.log(chalk.red('Share has no magnet URI yet. Start seeding first: pal serve'));
54
+ process.exitCode = 1;
55
+ return;
56
+ }
57
+ magnet = share.magnet;
58
+ fileName = fileName || share.name;
59
+ if (share.visibility === 'private') {
60
+ shareKeyHex = await getShareKey(share.id);
61
+ if (shareKeyHex) {
62
+ encrypted = true;
63
+ } else {
64
+ console.log(chalk.yellow('Warning: Private share but no encryption key found. Link will not include decryption key.'));
65
+ }
66
+ }
67
+ }
68
+
69
+ if (!magnet) {
70
+ console.log(chalk.red('Either --magnet or --share is required.'));
71
+ process.exitCode = 1;
72
+ return;
73
+ }
74
+ if (!fileName) {
75
+ console.log(chalk.red('--name is required when not using --share.'));
76
+ process.exitCode = 1;
77
+ return;
78
+ }
79
+
80
+ const expiresMs = parseDuration(opts.expires);
81
+ if (!expiresMs) {
82
+ console.log(chalk.red('Invalid --expires format. Use: 1d, 7d, 30d'));
83
+ process.exitCode = 1;
84
+ return;
85
+ }
86
+
87
+ const res = await fetch(`${DISCOVERY_URL}/api/v1/share-links`, {
88
+ method: 'POST',
89
+ headers: { 'Content-Type': 'application/json' },
90
+ body: JSON.stringify({
91
+ magnet,
92
+ fileName,
93
+ fromHandle,
94
+ message: opts.message || '',
95
+ expiresIn: expiresMs,
96
+ maxDownloads: parseInt(opts.maxDownloads) || 0,
97
+ password: opts.password || null,
98
+ encrypted,
99
+ }),
100
+ signal: AbortSignal.timeout(10000),
101
+ });
102
+
103
+ if (!res.ok) {
104
+ const err = await res.json().catch(() => ({}));
105
+ console.log(chalk.red(`Failed: ${err.error || res.statusText}`));
106
+ process.exitCode = 1;
107
+ return;
108
+ }
109
+
110
+ const data = await res.json();
111
+ // Append E2EE key as URL fragment (never sent to server)
112
+ const url = shareKeyHex ? `${data.url}#key=${shareKeyHex}` : data.url;
113
+ console.log(chalk.green('✔ Share link created:'));
114
+ console.log(` URL: ${chalk.cyan(url)}`);
115
+ if (encrypted) console.log(chalk.red(' ⚠ This URL contains the decryption key. Share it securely!'));
116
+ console.log(` ID: ${chalk.gray(data.id)}`);
117
+ if (data.expiresAt) console.log(` Expires: ${chalk.gray(new Date(data.expiresAt).toLocaleString())}`);
118
+ } catch (err) {
119
+ console.log(chalk.red(`Error: ${err.message}`));
120
+ process.exitCode = 1;
121
+ }
122
+ });
123
+
124
+ cmd
125
+ .command('list')
126
+ .description('list your active share links')
127
+ .action(async () => {
128
+ try {
129
+ const identity = await getIdentity();
130
+ if (!identity?.handle) {
131
+ console.log(chalk.red('You must register a handle first: pal register'));
132
+ process.exitCode = 1;
133
+ return;
134
+ }
135
+
136
+ const res = await fetch(`${DISCOVERY_URL}/api/v1/share-links?handle=${encodeURIComponent(identity.handle)}`, {
137
+ signal: AbortSignal.timeout(10000),
138
+ });
139
+
140
+ if (!res.ok) {
141
+ console.log(chalk.red('Failed to fetch share links.'));
142
+ process.exitCode = 1;
143
+ return;
144
+ }
145
+
146
+ const links = await res.json();
147
+ if (!Array.isArray(links) || links.length === 0) {
148
+ console.log(chalk.gray('No active share links.'));
149
+ return;
150
+ }
151
+
152
+ console.log('');
153
+ console.log(chalk.cyan('Share Links:'));
154
+ for (const l of links) {
155
+ console.log(` ${chalk.white(l.fileName || l.id)}`);
156
+ console.log(` URL: ${chalk.cyan(l.url)}`);
157
+ if (l.expiresAt) console.log(` Expires: ${chalk.gray(new Date(l.expiresAt).toLocaleString())}`);
158
+ if (l.downloads !== undefined) console.log(` Downloads: ${chalk.gray(l.downloads)}`);
159
+ }
160
+ } catch (err) {
161
+ console.log(chalk.red(`Error: ${err.message}`));
162
+ process.exitCode = 1;
163
+ }
164
+ });
165
+ cmd
166
+ .command('delete <id>')
167
+ .description('delete a share link')
168
+ .action(async (id) => {
169
+ try {
170
+ const identity = await getIdentity();
171
+ const res = await fetch(`${DISCOVERY_URL}/api/v1/share-links/${encodeURIComponent(id)}`, {
172
+ method: 'DELETE',
173
+ headers: { 'Content-Type': 'application/json' },
174
+ body: JSON.stringify({ handle: identity?.handle }),
175
+ signal: AbortSignal.timeout(10000),
176
+ });
177
+ if (!res.ok) {
178
+ console.log(chalk.red('Failed to delete share link.'));
179
+ process.exitCode = 1;
180
+ return;
181
+ }
182
+ console.log(chalk.green('✔ Share link deleted.'));
183
+ } catch (err) {
184
+ console.log(chalk.red(`Error: ${err.message}`));
185
+ process.exitCode = 1;
186
+ }
187
+ });
188
+ }
189
+
190
+ function parseDuration(str) {
191
+ const match = str.match(/^(\d+)([dhm])$/);
192
+ if (!match) return null;
193
+ const n = parseInt(match[1]);
194
+ const unit = match[2];
195
+ if (unit === 'd') return n * 86400000;
196
+ if (unit === 'h') return n * 3600000;
197
+ if (unit === 'm') return n * 60000;
198
+ return null;
199
+ }