pal-explorer-cli 0.4.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.
Files changed (156) hide show
  1. package/LICENSE.md +18 -0
  2. package/README.md +314 -0
  3. package/bin/pal.js +230 -0
  4. package/extensions/@palexplorer/analytics/README.md +45 -0
  5. package/extensions/@palexplorer/analytics/docs/MONETIZATION.md +14 -0
  6. package/extensions/@palexplorer/analytics/docs/PLAN.md +23 -0
  7. package/extensions/@palexplorer/analytics/docs/PRIVACY.md +38 -0
  8. package/extensions/@palexplorer/analytics/extension.json +27 -0
  9. package/extensions/@palexplorer/analytics/index.js +186 -0
  10. package/extensions/@palexplorer/analytics/test/analytics.test.js +82 -0
  11. package/extensions/@palexplorer/audit/extension.json +17 -0
  12. package/extensions/@palexplorer/audit/index.js +2 -0
  13. package/extensions/@palexplorer/auth-email/extension.json +17 -0
  14. package/extensions/@palexplorer/auth-email/index.js +102 -0
  15. package/extensions/@palexplorer/auth-oauth/extension.json +16 -0
  16. package/extensions/@palexplorer/auth-oauth/index.js +199 -0
  17. package/extensions/@palexplorer/chat/extension.json +17 -0
  18. package/extensions/@palexplorer/chat/index.js +2 -0
  19. package/extensions/@palexplorer/discovery/extension.json +16 -0
  20. package/extensions/@palexplorer/discovery/index.js +111 -0
  21. package/extensions/@palexplorer/email-notifications/extension.json +23 -0
  22. package/extensions/@palexplorer/email-notifications/index.js +242 -0
  23. package/extensions/@palexplorer/explorer-integration/extension.json +13 -0
  24. package/extensions/@palexplorer/explorer-integration/index.js +122 -0
  25. package/extensions/@palexplorer/groups/extension.json +17 -0
  26. package/extensions/@palexplorer/groups/index.js +2 -0
  27. package/extensions/@palexplorer/networks/extension.json +17 -0
  28. package/extensions/@palexplorer/networks/index.js +2 -0
  29. package/extensions/@palexplorer/share-links/extension.json +17 -0
  30. package/extensions/@palexplorer/share-links/index.js +2 -0
  31. package/extensions/@palexplorer/sync/extension.json +17 -0
  32. package/extensions/@palexplorer/sync/index.js +2 -0
  33. package/extensions/@palexplorer/user-mgmt/extension.json +17 -0
  34. package/extensions/@palexplorer/user-mgmt/index.js +2 -0
  35. package/extensions/@palexplorer/vfs/extension.json +17 -0
  36. package/extensions/@palexplorer/vfs/index.js +167 -0
  37. package/lib/capabilities.js +263 -0
  38. package/lib/commands/analytics.js +175 -0
  39. package/lib/commands/api-keys.js +131 -0
  40. package/lib/commands/audit.js +235 -0
  41. package/lib/commands/auth.js +137 -0
  42. package/lib/commands/backup.js +76 -0
  43. package/lib/commands/billing.js +148 -0
  44. package/lib/commands/chat.js +217 -0
  45. package/lib/commands/cloud-backup.js +231 -0
  46. package/lib/commands/comment.js +99 -0
  47. package/lib/commands/completion.js +203 -0
  48. package/lib/commands/compliance.js +218 -0
  49. package/lib/commands/config.js +136 -0
  50. package/lib/commands/connect.js +44 -0
  51. package/lib/commands/dept.js +294 -0
  52. package/lib/commands/device.js +146 -0
  53. package/lib/commands/download.js +226 -0
  54. package/lib/commands/explorer.js +178 -0
  55. package/lib/commands/extension.js +970 -0
  56. package/lib/commands/favorite.js +90 -0
  57. package/lib/commands/federation.js +270 -0
  58. package/lib/commands/file.js +533 -0
  59. package/lib/commands/group.js +271 -0
  60. package/lib/commands/gui-share.js +29 -0
  61. package/lib/commands/init.js +61 -0
  62. package/lib/commands/invite.js +59 -0
  63. package/lib/commands/list.js +59 -0
  64. package/lib/commands/log.js +116 -0
  65. package/lib/commands/nearby.js +108 -0
  66. package/lib/commands/network.js +251 -0
  67. package/lib/commands/notify.js +198 -0
  68. package/lib/commands/org.js +273 -0
  69. package/lib/commands/pal.js +180 -0
  70. package/lib/commands/permissions.js +216 -0
  71. package/lib/commands/pin.js +97 -0
  72. package/lib/commands/protocol.js +357 -0
  73. package/lib/commands/rbac.js +147 -0
  74. package/lib/commands/recover.js +36 -0
  75. package/lib/commands/register.js +171 -0
  76. package/lib/commands/relay.js +131 -0
  77. package/lib/commands/remote.js +368 -0
  78. package/lib/commands/revoke.js +50 -0
  79. package/lib/commands/scanner.js +280 -0
  80. package/lib/commands/schedule.js +344 -0
  81. package/lib/commands/scim.js +203 -0
  82. package/lib/commands/search.js +181 -0
  83. package/lib/commands/serve.js +438 -0
  84. package/lib/commands/server.js +350 -0
  85. package/lib/commands/share-link.js +199 -0
  86. package/lib/commands/share.js +323 -0
  87. package/lib/commands/sso.js +200 -0
  88. package/lib/commands/status.js +136 -0
  89. package/lib/commands/stream.js +562 -0
  90. package/lib/commands/su.js +187 -0
  91. package/lib/commands/sync.js +827 -0
  92. package/lib/commands/transfers.js +152 -0
  93. package/lib/commands/uninstall.js +188 -0
  94. package/lib/commands/update.js +204 -0
  95. package/lib/commands/user.js +276 -0
  96. package/lib/commands/vfs.js +84 -0
  97. package/lib/commands/web.js +52 -0
  98. package/lib/commands/webhook.js +180 -0
  99. package/lib/commands/whoami.js +59 -0
  100. package/lib/commands/workspace.js +121 -0
  101. package/lib/core/accessLog.js +54 -0
  102. package/lib/core/analytics.js +99 -0
  103. package/lib/core/backup.js +84 -0
  104. package/lib/core/billing.js +336 -0
  105. package/lib/core/bitfieldStore.js +53 -0
  106. package/lib/core/connectionManager.js +182 -0
  107. package/lib/core/dhtDiscovery.js +148 -0
  108. package/lib/core/discoveryClient.js +408 -0
  109. package/lib/core/extensionAnalyzer.js +357 -0
  110. package/lib/core/extensionSandbox.js +250 -0
  111. package/lib/core/extensionWorkerHost.js +166 -0
  112. package/lib/core/extensions.js +1082 -0
  113. package/lib/core/fileDiff.js +69 -0
  114. package/lib/core/groups.js +119 -0
  115. package/lib/core/identity.js +340 -0
  116. package/lib/core/mdnsService.js +126 -0
  117. package/lib/core/networks.js +81 -0
  118. package/lib/core/permissions.js +109 -0
  119. package/lib/core/pro.js +27 -0
  120. package/lib/core/resolver.js +74 -0
  121. package/lib/core/serverList.js +224 -0
  122. package/lib/core/sharePolicy.js +69 -0
  123. package/lib/core/shares.js +325 -0
  124. package/lib/core/signalingServer.js +441 -0
  125. package/lib/core/streamTransport.js +106 -0
  126. package/lib/core/su.js +55 -0
  127. package/lib/core/syncEngine.js +264 -0
  128. package/lib/core/syncState.js +159 -0
  129. package/lib/core/transfers.js +259 -0
  130. package/lib/core/users.js +225 -0
  131. package/lib/core/vfs.js +216 -0
  132. package/lib/core/webServer.js +702 -0
  133. package/lib/core/webrtcStream.js +396 -0
  134. package/lib/crypto/chatEncryption.js +57 -0
  135. package/lib/crypto/shareEncryption.js +195 -0
  136. package/lib/crypto/sharePassword.js +35 -0
  137. package/lib/crypto/streamEncryption.js +189 -0
  138. package/lib/package.json +1 -0
  139. package/lib/protocol/envelope.js +271 -0
  140. package/lib/protocol/handler.js +191 -0
  141. package/lib/protocol/index.js +27 -0
  142. package/lib/protocol/messages.js +247 -0
  143. package/lib/protocol/negotiation.js +127 -0
  144. package/lib/protocol/policy.js +142 -0
  145. package/lib/protocol/router.js +86 -0
  146. package/lib/protocol/sync.js +122 -0
  147. package/lib/utils/cli.js +15 -0
  148. package/lib/utils/config.js +123 -0
  149. package/lib/utils/configIntegrity.js +87 -0
  150. package/lib/utils/downloadDir.js +9 -0
  151. package/lib/utils/explorer.js +83 -0
  152. package/lib/utils/format.js +12 -0
  153. package/lib/utils/help.js +357 -0
  154. package/lib/utils/logger.js +103 -0
  155. package/lib/utils/torrent.js +203 -0
  156. package/package.json +71 -0
