Skip to content

Commit

Permalink
细节优化
Browse files Browse the repository at this point in the history
  • Loading branch information
TimeRainStarSky committed Jun 4, 2024
1 parent 5cbff35 commit 3e7c56f
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { EventEmitter } from "events"
import express from "express"
import http from "node:http"
import { WebSocketServer } from "ws"
import _ from "lodash"
import fs from "node:fs/promises"
import path from "node:path"
import util from "node:util"
Expand All @@ -15,7 +14,6 @@ import { exec, execFile } from "node:child_process"
import { fileTypeFromBuffer } from "file-type"
import md5 from "md5"
import { ulid } from "ulid"
import { Level } from "level"

export default class Yunzai extends EventEmitter {
stat = { start_time: Date.now()/1000 }
Expand Down Expand Up @@ -55,7 +53,6 @@ export default class Yunzai extends EventEmitter {
.use(express.text())
.use("/status", req => req.res.send(process.memoryUsage()))
.use(req => {
req.next()
let quiet = false
for (const i of req.app.quiet)
if (req.originalUrl.startsWith(i)) {
Expand All @@ -65,6 +62,7 @@ export default class Yunzai extends EventEmitter {
req.rid = `${req.ip}:${req.socket.remotePort}`
req.sid = `${req.protocol}://${req.hostname}:${req.socket.localPort}${req.originalUrl}`
this.makeLog(quiet?"debug":"mark", ["HTTP", req.method, "请求", req.headers, req.query, req.body], `${req.sid} <= ${req.rid}`)
req.next()
})
.use("/exit", req => {
if (["::1", "::ffff:127.0.0.1"].includes(req.ip) || req.hostname === "localhost")
Expand Down Expand Up @@ -279,7 +277,8 @@ export default class Yunzai extends EventEmitter {

async getMap(dir) {
const map = new Map
const db = new Level(`${dir}-leveldb`, { valueEncoding: "json" })
const db = new (await import("level"))
.Level(`${dir}-leveldb`, { valueEncoding: "json" })
try {
await db.open()
for await (let [key, value] of db.iterator()) {
Expand Down

0 comments on commit 3e7c56f

Please sign in to comment.