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