@@ -0,0 +1,203 @@
1
+ import chalk from 'chalk';
2
+
3
+ export default function scimCommand(program) {
4
+ const cmd = program
5
+ .command('scim')
6
+ .description('SCIM 2.0 provisioning server (Enterprise)')
7
+ .addHelpText('after', `
8
+ Examples:
9
+ $ pe scim configure --token myBearerToken --port 7475
10
+ $ pe scim start Start SCIM server
11
+ $ pe scim stop Stop SCIM server
12
+ $ pe scim status Show server status
13
+ $ pe scim users List provisioned users
14
+ $ pe scim groups List provisioned groups
15
+ `)
16
+ .action(() => { cmd.outputHelp(); });
17
+
18
+ cmd
19
+ .command('configure')
20
+ .description('set SCIM configuration')
21
+ .option('--token <bearerToken>', 'bearer token for auth')
22
+ .option('--port <port>', 'server port', '7475')
23
+ .option('--endpoint <path>', 'base path', '/scim/v2')
24
+ .action(async (opts) => {
25
+ try {
26
+ const extConfig = (await import('../utils/config.js')).default;
27
+ const existing = extConfig.get('ext.scim-provisioning') || {};
28
+ const token = opts.token || existing.bearerToken || null;
29
+ const config = {
30
+ ...existing,
31
+ bearerToken: null,
32
+ port: parseInt(opts.port, 10) || existing.port || 7475,
33
+ endpoint: opts.endpoint || existing.endpoint || '/scim/v2',
34
+ autoDeactivate: existing.autoDeactivate ?? true,
35
+ };
36
+
37
+ if (token) {
38
+ try {
39
+ const keytar = (await import('keytar')).default;
40
+ await keytar.setPassword('palexplorer', 'scim.token', token);
41
+ } catch {
42
+ config.bearerToken = token;
43
+ }
44
+ }
45
+
46
+ extConfig.set('ext.scim-provisioning', config);
47
+
48
+ console.log(chalk.green('✔ SCIM configuration updated'));
49
+ console.log(` Port: ${chalk.white(config.port)}`);
50
+ console.log(` Endpoint: ${chalk.white(config.endpoint)}`);
51
+ console.log(` Token: ${token ? chalk.gray(token.slice(0, 8) + '...') : chalk.yellow('not set')}`);
52
+ } catch (err) {
53
+ console.error(chalk.red(`Configure failed: ${err.message}`));
54
+ process.exitCode = 1;
55
+ }
56
+ });
57
+
58
+ cmd
59
+ .command('start')
60
+ .description('start SCIM server')
61
+ .action(async () => {
62
+ try {
63
+ const extConfig = (await import('../utils/config.js')).default;
64
+ const config = extConfig.get('ext.scim-provisioning') || {};
65
+
66
+ let hasToken = !!config.bearerToken;
67
+ if (!hasToken) {
68
+ try {
69
+ const keytar = (await import('keytar')).default;
70
+ hasToken = !!(await keytar.getPassword('palexplorer', 'scim.token'));
71
+ } catch {}
72
+ }
73
+ if (!hasToken) {
74
+ console.error(chalk.red('No bearer token configured. Run: pe scim configure --token <token>'));
75
+ process.exitCode = 1;
76
+ return;
77
+ }
78
+
79
+ config.running = true;
80
+ extConfig.set('ext.scim-provisioning', config);
81
+ console.log(chalk.green(`✔ SCIM server marked as running`));
82
+ console.log(` Port: ${chalk.white(config.port || 7475)}`);
83
+ console.log(` Endpoint: ${chalk.white(config.endpoint || '/scim/v2')}`);
84
+ console.log(chalk.gray(' Server lifecycle managed by extension on app startup.'));
85
+ } catch (err) {
86
+ console.error(chalk.red(`Start failed: ${err.message}`));
87
+ process.exitCode = 1;
88
+ }
89
+ });
90
+
91
+ cmd
92
+ .command('stop')
93
+ .description('stop SCIM server')
94
+ .action(async () => {
95
+ try {
96
+ const extConfig = (await import('../utils/config.js')).default;
97
+ const config = extConfig.get('ext.scim-provisioning') || {};
98
+ config.running = false;
99
+ extConfig.set('ext.scim-provisioning', config);
100
+ console.log(chalk.green('✔ SCIM server marked as stopped'));
101
+ } catch (err) {
102
+ console.error(chalk.red(`Stop failed: ${err.message}`));
103
+ process.exitCode = 1;
104
+ }
105
+ });
106
+
107
+ cmd
108
+ .command('status')
109
+ .description('show server status')
110
+ .action(async () => {
111
+ try {
112
+ const extConfig = (await import('../utils/config.js')).default;
113
+ const config = extConfig.get('ext.scim-provisioning') || {};
114
+ const store = extConfig.get('ext_store.scim-provisioning') || {};
115
+
116
+ const userCount = Object.keys(store).filter(k => k.startsWith('scim:user:')).length;
117
+ const groupCount = Object.keys(store).filter(k => k.startsWith('scim:group:')).length;
118
+
119
+ console.log('');
120
+ console.log(chalk.cyan.bold('SCIM Server Status'));
121
+ console.log(chalk.gray('─'.repeat(40)));
122
+ console.log(` Status: ${config.running ? chalk.green('running') : chalk.red('stopped')}`);
123
+ console.log(` Port: ${chalk.white(config.port || 7475)}`);
124
+ console.log(` Endpoint: ${chalk.white(config.endpoint || '/scim/v2')}`);
125
+ let tokenConfigured = !!config.bearerToken;
126
+ if (!tokenConfigured) {
127
+ try {
128
+ const keytar = (await import('keytar')).default;
129
+ tokenConfigured = !!(await keytar.getPassword('palexplorer', 'scim.token'));
130
+ } catch {}
131
+ }
132
+ console.log(` Token: ${tokenConfigured ? chalk.green('configured') : chalk.yellow('not set')}`);
133
+ console.log(` Users: ${chalk.white(userCount)}`);
134
+ console.log(` Groups: ${chalk.white(groupCount)}`);
135
+ console.log('');
136
+ } catch (err) {
137
+ console.error(chalk.red(`Status failed: ${err.message}`));
138
+ process.exitCode = 1;
139
+ }
140
+ });
141
+
142
+ cmd
143
+ .command('users')
144
+ .description('list provisioned users')
145
+ .action(async () => {
146
+ try {
147
+ const extConfig = (await import('../utils/config.js')).default;
148
+ const store = extConfig.get('ext_store.scim-provisioning') || {};
149
+ const users = Object.entries(store)
150
+ .filter(([k]) => k.startsWith('scim:user:'))
151
+ .map(([, v]) => v);
152
+
153
+ if (!users.length) {
154
+ console.log(chalk.gray('No provisioned users.'));
155
+ return;
156
+ }
157
+
158
+ console.log('');
159
+ console.log(chalk.cyan.bold('Provisioned Users'));
160
+ console.log(chalk.gray('─'.repeat(50)));
161
+ for (const user of users) {
162
+ const status = user.active !== false ? chalk.green('active') : chalk.red('deactivated');
163
+ console.log(` ${chalk.white(user.displayName || user.userName || user.id)} ${status}`);
164
+ if (user.userName) console.log(` Username: ${chalk.gray(user.userName)}`);
165
+ if (user.email) console.log(` Email: ${chalk.gray(user.email)}`);
166
+ }
167
+ console.log('');
168
+ } catch (err) {
169
+ console.error(chalk.red(`Users failed: ${err.message}`));
170
+ process.exitCode = 1;
171
+ }
172
+ });
173
+
174
+ cmd
175
+ .command('groups')
176
+ .description('list provisioned groups')
177
+ .action(async () => {
178
+ try {
179
+ const extConfig = (await import('../utils/config.js')).default;
180
+ const store = extConfig.get('ext_store.scim-provisioning') || {};
181
+ const groups = Object.entries(store)
182
+ .filter(([k]) => k.startsWith('scim:group:'))
183
+ .map(([, v]) => v);
184
+
185
+ if (!groups.length) {
186
+ console.log(chalk.gray('No provisioned groups.'));
187
+ return;
188
+ }
189
+
190
+ console.log('');
191
+ console.log(chalk.cyan.bold('Provisioned Groups'));
192
+ console.log(chalk.gray('─'.repeat(50)));
193
+ for (const group of groups) {
194
+ const memberCount = group.members?.length || 0;
195
+ console.log(` ${chalk.white(group.displayName || group.id)} ${chalk.gray(`(${memberCount} members)`)}`);
196
+ }
197
+ console.log('');
198
+ } catch (err) {
199
+ console.error(chalk.red(`Groups failed: ${err.message}`));
200
+ process.exitCode = 1;
201
+ }
202
+ });
203
+ }
@@ -0,0 +1,181 @@
1
+ import chalk from 'chalk';
2
+ import { getIdentity } from '../core/identity.js';
3
+ import { getPrimaryServer } from '../core/discoveryClient.js';
4
+ import { formatSize } from '../utils/format.js';
5
+
6
+ function truncate(str, len) {
7
+ if (!str) return '';
8
+ return str.length > len ? str.slice(0, len - 1) + '\u2026' : str;
9
+ }
10
+
11
+ export default function searchCommand(program) {
12
+ program
13
+ .command('search <query>')
14
+ .description('search for files, pals, or groups on the network')
15
+ .option('--kind <kind>', 'Search kind: files, pals, or groups', 'files')
16
+ .option('--scope <scope>', 'Search scope: public, group, or pal', 'public')
17
+ .option('--type <type>', 'File type: file or directory')
18
+ .option('--category <cat>', 'Category: documents, images, music, video, archives, code')
19
+ .option('--extension <ext>', 'Filter by file extension')
20
+ .option('--min-size <mb>', 'Minimum size in MB', parseFloat)
21
+ .option('--max-size <mb>', 'Maximum size in MB', parseFloat)
22
+ .option('--after <date>', 'Files shared after date (YYYY-MM-DD)')
23
+ .option('--before <date>', 'Files shared before date (YYYY-MM-DD)')
24
+ .option('--case-sensitive', 'Case-sensitive search')
25
+ .option('--sort <field>', 'Sort by: name, date, size, relevance', 'relevance')
26
+ .option('--limit <n>', 'Max results', parseInt, 20)
27
+ .addHelpText('after', `
28
+ Examples:
29
+ $ pe search "project plans" Search public shares
30
+ $ pe search "alice" --kind pals Search for users
31
+ $ pe search "linux" --kind groups Search for groups
32
+ $ pe search "*.pdf" --category documents Search for PDFs
33
+ `)
34
+ .action(async (query, opts) => {
35
+ try {
36
+ const identity = await getIdentity();
37
+ const server = getPrimaryServer();
38
+ const jsonMode = program.opts().json;
39
+
40
+ if (opts.kind === 'pals') {
41
+ const res = await fetch(`${server}/api/v1/directory?q=${encodeURIComponent(query)}`, {
42
+ signal: AbortSignal.timeout(10000),
43
+ });
44
+ if (!res.ok) throw new Error(`Search failed: ${res.statusText}`);
45
+ const data = await res.json();
46
+ const results = data.results || [];
47
+ if (results.length === 0) {
48
+ if (jsonMode) { console.log(JSON.stringify({ kind: 'pals', query, results: [] }, null, 2)); return; }
49
+ console.log(chalk.gray(`No pals found for "${query}".`));
50
+ return;
51
+ }
52
+ if (jsonMode) {
53
+ console.log(JSON.stringify({ kind: 'pals', query, results }, null, 2));
54
+ return;
55
+ }
56
+ console.log('');
57
+ console.log(chalk.cyan('Handle'.padEnd(20) + 'Public Key'));
58
+ console.log(chalk.gray('-'.repeat(60)));
59
+ for (const r of results) {
60
+ console.log(`${chalk.white(`@${r.handle}`).padEnd(20)}${chalk.gray(r.publicKey)}`);
61
+ }
62
+ console.log(chalk.gray(`\n${results.length} result(s)`));
63
+ return;
64
+ }
65
+
66
+ if (opts.kind === 'groups') {
67
+ const res = await fetch(`${server}/api/v1/groups/search?q=${encodeURIComponent(query)}`, {
68
+ signal: AbortSignal.timeout(10000),
69
+ });
70
+ if (!res.ok) throw new Error(`Search failed: ${res.statusText}`);
71
+ const data = await res.json();
72
+ const results = data.results || [];
73
+ if (results.length === 0) {
74
+ if (jsonMode) { console.log(JSON.stringify({ kind: 'groups', query, results: [] }, null, 2)); return; }
75
+ console.log(chalk.gray(`No groups found for "${query}".`));
76
+ return;
77
+ }
78
+ if (jsonMode) {
79
+ console.log(JSON.stringify({ kind: 'groups', query, results }, null, 2));
80
+ return;
81
+ }
82
+ console.log('');
83
+ console.log(chalk.cyan('Group Name'.padEnd(30) + 'Members'.padEnd(10) + 'Owner'));
84
+ console.log(chalk.gray('-'.repeat(65)));
85
+ for (const r of results) {
86
+ const name = truncate(r.name, 29).padEnd(30);
87
+ const members = String(r.memberCount || 0).padEnd(10);
88
+ const owner = r.ownerHandle ? `@${r.ownerHandle}` : r.owner.slice(0, 16) + '...';
89
+ console.log(`${chalk.white(name)}${chalk.yellow(members)}${chalk.cyan(owner)}`);
90
+ if (r.description) console.log(chalk.gray(` > ${truncate(r.description, 60)}`));
91
+ }
92
+ console.log(chalk.gray(`\n${results.length} result(s)`));
93
+ return;
94
+ }
95
+
96
+ // Default: kind === 'files'
97
+ const params = new URLSearchParams({ q: query });
98
+ if (opts.scope) params.set('scope', opts.scope);
99
+ if (opts.type) params.set('type', opts.type);
100
+ if (opts.category) params.set('category', opts.category);
101
+ if (opts.extension) params.set('extension', opts.extension);
102
+ if (opts.minSize) params.set('minSize', opts.minSize);
103
+ if (opts.maxSize) params.set('maxSize', opts.maxSize);
104
+ if (opts.after) params.set('after', opts.after);
105
+ if (opts.before) params.set('before', opts.before);
106
+ if (opts.caseSensitive) params.set('caseSensitive', 'true');
107
+ if (opts.sort) params.set('sort', opts.sort);
108
+ if (opts.limit) params.set('limit', opts.limit);
109
+
110
+ const headers = {};
111
+ if (identity?.publicKey) headers['X-Public-Key'] = identity.publicKey;
112
+ if (identity?.handle) headers['X-Handle'] = identity.handle;
113
+
114
+ const res = await fetch(`${server}/api/v1/search?${params}`, {
115
+ headers,
116
+ signal: AbortSignal.timeout(15000),
117
+ });
118
+
119
+ if (!res.ok) {
120
+ const err = await res.json().catch(() => ({}));
121
+ console.log(chalk.red(`Search failed: ${err.error || res.statusText}`));
122
+ process.exitCode = 1;
123
+ return;
124
+ }
125
+
126
+ const data = await res.json();
127
+ const results = data.results || data;
128
+
129
+ if (!Array.isArray(results) || results.length === 0) {
130
+ if (jsonMode) { console.log(JSON.stringify({ kind: 'files', query, results: [], total: 0 }, null, 2)); return; }
131
+ console.log(chalk.gray(`No results for "${query}".`));
132
+ return;
133
+ }
134
+
135
+ if (jsonMode) {
136
+ console.log(JSON.stringify({ kind: 'files', query, results, total: data.total || results.length }, null, 2));
137
+ return;
138
+ }
139
+
140
+ const nameW = 35;
141
+ const sizeW = 10;
142
+ const typeW = 10;
143
+ const ownerW = 15;
144
+ const dateW = 12;
145
+ const seedW = 7;
146
+
147
+ console.log('');
148
+ console.log(
149
+ chalk.cyan(
150
+ 'Name'.padEnd(nameW) +
151
+ 'Size'.padEnd(sizeW) +
152
+ 'Type'.padEnd(typeW) +
153
+ 'Owner'.padEnd(ownerW) +
154
+ 'Date'.padEnd(dateW) +
155
+ 'Seeders'
156
+ )
157
+ );
158
+ console.log(chalk.gray('-'.repeat(nameW + sizeW + typeW + ownerW + dateW + seedW)));
159
+
160
+ for (const r of results) {
161
+ const name = truncate(r.name || r.filename || '?', nameW - 1).padEnd(nameW);
162
+ const size = formatSize(r.size).padEnd(sizeW);
163
+ const type = (r.type || r.category || '-').padEnd(typeW);
164
+ const owner = truncate(r.owner || r.handle || '-', ownerW - 1).padEnd(ownerW);
165
+ const date = r.date || r.sharedAt ? new Date(r.date || r.sharedAt).toLocaleDateString() : '-';
166
+ const seeders = r.seeders != null ? String(r.seeders) : '-';
167
+
168
+ console.log(
169
+ `${chalk.white(name)}${chalk.yellow(size)}${chalk.gray(type)}${chalk.cyan(owner)}${chalk.gray(date.padEnd(dateW))}${chalk.green(seeders)}`
170
+ );
171
+ }
172
+
173
+ console.log('');
174
+ const total = data.total || results.length;
175
+ console.log(chalk.gray(`${results.length} result(s)${total > results.length ? ` of ${total} total` : ''}`));
176
+ } catch (err) {
177
+ console.log(chalk.red(`Error: ${err.message}`));
178
+ process.exitCode = 1;
179
+ }
180
+ });
181
+ }