fix: 控制臺不解析 buffer
This commit is contained in:
@@ -10,10 +10,9 @@ import chalk from "chalk"
|
||||
|
||||
function stringifyNotIncludeArrayBuffer(value: any) {
|
||||
return JSON.stringify(value, (_k, v) => {
|
||||
if (v instanceof ArrayBuffer) {
|
||||
if (v?.type == 'Buffer') {
|
||||
return {
|
||||
type: 'ArrayBuffer',
|
||||
byteLength: value.byteLength,
|
||||
type: 'Buffer',
|
||||
data: '[...binary data omitted...]'
|
||||
}
|
||||
}
|
||||
@@ -81,7 +80,7 @@ export default class ApiManager {
|
||||
|
||||
socket.on("The_White_Silk", async (name: string, args: { [key: string]: unknown }, callback_: (ret: ApiCallbackMessage) => void) => {
|
||||
function callback(ret: ApiCallbackMessage) {
|
||||
console.log(chalk.blue('[發]') + ` ${ip} <- ${ret.code == 200 ? chalk.green(ret.msg) : chalk.red(ret.msg)} [${ret.code}]${ret.data ? (' <extras: ' + JSON.stringify(ret.data) + '>') : ''}`)
|
||||
console.log(chalk.blue('[發]') + ` ${ip} <- ${ret.code == 200 ? chalk.green(ret.msg) : chalk.red(ret.msg)} [${ret.code}]${ret.data ? (' <extras: ' + stringifyNotIncludeArrayBuffer(ret.data) + '>') : ''}`)
|
||||
return callback_(ret)
|
||||
}
|
||||
async function checkIsPromiseAndAwait(value: Promise<unknown> | unknown) {
|
||||
@@ -94,7 +93,7 @@ export default class ApiManager {
|
||||
msg: "Invalid request.",
|
||||
code: 400
|
||||
})
|
||||
console.log(chalk.red('[收]') + ` ${ip} -> ${chalk.yellow(name)} <args: ${JSON.stringify(args)}>`)
|
||||
console.log(chalk.red('[收]') + ` ${ip} -> ${chalk.yellow(name)} <args: ${stringifyNotIncludeArrayBuffer(args)}>`)
|
||||
|
||||
return callback(await checkIsPromiseAndAwait(this.event_listeners[name]?.(args, clientInfo)) || {
|
||||
code: 501,
|
||||
|
||||
Reference in New Issue
Block a user