@cnife/flyer 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +32 -2
- package/bin/flyer.js +41 -0
- package/lib/install.js +217 -0
- package/package.json +38 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CNife
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @cnife/flyer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Publish HTML to a shareable URL. Defaults to a 1-hour page; optional password, permanent pages, and terminal QR code.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx -y @cnife/flyer@latest publish report.html
|
|
7
|
+
npm install -g @cnife/flyer
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
The package is a small launcher. On first run it downloads the matching `flyer` binary from [GitHub Releases](https://github.com/CNife/flyer/releases), verifies `checksums.txt`, and caches it under `~/.cache/flyer/` (or `%LOCALAPPDATA%\flyer\cache` on Windows). Set `FLYER_CACHE_DIR` to override; set `FLYER_RELEASE_BASE` only for mirrors or testing.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
flyer publish report.html
|
|
16
|
+
flyer publish report.html --ttl 24h
|
|
17
|
+
flyer publish report.html --permanent
|
|
18
|
+
flyer publish report.html --password secret
|
|
19
|
+
cat report.html | flyer publish -
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`stdout` is only the URL; metadata and the QR code go to `stderr`. Use `--no-qr` in scripts and `--json` for structured output.
|
|
23
|
+
|
|
24
|
+
Connect to a server:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
flyer config set server https://flyer.example.com
|
|
28
|
+
flyer config set key fly_...
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Server setup, API, and source: <https://github.com/CNife/flyer>.
|
|
32
|
+
|
|
33
|
+
MIT licensed.
|
package/bin/flyer.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { spawn } = require('node:child_process');
|
|
5
|
+
const { ensureBinary } = require('../lib/install');
|
|
6
|
+
|
|
7
|
+
async function main() {
|
|
8
|
+
const binary = await ensureBinary();
|
|
9
|
+
const child = spawn(binary, process.argv.slice(2), { stdio: 'inherit' });
|
|
10
|
+
|
|
11
|
+
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
12
|
+
process.on(signal, () => {
|
|
13
|
+
try {
|
|
14
|
+
child.kill(signal);
|
|
15
|
+
} catch {
|
|
16
|
+
// the child may already be gone
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
child.on('error', (err) => {
|
|
22
|
+
console.error(`flyer: ${err.message}`);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
});
|
|
25
|
+
child.on('exit', (code, signal) => {
|
|
26
|
+
if (signal) {
|
|
27
|
+
try {
|
|
28
|
+
process.kill(process.pid, signal);
|
|
29
|
+
return;
|
|
30
|
+
} catch {
|
|
31
|
+
// fall through to the numeric exit code
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
process.exit(code ?? 1);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
main().catch((err) => {
|
|
39
|
+
console.error(`flyer: ${err.message}`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
});
|
package/lib/install.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const crypto = require('node:crypto');
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const http = require('node:http');
|
|
6
|
+
const https = require('node:https');
|
|
7
|
+
const os = require('node:os');
|
|
8
|
+
const path = require('node:path');
|
|
9
|
+
const { URL } = require('node:url');
|
|
10
|
+
|
|
11
|
+
const pkg = require('../package.json');
|
|
12
|
+
|
|
13
|
+
const DEFAULT_RELEASE_BASE = 'https://github.com/CNife/flyer/releases/download';
|
|
14
|
+
const MAX_CHECKSUM_BYTES = 1024 * 1024;
|
|
15
|
+
const MAX_BINARY_BYTES = 128 * 1024 * 1024;
|
|
16
|
+
const MAX_REDIRECTS = 5;
|
|
17
|
+
|
|
18
|
+
const PLATFORMS = {
|
|
19
|
+
'linux-x64': { os: 'linux', arch: 'amd64', ext: '' },
|
|
20
|
+
'linux-arm64': { os: 'linux', arch: 'arm64', ext: '' },
|
|
21
|
+
'darwin-x64': { os: 'darwin', arch: 'amd64', ext: '' },
|
|
22
|
+
'darwin-arm64': { os: 'darwin', arch: 'arm64', ext: '' },
|
|
23
|
+
'win32-x64': { os: 'windows', arch: 'amd64', ext: '.exe' },
|
|
24
|
+
'win32-arm64': { os: 'windows', arch: 'arm64', ext: '.exe' },
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function releaseBase() {
|
|
28
|
+
return (process.env.FLYER_RELEASE_BASE || DEFAULT_RELEASE_BASE).replace(/\/+$/, '');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function platformInfo(platform = process.platform, arch = process.arch) {
|
|
32
|
+
const info = PLATFORMS[`${platform}-${arch}`];
|
|
33
|
+
if (!info) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`unsupported platform ${platform}/${arch}; install a binary from https://github.com/CNife/flyer/releases`,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return info;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function assetName(version, goos, goarch) {
|
|
42
|
+
const ext = goos === 'windows' ? '.exe' : '';
|
|
43
|
+
return `flyer_${version}_${goos}_${goarch}${ext}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function checksumsUrl(version) {
|
|
47
|
+
return `${releaseBase()}/v${version}/checksums.txt`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function binaryUrl(version, asset) {
|
|
51
|
+
return `${releaseBase()}/v${version}/${asset}`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function parseChecksums(text) {
|
|
55
|
+
const sums = new Map();
|
|
56
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
57
|
+
const line = raw.trim();
|
|
58
|
+
if (!line || line.startsWith('#')) continue;
|
|
59
|
+
const match = /^([a-fA-F0-9]{64})\s+\*?(.+?)\s*$/.exec(line);
|
|
60
|
+
if (match) sums.set(match[2], match[1].toLowerCase());
|
|
61
|
+
}
|
|
62
|
+
return sums;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function cacheRoot() {
|
|
66
|
+
if (process.env.FLYER_CACHE_DIR) return process.env.FLYER_CACHE_DIR;
|
|
67
|
+
if (process.platform === 'win32' && process.env.LOCALAPPDATA) {
|
|
68
|
+
return path.join(process.env.LOCALAPPDATA, 'flyer', 'cache');
|
|
69
|
+
}
|
|
70
|
+
return path.join(process.env.XDG_CACHE_HOME || path.join(os.homedir(), '.cache'), 'flyer');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function binaryPath(version, info) {
|
|
74
|
+
return path.join(cacheRoot(), version, `${info.os}-${info.arch}`, `flyer${info.ext}`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function isUsable(file) {
|
|
78
|
+
try {
|
|
79
|
+
return fs.statSync(file).size > 0;
|
|
80
|
+
} catch {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function request(url, redirects = 0) {
|
|
86
|
+
if (redirects > MAX_REDIRECTS) {
|
|
87
|
+
return Promise.reject(new Error(`too many redirects for ${url}`));
|
|
88
|
+
}
|
|
89
|
+
const parsed = new URL(url);
|
|
90
|
+
const transport = parsed.protocol === 'https:' ? https : parsed.protocol === 'http:' ? http : null;
|
|
91
|
+
if (!transport) {
|
|
92
|
+
return Promise.reject(new Error(`unsupported URL ${url}`));
|
|
93
|
+
}
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
const req = transport.get(
|
|
96
|
+
parsed,
|
|
97
|
+
{ headers: { 'user-agent': `flyer/${pkg.version}` } },
|
|
98
|
+
(res) => {
|
|
99
|
+
const status = res.statusCode || 0;
|
|
100
|
+
if (status >= 300 && status < 400 && res.headers.location) {
|
|
101
|
+
res.resume();
|
|
102
|
+
resolve(request(new URL(res.headers.location, parsed).toString(), redirects + 1));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (status !== 200) {
|
|
106
|
+
res.resume();
|
|
107
|
+
reject(new Error(`download ${url} failed: HTTP ${status}`));
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
resolve(res);
|
|
111
|
+
},
|
|
112
|
+
);
|
|
113
|
+
req.on('error', reject);
|
|
114
|
+
req.setTimeout(30000, () => req.destroy(new Error(`download ${url} timed out`)));
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async function readText(url, maxBytes = MAX_CHECKSUM_BYTES) {
|
|
119
|
+
const res = await request(url);
|
|
120
|
+
const chunks = [];
|
|
121
|
+
let size = 0;
|
|
122
|
+
for await (const chunk of res) {
|
|
123
|
+
size += chunk.length;
|
|
124
|
+
if (size > maxBytes) {
|
|
125
|
+
res.destroy();
|
|
126
|
+
throw new Error(`download ${url} is too large`);
|
|
127
|
+
}
|
|
128
|
+
chunks.push(chunk);
|
|
129
|
+
}
|
|
130
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function download(url, dest) {
|
|
134
|
+
const res = await request(url);
|
|
135
|
+
await new Promise((resolve, reject) => {
|
|
136
|
+
const out = fs.createWriteStream(dest, { mode: 0o700 });
|
|
137
|
+
let size = 0;
|
|
138
|
+
res.on('data', (chunk) => {
|
|
139
|
+
size += chunk.length;
|
|
140
|
+
if (size > MAX_BINARY_BYTES) {
|
|
141
|
+
res.destroy(new Error(`download ${url} is too large`));
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
res.on('error', reject);
|
|
145
|
+
out.on('error', reject);
|
|
146
|
+
out.on('finish', resolve);
|
|
147
|
+
res.pipe(out);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function sha256(file) {
|
|
152
|
+
const hash = crypto.createHash('sha256');
|
|
153
|
+
hash.update(fs.readFileSync(file));
|
|
154
|
+
return hash.digest('hex');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function equalHex(leftHex, rightHex) {
|
|
158
|
+
const left = Buffer.from(leftHex, 'hex');
|
|
159
|
+
const right = Buffer.from(rightHex, 'hex');
|
|
160
|
+
return left.length > 0 && left.length === right.length && crypto.timingSafeEqual(left, right);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async function ensureBinary() {
|
|
164
|
+
const info = platformInfo();
|
|
165
|
+
const version = pkg.version;
|
|
166
|
+
const dest = binaryPath(version, info);
|
|
167
|
+
if (isUsable(dest)) return dest;
|
|
168
|
+
|
|
169
|
+
const asset = assetName(version, info.os, info.arch);
|
|
170
|
+
const sums = parseChecksums(await readText(checksumsUrl(version)));
|
|
171
|
+
const want = sums.get(asset);
|
|
172
|
+
if (!want) {
|
|
173
|
+
throw new Error(`checksum for ${asset} not found in checksums.txt`);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const dir = path.dirname(dest);
|
|
177
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
178
|
+
const tmp = path.join(dir, `.${asset}.${process.pid}.${Date.now()}`);
|
|
179
|
+
try {
|
|
180
|
+
await download(binaryUrl(version, asset), tmp);
|
|
181
|
+
const got = sha256(tmp);
|
|
182
|
+
if (!equalHex(got, want)) {
|
|
183
|
+
throw new Error(`checksum mismatch for ${asset}: got ${got}, want ${want}`);
|
|
184
|
+
}
|
|
185
|
+
if (process.platform !== 'win32') {
|
|
186
|
+
fs.chmodSync(tmp, 0o755);
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
fs.renameSync(tmp, dest);
|
|
190
|
+
} catch (err) {
|
|
191
|
+
if (isUsable(dest)) {
|
|
192
|
+
fs.unlinkSync(tmp);
|
|
193
|
+
return dest;
|
|
194
|
+
}
|
|
195
|
+
throw err;
|
|
196
|
+
}
|
|
197
|
+
} catch (err) {
|
|
198
|
+
try {
|
|
199
|
+
fs.unlinkSync(tmp);
|
|
200
|
+
} catch {
|
|
201
|
+
// ignore cleanup errors
|
|
202
|
+
}
|
|
203
|
+
throw err;
|
|
204
|
+
}
|
|
205
|
+
return dest;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
module.exports = {
|
|
209
|
+
assetName,
|
|
210
|
+
binaryPath,
|
|
211
|
+
binaryUrl,
|
|
212
|
+
cacheRoot,
|
|
213
|
+
checksumsUrl,
|
|
214
|
+
ensureBinary,
|
|
215
|
+
parseChecksums,
|
|
216
|
+
platformInfo,
|
|
217
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cnife/flyer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Publish HTML to shareable, expiring, password-protected URLs.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/CNife/flyer.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/CNife/flyer",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/CNife/flyer/issues"
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"flyer": "bin/flyer.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"bin",
|
|
19
|
+
"lib",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"test": "node --test"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"flyer",
|
|
34
|
+
"html",
|
|
35
|
+
"share",
|
|
36
|
+
"publish",
|
|
37
|
+
"cli",
|
|
38
|
+
"agent"
|
|
39
|
+
]
|
|
40
|
+
}
|