-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from ikxin/feature
refactor: 使用 bun 重构 kms 检测模块
- Loading branch information
Showing
4 changed files
with
33 additions
and
35 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -1,47 +1,31 @@ | ||
import { createServer } from 'http' | ||
import { platform } from 'os' | ||
import { execFile } from 'child_process' | ||
|
||
type Body = { | ||
port: string | ||
host: string | ||
app: string | ||
protocol: '4' | '5' | '6' | ||
} | ||
|
||
const getResult = (body: Body) => { | ||
const { port, host, app, protocol } = body | ||
|
||
const fetchData = params => { | ||
return new Promise(resolve => { | ||
const { host, port, app, protocol } = params | ||
execFile( | ||
`./vlmcs/vlmcs-${platform()}`, | ||
[ | ||
`-${['4', '5', '6'].includes(protocol) ? protocol : '6'}`, | ||
`${host}:${port}`, | ||
`${app === '' ? '' : '-l ' + app}` | ||
], | ||
{ timeout: 5000 }, | ||
(err, std) => { | ||
if (err) { | ||
resolve({ msg: 'error', result: std.toString() }) | ||
} else { | ||
resolve({ msg: 'success', result: std.toString() }) | ||
} | ||
`./service/vlmcs/vlmcs-${platform()}`, | ||
[`-l ${app}`, `-${protocol}`, `${host}:${port}`], | ||
{ timeout: 10 * 1000 }, | ||
function (error, stdout) { | ||
resolve({ result: error ? 'error' : 'success', stdout: stdout.toString() }) | ||
} | ||
) | ||
}) | ||
} | ||
|
||
const server = createServer(async (req, res) => { | ||
const url = new URL(req.url, `http://${req.headers.host}`) | ||
|
||
const body = Object.fromEntries(url.searchParams) as Body | ||
|
||
if (url.pathname === '/check') { | ||
res.end(JSON.stringify(await getResult(body))) | ||
} else { | ||
res.end('KMS Tools') | ||
const server = Bun.serve({ | ||
async fetch(req) { | ||
const url = new URL(req.url) | ||
if (url.pathname === '/api/kms-check') { | ||
const params = Object.fromEntries(url.searchParams) | ||
const result = await fetchData(params) | ||
return new Response(JSON.stringify(result)) | ||
} else { | ||
return new Response(`404!`) | ||
} | ||
} | ||
}) | ||
|
||
server.listen(3000, () => console.log('Server running at http://localhost:3000/')) | ||
console.log(`Server running at http://localhost:${server.port}`) |
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,5 @@ | ||
{ | ||
"compilerOptions": { | ||
"types": ["bun-types"] | ||
} | ||
} |
27dd580
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
kms-tools – ./
kmstools.vercel.app
kms-tools.vercel.app
kms-tools-ikxin.vercel.app
kms-tools-git-master-ikxin.vercel.app