my-airdrop 1.1.0 → 1.1.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.
Files changed (2) hide show
  1. package/bin/cli.js +63 -0
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -4,6 +4,7 @@
4
4
  const path = require('path');
5
5
  const os = require('os');
6
6
  const fs = require('fs');
7
+ const https = require('https');
7
8
  const chalk = require('chalk');
8
9
  const qrcode = require('qrcode-terminal');
9
10
  const localtunnel = require('localtunnel');
@@ -23,6 +24,49 @@ for (let i = 0; i < args.length; i++) {
23
24
  else if (!args[i].startsWith('-')) servePath = path.resolve(args[i]);
24
25
  }
25
26
 
27
+ // ── Interactive select ───────────────────────────────
28
+ function select(question, options) {
29
+ return new Promise(resolve => {
30
+ let idx = 0;
31
+
32
+ function draw() {
33
+ process.stdout.write('\x1B[2J\x1B[H');
34
+ console.log('');
35
+ console.log(' ' + chalk.bold.hex('#818cf8')('◆ ') + chalk.bold.white('my-airdrop'));
36
+ console.log('');
37
+ console.log(' ' + chalk.gray(question));
38
+ console.log('');
39
+ options.forEach((opt, i) => {
40
+ const cursor = i === idx ? chalk.hex('#818cf8')('●') : chalk.gray('○');
41
+ const label = i === idx ? chalk.white(opt.label) : chalk.gray(opt.label);
42
+ const desc = i === idx ? chalk.gray(' ' + opt.desc) : chalk.gray(' ' + opt.desc);
43
+ console.log(' ' + cursor + ' ' + label + desc);
44
+ });
45
+ console.log('');
46
+ console.log(chalk.gray(' ↑↓ to move · Enter to select'));
47
+ }
48
+
49
+ draw();
50
+ process.stdin.setRawMode(true);
51
+ process.stdin.resume();
52
+ process.stdin.setEncoding('utf8');
53
+
54
+ process.stdin.on('data', function handler(key) {
55
+ if (key === '\u0003') { process.stdin.setRawMode(false); process.exit(0); }
56
+ if (key === '\u001B\u005B\u0041' || key === 'k') idx = (idx - 1 + options.length) % options.length; // up
57
+ if (key === '\u001B\u005B\u0042' || key === 'j') idx = (idx + 1) % options.length; // down
58
+ if (key === '\r' || key === '\n') {
59
+ process.stdin.removeListener('data', handler);
60
+ process.stdin.setRawMode(false);
61
+ process.stdin.pause();
62
+ resolve(options[idx].value);
63
+ return;
64
+ }
65
+ draw();
66
+ });
67
+ });
68
+ }
69
+
26
70
  if (!fs.existsSync(servePath) || !fs.statSync(servePath).isDirectory()) {
27
71
  console.error(chalk.red(' Not a directory: ' + servePath));
28
72
  process.exit(1);
@@ -84,6 +128,14 @@ function getLocalIP() {
84
128
 
85
129
  // ── Main ─────────────────────────────────────────────
86
130
  async function main() {
131
+ // Interactive mode if no flags given
132
+ if (process.stdin.isTTY && !args.some(a => a.startsWith('--'))) {
133
+ usePublic = await select('How do you want to share?', [
134
+ { label: 'Local', desc: '— same WiFi only', value: false },
135
+ { label: 'Public', desc: '— accessible from anywhere', value: true },
136
+ ]);
137
+ }
138
+
87
139
  const { count, size } = quickScan(servePath);
88
140
 
89
141
  // Hard limit
@@ -160,6 +212,17 @@ async function main() {
160
212
  const tunnel = await localtunnel({ port });
161
213
  publicURL = tunnel.url;
162
214
  process.stdout.write('\r ' + chalk.gray('Public ') + chalk.bold.cyan(publicURL) + '\n');
215
+
216
+ // Fetch tunnel password (public IP)
217
+ https.get('https://loca.lt/mytunnelpassword', res => {
218
+ let data = '';
219
+ res.on('data', c => data += c);
220
+ res.on('end', () => {
221
+ const pw = data.trim();
222
+ if (pw) console.log(' ' + chalk.gray('Password ') + chalk.bold.yellow(pw) + chalk.gray(' (share this with visitors)'));
223
+ });
224
+ }).on('error', () => {});
225
+
163
226
  tunnel.on('close', () => {
164
227
  console.log('\n' + chalk.yellow(' ⚠ Public tunnel closed'));
165
228
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "my-airdrop",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Share files over local network — like AirDrop but from your terminal",
5
5
  "keywords": [
6
6
  "file-sharing",