nemfile 1.0.3 → 1.0.5

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/package.json +1 -1
  2. package/server.js +60 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nemfile",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Send files, screenshots and text between your phone, iPad and computer over local Wi-Fi \u2014 no cloud, no account, no app install. One command: npx nemfile.",
5
5
  "keywords": [
6
6
  "file-transfer",
package/server.js CHANGED
@@ -6,10 +6,41 @@ const os = require('os');
6
6
  const QRCode = require('qrcode');
7
7
  const { Tunnel } = require('cloudflared');
8
8
 
9
+ const pkg = require('./package.json');
10
+
9
11
  const app = express();
10
12
  const PORT = 3333;
11
13
  const NO_TUNNEL = process.argv.includes('--no-tunnel') || process.argv.includes('-L');
12
14
  const UPLOADS_DIR = path.join(process.cwd(), 'uploads');
15
+ const MAX_FILE_SIZE = 2 * 1024 * 1024 * 1024; // 2GB
16
+
17
+ // Colorize only when writing to a real terminal — an interactive TTY. Piped
18
+ // or redirected output (`nemfile > log.txt`, Docker logs, CI) gets plain text
19
+ // instead of raw escape codes.
20
+ const isTTY = process.stdout.isTTY;
21
+ const c = {
22
+ orange: s => (isTTY ? `\x1b[38;5;208m${s}\x1b[0m` : s),
23
+ bold: s => (isTTY ? `\x1b[1m${s}\x1b[0m` : s),
24
+ dim: s => (isTTY ? `\x1b[2m${s}\x1b[0m` : s),
25
+ green: s => (isTTY ? `\x1b[32m${s}\x1b[0m` : s),
26
+ };
27
+
28
+ function printBanner() {
29
+ const logoPlain = 'NEM//FILE';
30
+ const tagline = `local file transfer · v${pkg.version}`;
31
+ const innerWidth = Math.max(logoPlain.length, tagline.length) + 2;
32
+ const pad = s => s + ' '.repeat(innerWidth - s.length);
33
+ // Built by hand instead of composing c.bold()/c.orange() naively: the
34
+ // inner reset from orange('//') would also clear bold before "FILE".
35
+ const logoColored = isTTY ? `\x1b[1mNEM\x1b[38;5;208m//\x1b[39mFILE\x1b[0m` : logoPlain;
36
+
37
+ console.log('');
38
+ console.log(' ╭' + '─'.repeat(innerWidth) + '╮');
39
+ console.log(' │ ' + logoColored + ' '.repeat(innerWidth - logoPlain.length - 1) + '│');
40
+ console.log(' │ ' + c.dim(pad(tagline).slice(0, -1)) + '│');
41
+ console.log(' ╰' + '─'.repeat(innerWidth) + '╯');
42
+ console.log('');
43
+ }
13
44
 
14
45
  if (!fs.existsSync(UPLOADS_DIR)) fs.mkdirSync(UPLOADS_DIR);
15
46
 
@@ -22,7 +53,7 @@ const storage = multer.diskStorage({
22
53
  },
23
54
  });
24
55
 
25
- const upload = multer({ storage, limits: { fileSize: 2 * 1024 * 1024 * 1024 } }); // 2GB
56
+ const upload = multer({ storage, limits: { fileSize: MAX_FILE_SIZE } });
26
57
 
27
58
  const sseClients = new Set();
28
59
  const textClips = []; // in-memory, max 50
@@ -911,8 +942,21 @@ app.post('/upload', upload.single('image'), (req, res) => {
911
942
  res.json({ ok: true, ...payload });
912
943
  });
913
944
 
945
+ function printFooter() {
946
+ console.log('');
947
+ console.log(c.dim(' Press Ctrl+C to stop'));
948
+ console.log('');
949
+ }
950
+
914
951
  app.listen(PORT, '0.0.0.0', async () => {
915
- console.log('\nnemfile is running:\n');
952
+ printBanner();
953
+
954
+ const sizeGB = MAX_FILE_SIZE / 1024 / 1024 / 1024;
955
+
956
+ console.log(' ' + c.green('●') + ' ONLINE ' + c.dim('port ' + PORT));
957
+ console.log(' ' + c.dim('mode ') + (NO_TUNNEL ? 'LAN only (--no-tunnel)' : 'LAN + public tunnel'));
958
+ console.log(' ' + c.dim('uploads ') + UPLOADS_DIR + c.dim(` (max ${sizeGB}GB/file)`));
959
+ console.log('');
916
960
  console.log(' Local: http://localhost:' + PORT);
917
961
 
918
962
  for (const list of Object.values(os.networkInterfaces())) {
@@ -923,9 +967,19 @@ app.listen(PORT, '0.0.0.0', async () => {
923
967
  }
924
968
  }
925
969
 
970
+ console.log('');
971
+ const label = s => c.dim(s.padEnd(10));
972
+ const blank = ' '.repeat(10);
973
+ const method = s => s.padEnd(5);
974
+ const path = s => s.padEnd(16);
975
+
976
+ console.log(' ' + label('Flags') + '--no-tunnel, -L'.padEnd(16) + 'LAN only, skip the public tunnel');
977
+ console.log(' ' + label('API') + method('GET') + path('/api/files') + 'list uploaded files as JSON');
978
+ console.log(' ' + blank + method('POST') + path('/upload') + 'upload a file (multipart field "image")');
979
+
926
980
  if (NO_TUNNEL) {
927
- console.log('\n Public tunnel disabled — LAN only.\n');
928
- return;
981
+ console.log('\n Public tunnel disabled — LAN only.');
982
+ return printFooter();
929
983
  }
930
984
 
931
985
  console.log('\n Starting public tunnel...');
@@ -939,7 +993,8 @@ app.listen(PORT, '0.0.0.0', async () => {
939
993
 
940
994
  tunnel.once('url', url => {
941
995
  publicUrl = url;
942
- console.log(' Public: ' + publicUrl + ' ← use this outside LAN\n');
996
+ console.log(' Public: ' + publicUrl + ' ← use this outside LAN');
997
+ printFooter();
943
998
  });
944
999
  tunnel.on('error', err => {
945
1000
  console.error(' Tunnel error:', err.message);