-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
255 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* build single executable binary with Node.js SEA | ||
*/ | ||
|
||
import * as fs from 'node:fs'; | ||
import * as path from 'node:path/posix'; | ||
import {execSync} from 'node:child_process'; | ||
|
||
async function main() { | ||
const [major, minor, patch] = process.versions.node.split('.').map(Number); | ||
if (major <= 22) { | ||
console.error('need node22 to run this scripts'); | ||
return; | ||
} | ||
|
||
execSync('npm run build'); | ||
const data = JSON.parse(fs.readFileSync('sea-config.tmpl.json').toString()); | ||
const assets = {}; | ||
for await (const p of walk('./dist/assets')) { | ||
assets[path.normalize(p)] = p; | ||
} | ||
|
||
fs.writeFileSync('sea-config.json', JSON.stringify({...data, assets})); | ||
|
||
execSync('node --experimental-sea-config sea-config.json'); | ||
fs.copyFileSync(process.execPath, 'flood.exe'); | ||
execSync( | ||
'npx postject flood.exe NODE_SEA_BLOB sea-prep.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2', | ||
); | ||
} | ||
|
||
async function* walk(dir) { | ||
for await (const d of await fs.promises.opendir(dir)) { | ||
const entry = path.join(dir, d.name); | ||
if (d.isDirectory()) yield* walk(entry); | ||
else if (d.isFile()) yield entry; | ||
} | ||
} | ||
|
||
await main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as zlib from 'node:zlib'; | ||
import * as fs from 'node:fs'; | ||
|
||
const buf = fs.readFileSync('server/geoip/GeoLite2-Country.mmdb'); | ||
|
||
fs.writeFileSync( | ||
'server/geoip/data.mjs', | ||
` | ||
// data is brotli compressed GeoLite2-Country.mmdb in base64 format | ||
export const data = "${zlib.brotliCompressSync(buf).toString('base64')}"; | ||
`, | ||
); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GeoLite2-Country.mmdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const data: string; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as zlib from 'node:zlib'; | ||
|
||
import {Reader} from '@maxmind/geoip2-node'; | ||
|
||
import * as data from '../geoip/data.mjs'; | ||
|
||
const r = Reader.openBuffer(zlib.brotliDecompressSync(Buffer.from(data.data, 'base64'))); | ||
|
||
export function lookup(s: string): string { | ||
try { | ||
return r.country(s)?.country?.isoCode ?? ''; | ||
} catch { | ||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters