nemfile 1.0.2 → 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/README.md +36 -0
- package/package.json +1 -1
- package/server.js +85 -3
package/README.md
CHANGED
|
@@ -93,6 +93,38 @@ Open the **LAN** address on your phone — or scan the QR code shown on the page
|
|
|
93
93
|
|
|
94
94
|
To share text instead of a file, paste into the text box and hit send; it shows up as a clip on every other device.
|
|
95
95
|
|
|
96
|
+
### Flags
|
|
97
|
+
|
|
98
|
+
| Flag | Effect |
|
|
99
|
+
| --- | --- |
|
|
100
|
+
| `--no-tunnel`, `-L` | Don't start the public Cloudflare Tunnel — LAN only. |
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
npx nemfile --no-tunnel
|
|
104
|
+
npx nemfile -L # same thing, shorter
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### CLI / scripting (curl, no browser)
|
|
108
|
+
|
|
109
|
+
Every route works from a plain shell, so a headless machine can push and pull files without opening the page at all.
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# Upload a file — the multipart field must be named "image" (any file type works)
|
|
113
|
+
curl -F "image=@photo.png" http://192.168.1.10:3333/upload
|
|
114
|
+
# {"ok":true,"filename":"1699999999999-photo.png","url":"/uploads/1699999999999-photo.png"}
|
|
115
|
+
|
|
116
|
+
# List everything currently on the server, as JSON
|
|
117
|
+
curl http://192.168.1.10:3333/api/files
|
|
118
|
+
# {"ok":true,"files":[{"filename":"...","url":"/uploads/...","size":12345,"uploadedAt":"2026-...Z"}]}
|
|
119
|
+
|
|
120
|
+
# Download a file
|
|
121
|
+
curl -O http://192.168.1.10:3333/uploads/1699999999999-photo.png
|
|
122
|
+
|
|
123
|
+
# List + download every file in one line (needs jq)
|
|
124
|
+
curl -s http://192.168.1.10:3333/api/files | jq -r '.files[].url' | \
|
|
125
|
+
while read -r u; do curl -sO "http://192.168.1.10:3333$u"; done
|
|
126
|
+
```
|
|
127
|
+
|
|
96
128
|
## How it works
|
|
97
129
|
|
|
98
130
|
nemfile starts a small Express server on port `3333` bound to `0.0.0.0`, so any device on the same Wi-Fi can reach it. Uploads are handled by `multer` and written to `./uploads`. A server-sent-events stream keeps every open browser tab in sync, and `qrcode` renders the pairing QR codes. Optionally, a Cloudflare Tunnel (no account needed) exposes the same page on a public HTTPS URL for when the two devices aren't on the same network.
|
|
@@ -137,6 +169,10 @@ Port `3333`, bound to all interfaces so other devices on the network can connect
|
|
|
137
169
|
|
|
138
170
|
In an `uploads/` directory created inside the folder you ran the command from. `cd` somewhere else first if you want them elsewhere.
|
|
139
171
|
|
|
172
|
+
### Can I upload or list files from a script or a headless machine, without a browser?
|
|
173
|
+
|
|
174
|
+
Yes. `POST /upload` (multipart field `image`) and `GET /api/files` (JSON listing) both work from plain `curl` — see [CLI / scripting](#cli--scripting-curl-no-browser) above. Nothing about nemfile requires a browser; the web page is just the most convenient client for a phone.
|
|
175
|
+
|
|
140
176
|
### Is it safe to leave running?
|
|
141
177
|
|
|
142
178
|
On a trusted home or office network, yes — but note that anyone who can reach the port can upload and browse files. Don't leave the public tunnel open on an untrusted network, and stop the server (`Ctrl+C`) when you're done.
|
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,9 +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;
|
|
13
|
+
const NO_TUNNEL = process.argv.includes('--no-tunnel') || process.argv.includes('-L');
|
|
11
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
|
+
}
|
|
12
54
|
|
|
13
55
|
if (!fs.existsSync(UPLOADS_DIR)) fs.mkdirSync(UPLOADS_DIR);
|
|
14
56
|
|
|
@@ -21,7 +63,7 @@ const storage = multer.diskStorage({
|
|
|
21
63
|
},
|
|
22
64
|
});
|
|
23
65
|
|
|
24
|
-
const upload = multer({ storage, limits: { fileSize:
|
|
66
|
+
const upload = multer({ storage, limits: { fileSize: MAX_FILE_SIZE } });
|
|
25
67
|
|
|
26
68
|
const sseClients = new Set();
|
|
27
69
|
const textClips = []; // in-memory, max 50
|
|
@@ -883,6 +925,23 @@ app.delete('/clear', (req, res) => {
|
|
|
883
925
|
res.json({ ok: true, deleted: files.length });
|
|
884
926
|
});
|
|
885
927
|
|
|
928
|
+
// JSON file listing for scripts/CLI use — curl http://host:3333/api/files
|
|
929
|
+
app.get('/api/files', (req, res) => {
|
|
930
|
+
const files = fs.readdirSync(UPLOADS_DIR).sort().reverse();
|
|
931
|
+
res.json({
|
|
932
|
+
ok: true,
|
|
933
|
+
files: files.map(f => {
|
|
934
|
+
const stat = fs.statSync(path.join(UPLOADS_DIR, f));
|
|
935
|
+
return {
|
|
936
|
+
filename: f,
|
|
937
|
+
url: '/uploads/' + f,
|
|
938
|
+
size: stat.size,
|
|
939
|
+
uploadedAt: stat.mtime.toISOString(),
|
|
940
|
+
};
|
|
941
|
+
}),
|
|
942
|
+
});
|
|
943
|
+
});
|
|
944
|
+
|
|
886
945
|
app.post('/upload', upload.single('image'), (req, res) => {
|
|
887
946
|
if (!req.file) return res.json({ ok: false, error: 'No file received' });
|
|
888
947
|
const payload = { filename: req.file.filename, url: '/uploads/' + req.file.filename };
|
|
@@ -893,8 +952,21 @@ app.post('/upload', upload.single('image'), (req, res) => {
|
|
|
893
952
|
res.json({ ok: true, ...payload });
|
|
894
953
|
});
|
|
895
954
|
|
|
955
|
+
function printFooter() {
|
|
956
|
+
console.log('');
|
|
957
|
+
console.log(c.dim(' Press Ctrl+C to stop'));
|
|
958
|
+
console.log('');
|
|
959
|
+
}
|
|
960
|
+
|
|
896
961
|
app.listen(PORT, '0.0.0.0', async () => {
|
|
897
|
-
|
|
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('');
|
|
898
970
|
console.log(' Local: http://localhost:' + PORT);
|
|
899
971
|
|
|
900
972
|
for (const list of Object.values(os.networkInterfaces())) {
|
|
@@ -905,6 +977,14 @@ app.listen(PORT, '0.0.0.0', async () => {
|
|
|
905
977
|
}
|
|
906
978
|
}
|
|
907
979
|
|
|
980
|
+
console.log('');
|
|
981
|
+
await printQR('Scan on your phone (LAN):', `http://${getLocalIP()}:${PORT}`);
|
|
982
|
+
|
|
983
|
+
if (NO_TUNNEL) {
|
|
984
|
+
console.log('\n Public tunnel disabled — LAN only.');
|
|
985
|
+
return printFooter();
|
|
986
|
+
}
|
|
987
|
+
|
|
908
988
|
console.log('\n Starting public tunnel...');
|
|
909
989
|
|
|
910
990
|
// Quick Tunnel (trycloudflare.com): anonymous, no Cloudflare account, no
|
|
@@ -914,9 +994,11 @@ app.listen(PORT, '0.0.0.0', async () => {
|
|
|
914
994
|
// the gallery at once.
|
|
915
995
|
const tunnel = Tunnel.quick(`http://localhost:${PORT}`);
|
|
916
996
|
|
|
917
|
-
tunnel.once('url', url => {
|
|
997
|
+
tunnel.once('url', async url => {
|
|
918
998
|
publicUrl = url;
|
|
919
999
|
console.log(' Public: ' + publicUrl + ' ← use this outside LAN\n');
|
|
1000
|
+
await printQR('Scan from anywhere (public):', url);
|
|
1001
|
+
printFooter();
|
|
920
1002
|
});
|
|
921
1003
|
tunnel.on('error', err => {
|
|
922
1004
|
console.error(' Tunnel error:', err.message);
|