flashroute 0.0.0-stage → 0.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.
- package/LICENSE +21 -0
- package/README.md +16 -2
- package/bin/flashroute.js +103 -0
- package/package.json +23 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 uiautodev
|
|
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,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# flashroute
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Run the [FlashRoute](https://github.com/uiautodev/flashroute) AI gateway with `npx`:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx flashroute
|
|
7
|
+
# open http://localhost:8080
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
The wrapper downloads the matching `flashroute-server-*` binary from the GitHub release for your platform, verifies its SHA-256 checksum, caches it under `~/.cache/flashroute`, and runs it. Arguments are passed through:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npx flashroute -listen 0.0.0.0:8080 -data-dir ~/.config/flashroute
|
|
14
|
+
npx flashroute -version
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Set `FLASHROUTE_CACHE_DIR` to change the download cache location. Set `FLASHROUTE_RELEASE_BASE_URL` to use a release mirror or a local test server.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { createHash } = require('node:crypto');
|
|
5
|
+
const { createWriteStream } = require('node:fs');
|
|
6
|
+
const { chmod, mkdir, readFile, rename, rm } = require('node:fs/promises');
|
|
7
|
+
const { spawn } = require('node:child_process');
|
|
8
|
+
const os = require('node:os');
|
|
9
|
+
const path = require('node:path');
|
|
10
|
+
const { pipeline } = require('node:stream/promises');
|
|
11
|
+
const { Readable } = require('node:stream');
|
|
12
|
+
|
|
13
|
+
const pkg = require('../package.json');
|
|
14
|
+
const version = pkg.version;
|
|
15
|
+
|
|
16
|
+
const platforms = {
|
|
17
|
+
darwin: { x64: 'darwin-x86_64', arm64: 'darwin-arm64' },
|
|
18
|
+
linux: { x64: 'linux-x86_64', arm64: 'linux-arm64' },
|
|
19
|
+
win32: { x64: 'windows-amd64' }
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const arch = platforms[process.platform]?.[process.arch];
|
|
23
|
+
if (!arch) {
|
|
24
|
+
console.error(`flashroute: unsupported platform ${process.platform}/${process.arch}`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
if (!/^\d+\.\d+\.\d+/.test(version)) {
|
|
28
|
+
console.error(`flashroute: invalid package version ${version}`);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const ext = process.platform === 'win32' ? '.exe' : '';
|
|
33
|
+
const asset = `flashroute-server-${arch}-${version}${ext}`;
|
|
34
|
+
const tag = `v${version}`;
|
|
35
|
+
const baseURL =
|
|
36
|
+
process.env.FLASHROUTE_RELEASE_BASE_URL || `https://github.com/uiautodev/flashroute/releases/download/${tag}`;
|
|
37
|
+
const cacheRoot =
|
|
38
|
+
process.env.FLASHROUTE_CACHE_DIR ||
|
|
39
|
+
(process.platform === 'win32'
|
|
40
|
+
? path.join(process.env.LOCALAPPDATA || os.homedir(), 'flashroute')
|
|
41
|
+
: path.join(os.homedir(), '.cache', 'flashroute'));
|
|
42
|
+
const binaryPath = path.join(cacheRoot, 'bin', version, asset);
|
|
43
|
+
|
|
44
|
+
async function download(url, destination, checksum) {
|
|
45
|
+
const response = await fetch(url);
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
throw new Error(`download failed (${response.status}) for ${url}`);
|
|
48
|
+
}
|
|
49
|
+
await mkdir(path.dirname(destination), { recursive: true });
|
|
50
|
+
const temporary = `${destination}.tmp-${process.pid}`;
|
|
51
|
+
await pipeline(Readable.fromWeb(response.body), createWriteStream(temporary));
|
|
52
|
+
if (checksum) {
|
|
53
|
+
const actual = createHash('sha256').update(await readFile(temporary)).digest('hex');
|
|
54
|
+
if (actual !== checksum) {
|
|
55
|
+
await rm(temporary, { force: true });
|
|
56
|
+
throw new Error(`checksum mismatch for ${asset}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
await rename(temporary, destination);
|
|
60
|
+
await chmod(destination, 0o755);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function ensureBinary() {
|
|
64
|
+
try {
|
|
65
|
+
await readFile(binaryPath);
|
|
66
|
+
return binaryPath;
|
|
67
|
+
} catch {
|
|
68
|
+
// Download below.
|
|
69
|
+
}
|
|
70
|
+
const sumsResponse = await fetch(`${baseURL}/SHA256SUMS`);
|
|
71
|
+
if (!sumsResponse.ok) {
|
|
72
|
+
throw new Error(`could not fetch checksums (${sumsResponse.status}) for ${tag}`);
|
|
73
|
+
}
|
|
74
|
+
const sums = await sumsResponse.text();
|
|
75
|
+
const line = sums.split('\n').find((item) => item.trim().split(/\s+/).at(-1) === asset);
|
|
76
|
+
if (!line) {
|
|
77
|
+
throw new Error(`no checksum found for ${asset} in ${tag}`);
|
|
78
|
+
}
|
|
79
|
+
const checksum = line.trim().split(/\s+/)[0];
|
|
80
|
+
console.error(`flashroute: downloading ${asset}...`);
|
|
81
|
+
await download(`${baseURL}/${asset}`, binaryPath, checksum);
|
|
82
|
+
return binaryPath;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function main() {
|
|
86
|
+
let binary;
|
|
87
|
+
try {
|
|
88
|
+
binary = await ensureBinary();
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.error(`flashroute: ${error.message}`);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
const child = spawn(binary, process.argv.slice(2), { stdio: 'inherit' });
|
|
94
|
+
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
95
|
+
process.on(signal, () => child.kill(signal));
|
|
96
|
+
}
|
|
97
|
+
child.on('exit', (code, signal) => {
|
|
98
|
+
if (signal) process.kill(process.pid, signal);
|
|
99
|
+
else process.exit(code ?? 1);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flashroute",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Run the FlashRoute AI gateway with npx flashroute.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/uiautodev/flashroute.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/uiautodev/flashroute",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/uiautodev/flashroute/issues"
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"flashroute": "bin/flashroute.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"bin",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=18"
|
|
24
|
+
}
|
|
25
|
+
}
|