Skip to content

Commit

Permalink
refactor: compatible request query interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ikxin committed May 28, 2024
1 parent fe02b8c commit 615e6de
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"dependencies": {
"@arco-design/web-vue": "^2.55.1",
"@elysiajs/cors": "^1.0.2",
"@elysiajs/static": "^1.0.3",
"@vueuse/core": "^10.9.0",
"@vueuse/integrations": "^10.9.0",
Expand Down
30 changes: 25 additions & 5 deletions service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Elysia } from 'elysia'
import { execFile } from 'child_process'
import { staticPlugin } from '@elysiajs/static'
import * as schema from './schema'
import { cors } from '@elysiajs/cors'

const sqlite = new Database('sqlite.db')
const db = drizzle(sqlite, { schema })
Expand All @@ -19,7 +20,19 @@ const vlmcsdServers = [
's1.kms.cx',
]

const runVlmcs = (server: string) => {
export type RunVlmcsType = {
domain: string
port?: number
protocol?: number
app?: number
}

const runVlmcs = ({
domain,
port = 1688,
protocol = 6,
app = 26,
}: RunVlmcsType) => {
return new Promise<{
content: string
delay: number
Expand All @@ -29,13 +42,13 @@ const runVlmcs = (server: string) => {
const before = Date.now()
execFile(
`./service/binaries/vlmcs-${platform()}-${arch()}`,
[server],
[`${domain}:${port}`, `-${protocol}`, `-l ${app}`],
{ timeout: 5 * 1000 },
(err, stdout) => {
resolve({
content: stdout.trim(),
delay: Date.now() - before,
server,
server: domain,
status: err ? false : true,
})
},
Expand All @@ -47,7 +60,7 @@ new CronJob(
'0/20 * * * * *',
async function () {
for (const item of vlmcsdServers) {
const result = await runVlmcs(item)
const result = await runVlmcs({ domain: item })
db.insert(schema.logs)
.values({
...result,
Expand All @@ -70,12 +83,19 @@ app.use(
}),
)

app.use(cors())

app.get('/*', () => Bun.file('dist/index.html'))

app.get('/api/record', async () => {
app.get('/api/logs', async () => {
return await db.query.logs.findMany()
})

app.post('/api/check', async (request) => {
const body = request.body as RunVlmcsType
return await runVlmcs(body)
})

app.listen(3000)

console.log(`Elysia is running at on port ${app.server?.url} ...`)
Expand Down
2 changes: 1 addition & 1 deletion src/typings/components.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable */
/* prettier-ignore */
// @ts-nocheck
// Generated by unplugin-vue-components
// Read more: https://github.com/vuejs/core/pull/3399
export {}

/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
AAlert: typeof import('@arco-design/web-vue')['Alert']
Expand Down
2 changes: 1 addition & 1 deletion src/views/tools.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const handleSubmit = async data => {
if (data.errors === undefined) {
resultInfo.loading = true
try {
const { data } = await useAxios('/api/kms/check', {
const { data } = await useAxios('http://localhost:3000/api/check', {
method: 'post',
data: formData.value,
headers: { 'Content-Type': 'multipart/form-data' },
Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default defineConfig({
server: {
proxy: {
'/api': {
target: 'http://localhost:3000',
target: 'http://localhost:3000/',
changeOrigin: true,
},
},
Expand Down

0 comments on commit 615e6de

Please sign in to comment.