nemfile 1.0.3 → 1.0.4
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/package.json +1 -1
- package/server.js +64 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nemfile",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
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,51 @@ 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
|
+
}
|
|
44
|
+
|
|
45
|
+
async function printQR(label, url) {
|
|
46
|
+
// Skip when not a real terminal — a log file or piped output can't scan a
|
|
47
|
+
// QR code anyway, and qrcode's own renderer doesn't check isTTY, so it
|
|
48
|
+
// would otherwise dump raw ANSI block-art escapes into the log.
|
|
49
|
+
if (!isTTY) return;
|
|
50
|
+
const qr = await QRCode.toString(url, { type: 'terminal', small: true });
|
|
51
|
+
console.log(` ${c.dim(label)}`);
|
|
52
|
+
console.log(qr.split('\n').map(l => ' ' + l).join('\n'));
|
|
53
|
+
}
|
|
13
54
|
|
|
14
55
|
if (!fs.existsSync(UPLOADS_DIR)) fs.mkdirSync(UPLOADS_DIR);
|
|
15
56
|
|
|
@@ -22,7 +63,7 @@ const storage = multer.diskStorage({
|
|
|
22
63
|
},
|
|
23
64
|
});
|
|
24
65
|
|
|
25
|
-
const upload = multer({ storage, limits: { fileSize:
|
|
66
|
+
const upload = multer({ storage, limits: { fileSize: MAX_FILE_SIZE } });
|
|
26
67
|
|
|
27
68
|
const sseClients = new Set();
|
|
28
69
|
const textClips = []; // in-memory, max 50
|
|
@@ -911,8 +952,21 @@ app.post('/upload', upload.single('image'), (req, res) => {
|
|
|
911
952
|
res.json({ ok: true, ...payload });
|
|
912
953
|
});
|
|
913
954
|
|
|
955
|
+
function printFooter() {
|
|
956
|
+
console.log('');
|
|
957
|
+
console.log(c.dim(' Press Ctrl+C to stop'));
|
|
958
|
+
console.log('');
|
|
959
|
+
}
|
|
960
|
+
|
|
914
961
|
app.listen(PORT, '0.0.0.0', async () => {
|
|
915
|
-
|
|
962
|
+
printBanner();
|
|
963
|
+
|
|
964
|
+
const sizeGB = MAX_FILE_SIZE / 1024 / 1024 / 1024;
|
|
965
|
+
|
|
966
|
+
console.log(' ' + c.green('●') + ' ONLINE ' + c.dim('port ' + PORT));
|
|
967
|
+
console.log(' ' + c.dim('mode ') + (NO_TUNNEL ? 'LAN only (--no-tunnel)' : 'LAN + public tunnel'));
|
|
968
|
+
console.log(' ' + c.dim('uploads ') + UPLOADS_DIR + c.dim(` (max ${sizeGB}GB/file)`));
|
|
969
|
+
console.log('');
|
|
916
970
|
console.log(' Local: http://localhost:' + PORT);
|
|
917
971
|
|
|
918
972
|
for (const list of Object.values(os.networkInterfaces())) {
|
|
@@ -923,9 +977,12 @@ app.listen(PORT, '0.0.0.0', async () => {
|
|
|
923
977
|
}
|
|
924
978
|
}
|
|
925
979
|
|
|
980
|
+
console.log('');
|
|
981
|
+
await printQR('Scan on your phone (LAN):', `http://${getLocalIP()}:${PORT}`);
|
|
982
|
+
|
|
926
983
|
if (NO_TUNNEL) {
|
|
927
|
-
console.log('\n Public tunnel disabled — LAN only
|
|
928
|
-
return;
|
|
984
|
+
console.log('\n Public tunnel disabled — LAN only.');
|
|
985
|
+
return printFooter();
|
|
929
986
|
}
|
|
930
987
|
|
|
931
988
|
console.log('\n Starting public tunnel...');
|
|
@@ -937,9 +994,11 @@ app.listen(PORT, '0.0.0.0', async () => {
|
|
|
937
994
|
// the gallery at once.
|
|
938
995
|
const tunnel = Tunnel.quick(`http://localhost:${PORT}`);
|
|
939
996
|
|
|
940
|
-
tunnel.once('url', url => {
|
|
997
|
+
tunnel.once('url', async url => {
|
|
941
998
|
publicUrl = url;
|
|
942
999
|
console.log(' Public: ' + publicUrl + ' ← use this outside LAN\n');
|
|
1000
|
+
await printQR('Scan from anywhere (public):', url);
|
|
1001
|
+
printFooter();
|
|
943
1002
|
});
|
|
944
1003
|
tunnel.on('error', err => {
|
|
945
1004
|
console.error(' Tunnel error:', err.message);
|