From fb45c1020e1ab0f5aaf41c5bad0ff3eedcf0ec9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Sun, 5 Jan 2025 10:49:49 +0800 Subject: [PATCH] =?UTF-8?q?revert:=20=E5=86=8D=E4=B9=9F=E4=B8=8D=E7=94=A8u?= =?UTF-8?q?mami=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/umami.ts | 42 ++++++++++++++++++++++++++++------------- src/core/index.ts | 6 ------ src/framework/napcat.ts | 6 ------ src/shell/base.ts | 7 ------- 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/common/umami.ts b/src/common/umami.ts index 1ae88a878..917b92d25 100644 --- a/src/common/umami.ts +++ b/src/common/umami.ts @@ -106,23 +106,39 @@ export class UmamiTraceCore { "Host": "umami.napneko.icu", "Content-Type": "application/json", "User-Agent": this.ua, - ...(this.cache ? { 'x-umami-cache': this.cache } : {}) + ...(this.cache ? { 'x-umami-cache': this.filterInvalidChars(this.cache) } : {}) } }; - - const request = https.request(options, (res) => { - res.on('error', (error) => { - + try { + const request = https.request(options, (res) => { + let responseData = ''; + + res.on('data', (chunk) => { + responseData += chunk; + }); + + res.on('end', () => { + if (!this.cache) { + this.cache = responseData; + console.log('Umami cache:', this.cache); + } + }); + + res.on('error', (error) => { + }); }); - res.on('data', (data) => { - if (!this.cache) { - this.cache = data.toString(); - } + + request.on('error', (error) => { }); - }).on('error', () => { }); - - request.write(JSON.stringify({ type, payload })); - request.end(); + + request.write(JSON.stringify({ type, payload })); + request.end(); + } catch (error) { + } + } + + filterInvalidChars(value: string): string { + return value.replace(/[^\x00-\x7F]/g, ''); } startHeartbeat() { diff --git a/src/core/index.ts b/src/core/index.ts index ef4b101c7..05f407142 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -30,7 +30,6 @@ import os from 'node:os'; import { NodeIKernelMsgListener, NodeIKernelProfileListener } from '@/core/listeners'; import { proxiedListenerOf } from '@/common/proxy-handler'; import { NTQQPacketApi } from './apis/packet'; -import { UmamiTrace } from '@/common/umami'; export * from './wrapper'; export * from './types'; export * from './services'; @@ -155,11 +154,6 @@ export class NapCatCore { const msgListener = new NodeIKernelMsgListener(); msgListener.onKickedOffLine = (Info: KickedOffLineInfo) => { - if (this.context.workingEnv === NapCatCoreWorkingEnv.Framework) { - UmamiTrace.sendTrace('event/kickoff'); - } else { - UmamiTrace.sendTrace('event/kickoff'); - } // 下线通知 this.context.logger.logError('[KickedOffLine] [' + Info.tipsTitle + '] ' + Info.tipsDesc); this.selfInfo.online = false; diff --git a/src/framework/napcat.ts b/src/framework/napcat.ts index 799f3bb1d..84c4c448d 100644 --- a/src/framework/napcat.ts +++ b/src/framework/napcat.ts @@ -9,7 +9,6 @@ import { NodeIKernelLoginService } from '@/core/services'; import { NodeIQQNTWrapperSession, WrapperNodeApi } from '@/core/wrapper'; import { InitWebUi, WebUiConfig } from '@/webui'; import { NapCatOneBot11Adapter } from '@/onebot'; -import { UmamiTrace } from '@/common/umami'; //Framework ES入口文件 export async function getWebUiUrl() { @@ -26,7 +25,6 @@ export async function NCoreInitFramework( console.log('NapCat Framework App Loading...'); process.on('uncaughtException', (err) => { - UmamiTrace.sendTrace('uncaught/error', err.message); console.log('[NapCat] [Error] Unhandled Exception:', err.message); }); @@ -38,10 +36,6 @@ export async function NCoreInitFramework( const logger = new LogWrapper(pathWrapper.logsPath); const basicInfoWrapper = new QQBasicInfoWrapper({ logger }); const wrapper = loadQQWrapper(basicInfoWrapper.getFullQQVesion()); - let guid = loginService.getMachineGuid(); - UmamiTrace.init(basicInfoWrapper.getFullQQVesion(), guid,'framework'); - UmamiTrace.sendTrace('boot/init'); - UmamiTrace.sendTrace('login/success'); //直到登录成功后,执行下一步 const selfInfo = await new Promise((resolveSelfInfo) => { const loginListener = new NodeIKernelLoginListener(); diff --git a/src/shell/base.ts b/src/shell/base.ts index 1e555dde0..914a55cd3 100644 --- a/src/shell/base.ts +++ b/src/shell/base.ts @@ -29,11 +29,9 @@ import { InitWebUi } from '@/webui'; import { WebUiDataRuntime } from '@/webui/src/helper/Data'; import { napCatVersion } from '@/common/version'; import { NodeIO3MiscListener } from '@/core/listeners/NodeIO3MiscListener'; -import { UmamiTrace } from '@/common/umami'; // NapCat Shell App ES 入口文件 async function handleUncaughtExceptions(logger: LogWrapper) { process.on('uncaughtException', (err) => { - UmamiTrace.sendTrace('uncaught/error', err.message); logger.logError('[NapCat] [Error] Unhandled Exception:', err.message); }); process.on('unhandledRejection', (reason, promise) => { @@ -153,7 +151,6 @@ async function handleLogin( }; loginListener.onQRCodeSessionFailed = (errType: number, errCode: number, errMsg: string) => { - UmamiTrace.sendTrace('qrlogin/error', [errType, errCode, errMsg].toString()); if (!isLogined) { logger.logError('[Core] [Login] Login Error,ErrType: ', errType, ' ErrCode:', errCode); if (errType == 1 && errCode == 3) { @@ -164,7 +161,6 @@ async function handleLogin( }; loginListener.onLoginFailed = (...args) => { - UmamiTrace.sendTrace('login/error', args.toString()); logger.logError('[Core] [Login] Login Error , ErrInfo: ', JSON.stringify(args)); }; @@ -298,10 +294,7 @@ export async function NCoreInitShell() { const dataTimestape = new Date().getTime().toString(); o3Service.reportAmgomWeather('login', 'a1', [dataTimestape, '0', '0']); - UmamiTrace.init(basicInfoWrapper.getFullQQVesion(), loginService.getMachineGuid(), 'shell'); - UmamiTrace.sendTrace('boot/init'); const selfInfo = await handleLogin(loginService, logger, pathWrapper, quickLoginUin, historyLoginList); - UmamiTrace.sendTrace('login/success'); const amgomDataPiece = 'eb1fd6ac257461580dc7438eb099f23aae04ca679f4d88f53072dc56e3bb1129'; o3Service.setAmgomDataPiece(basicInfoWrapper.QQVersionAppid, new Uint8Array(Buffer.from(amgomDataPiece, 'hex')));