diff --git a/napcat.webui/eslint.config.mjs b/napcat.webui/eslint.config.mjs new file mode 100644 index 00000000..76fd91bf --- /dev/null +++ b/napcat.webui/eslint.config.mjs @@ -0,0 +1,53 @@ +import globals from 'globals'; +import ts from 'typescript-eslint'; +import vue from 'eslint-plugin-vue'; +import prettier from 'eslint-plugin-prettier/recommended'; + +export default [ + { + languageOptions: { + globals: { + ...globals.browser, + ...globals.node, + }, + }, + }, + ...ts.configs.recommended, + { + rules: { + '@typescript-eslint/no-explicit-any': 'warn', + '@typescript-eslint/no-unused-vars': 'warn', + '@typescript-eslint/no-var-requires': 'warn', + }, + }, + ...vue.configs['flat/base'], + { + files: ['*.vue', '**/*.vue'], + languageOptions: { + parserOptions: { + parser: ts.parser, + }, + }, + }, + { + rules: { + indent: ['error', 4], + semi: ['error', 'always'], + 'no-unused-vars': 'off', + '@typescript-eslint/no-explicit-any': 'warn', + '@typescript-eslint/no-unused-vars': 'warn', + '@typescript-eslint/no-var-requires': 'warn', + 'object-curly-spacing': ['error', 'always'], + 'vue/v-for-delimiter-style': ['error', 'in'], + 'vue/require-name-property': 'warn', + 'vue/prefer-true-attribute-shorthand': 'warn', + 'prefer-arrow-callback': 'warn', + }, + }, + prettier, + { + rules: { + 'prettier/prettier': 'warn', + }, + }, +]; diff --git a/napcat.webui/package.json b/napcat.webui/package.json index dbb6d91a..49ec18b9 100644 --- a/napcat.webui/package.json +++ b/napcat.webui/package.json @@ -4,18 +4,26 @@ "version": "0.0.0", "type": "module", "scripts": { - "dev": "vite", + "lint": "eslint . --fix", + "dev": "vite --host 127.0.0.1", "build": "vue-tsc -b && vite build", "preview": "vite preview" }, "dependencies": { + "eslint-plugin-prettier": "^5.2.1", "qrcode": "^1.5.4", "tdesign-vue-next": "^1.10.3", "vue": "^3.5.12", "vue-router": "^4.4.5" }, "devDependencies": { + "@eslint/eslintrc": "^3.1.0", + "@eslint/js": "^9.14.0", + "@types/qrcode": "^1.5.5", "@vitejs/plugin-vue": "^5.1.4", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-vue": "^9.31.0", + "globals": "^15.12.0", "typescript": "~5.6.2", "vite": "^5.4.10", "vue-tsc": "^2.1.8" diff --git a/napcat.webui/src/App.vue b/napcat.webui/src/App.vue index 17b2da68..e5fe963f 100644 --- a/napcat.webui/src/App.vue +++ b/napcat.webui/src/App.vue @@ -1,11 +1,7 @@ - \ No newline at end of file + diff --git a/napcat.webui/src/backend/shell.ts b/napcat.webui/src/backend/shell.ts index 878ed7e1..b227e07e 100644 --- a/napcat.webui/src/backend/shell.ts +++ b/napcat.webui/src/backend/shell.ts @@ -1,14 +1,17 @@ export class QQLoginManager { private retCredential: string; - private apiprefix: string; + private readonly apiPrefix: string; + // TODO: //调试时http://127.0.0.1:6099/api 打包时 ../api - constructor(retCredential: string, apiprefix: string = 'http://127.0.0.1:6099/api') { + constructor(retCredential: string, apiPrefix: string = 'http://127.0.0.1:6099/api') { this.retCredential = retCredential; - this.apiprefix = apiprefix; + this.apiPrefix = apiPrefix; } + + // TODO: public async GetOB11Config(): Promise { try { - const ConfigResponse = await fetch(`${this.apiprefix}/OB11Config/GetConfig`, { + const ConfigResponse = await fetch(`${this.apiPrefix}/OB11Config/GetConfig`, { method: 'POST', headers: { Authorization: 'Bearer ' + this.retCredential, @@ -22,14 +25,14 @@ export class QQLoginManager { } } } catch (error) { - console.error("Error getting OB11 config:", error); + console.error('Error getting OB11 config:', error); } return {}; } public async SetOB11Config(config: any): Promise { try { - const ConfigResponse = await fetch(`${this.apiprefix}/OB11Config/SetConfig`, { + const ConfigResponse = await fetch(`${this.apiPrefix}/OB11Config/SetConfig`, { method: 'POST', headers: { Authorization: 'Bearer ' + this.retCredential, @@ -44,137 +47,137 @@ export class QQLoginManager { } } } catch (error) { - console.error("Error setting OB11 config:", error); + console.error('Error setting OB11 config:', error); } return false; } public async checkQQLoginStatus(): Promise { try { - let QQLoginResponse = await fetch(`${this.apiprefix}/QQLogin/CheckLoginStatus`, { + const QQLoginResponse = await fetch(`${this.apiPrefix}/QQLogin/CheckLoginStatus`, { method: 'POST', headers: { - 'Authorization': "Bearer " + this.retCredential, - 'Content-Type': 'application/json' - } + Authorization: 'Bearer ' + this.retCredential, + 'Content-Type': 'application/json', + }, }); if (QQLoginResponse.status == 200) { - let QQLoginResponseJson = await QQLoginResponse.json(); + const QQLoginResponseJson = await QQLoginResponse.json(); if (QQLoginResponseJson.code == 0) { return QQLoginResponseJson.data.isLogin; } } } catch (error) { - console.error("Error checking QQ login status:", error); + console.error('Error checking QQ login status:', error); } return false; } public async checkWebUiLogined(): Promise { try { - let LoginResponse = await fetch(`${this.apiprefix}/auth/check`, { + const LoginResponse = await fetch(`${this.apiPrefix}/auth/check`, { method: 'POST', headers: { - 'Authorization': "Bearer " + this.retCredential, - 'Content-Type': 'application/json' - } + Authorization: 'Bearer ' + this.retCredential, + 'Content-Type': 'application/json', + }, }); if (LoginResponse.status == 200) { - let LoginResponseJson = await LoginResponse.json(); + const LoginResponseJson = await LoginResponse.json(); if (LoginResponseJson.code == 0) { return true; } } } catch (error) { - console.error("Error checking web UI login status:", error); + console.error('Error checking web UI login status:', error); } return false; } public async loginWithToken(token: string): Promise { try { - let loginResponse = await fetch(`${this.apiprefix}/auth/login`, { + const loginResponse = await fetch(`${this.apiPrefix}/auth/login`, { method: 'POST', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', }, - body: JSON.stringify({ token: token }) + body: JSON.stringify({ token: token }), }); const loginResponseJson = await loginResponse.json(); - let retCode = loginResponseJson.code; + const retCode = loginResponseJson.code; if (retCode === 0) { this.retCredential = loginResponseJson.data.Credential; return this.retCredential; } } catch (error) { - console.error("Error logging in with token:", error); + console.error('Error logging in with token:', error); } return null; } public async getQQLoginQrcode(): Promise { try { - let QQLoginResponse = await fetch(`${this.apiprefix}/QQLogin/GetQQLoginQrcode`, { + const QQLoginResponse = await fetch(`${this.apiPrefix}/QQLogin/GetQQLoginQrcode`, { method: 'POST', headers: { - 'Authorization': "Bearer " + this.retCredential, - 'Content-Type': 'application/json' - } + Authorization: 'Bearer ' + this.retCredential, + 'Content-Type': 'application/json', + }, }); if (QQLoginResponse.status == 200) { - let QQLoginResponseJson = await QQLoginResponse.json(); + const QQLoginResponseJson = await QQLoginResponse.json(); if (QQLoginResponseJson.code == 0) { - return QQLoginResponseJson.data.qrcode || ""; + return QQLoginResponseJson.data.qrcode || ''; } } } catch (error) { - console.error("Error getting QQ login QR code:", error); + console.error('Error getting QQ login QR code:', error); } - return ""; + return ''; } public async getQQQuickLoginList(): Promise { try { - let QQLoginResponse = await fetch(`${this.apiprefix}/QQLogin/GetQuickLoginList`, { + const QQLoginResponse = await fetch(`${this.apiPrefix}/QQLogin/GetQuickLoginList`, { method: 'POST', headers: { - 'Authorization': "Bearer " + this.retCredential, - 'Content-Type': 'application/json' - } + Authorization: 'Bearer ' + this.retCredential, + 'Content-Type': 'application/json', + }, }); if (QQLoginResponse.status == 200) { - let QQLoginResponseJson = await QQLoginResponse.json(); + const QQLoginResponseJson = await QQLoginResponse.json(); if (QQLoginResponseJson.code == 0) { return QQLoginResponseJson.data || []; } } } catch (error) { - console.error("Error getting QQ quick login list:", error); + console.error('Error getting QQ quick login list:', error); } return []; } - public async setQuickLogin(uin: string): Promise<{ result: boolean, errMsg: string }> { + public async setQuickLogin(uin: string): Promise<{ result: boolean; errMsg: string }> { try { - let QQLoginResponse = await fetch(`${this.apiprefix}/QQLogin/SetQuickLogin`, { + const QQLoginResponse = await fetch(`${this.apiPrefix}/QQLogin/SetQuickLogin`, { method: 'POST', headers: { - 'Authorization': "Bearer " + this.retCredential, - 'Content-Type': 'application/json' + Authorization: 'Bearer ' + this.retCredential, + 'Content-Type': 'application/json', }, - body: JSON.stringify({ uin: uin }) + body: JSON.stringify({ uin: uin }), }); if (QQLoginResponse.status == 200) { - let QQLoginResponseJson = await QQLoginResponse.json(); + const QQLoginResponseJson = await QQLoginResponse.json(); if (QQLoginResponseJson.code == 0) { - return { result: true, errMsg: "" }; + return { result: true, errMsg: '' }; } else { return { result: false, errMsg: QQLoginResponseJson.message }; } } } catch (error) { - console.error("Error setting quick login:", error); + console.error('Error setting quick login:', error); } - return { result: false, errMsg: "接口异常" }; + return { result: false, errMsg: '接口异常' }; } -} \ No newline at end of file +} diff --git a/napcat.webui/src/components/Dashboard.vue b/napcat.webui/src/components/Dashboard.vue index a2afa213..d3eb2ec6 100644 --- a/napcat.webui/src/components/Dashboard.vue +++ b/napcat.webui/src/components/Dashboard.vue @@ -1,56 +1,55 @@ - \ No newline at end of file + diff --git a/napcat.webui/src/components/QQLogin.vue b/napcat.webui/src/components/QQLogin.vue index 3ec8da12..13d4b674 100644 --- a/napcat.webui/src/components/QQLogin.vue +++ b/napcat.webui/src/components/QQLogin.vue @@ -2,67 +2,91 @@ - \ No newline at end of file + diff --git a/napcat.webui/src/pages/network/HttpClientComponent.vue b/napcat.webui/src/pages/network/HttpClientComponent.vue index 45f02d8f..ce55b9f9 100644 --- a/napcat.webui/src/pages/network/HttpClientComponent.vue +++ b/napcat.webui/src/pages/network/HttpClientComponent.vue @@ -1,29 +1,42 @@ - \ No newline at end of file + diff --git a/napcat.webui/src/pages/network/HttpServerComponent.vue b/napcat.webui/src/pages/network/HttpServerComponent.vue index a43286b0..1474135a 100644 --- a/napcat.webui/src/pages/network/HttpServerComponent.vue +++ b/napcat.webui/src/pages/network/HttpServerComponent.vue @@ -1,38 +1,57 @@ - \ No newline at end of file + diff --git a/napcat.webui/src/pages/network/WebsocketClientComponent.vue b/napcat.webui/src/pages/network/WebsocketClientComponent.vue index 52312230..07b46018 100644 --- a/napcat.webui/src/pages/network/WebsocketClientComponent.vue +++ b/napcat.webui/src/pages/network/WebsocketClientComponent.vue @@ -1,32 +1,47 @@ - \ No newline at end of file + diff --git a/napcat.webui/src/pages/network/WebsocketServerComponent.vue b/napcat.webui/src/pages/network/WebsocketServerComponent.vue index c6d6d1f3..57e762b9 100644 --- a/napcat.webui/src/pages/network/WebsocketServerComponent.vue +++ b/napcat.webui/src/pages/network/WebsocketServerComponent.vue @@ -1,38 +1,57 @@ - \ No newline at end of file + diff --git a/napcat.webui/src/router/index.ts b/napcat.webui/src/router/index.ts index b615fb7b..50f67c11 100644 --- a/napcat.webui/src/router/index.ts +++ b/napcat.webui/src/router/index.ts @@ -1,4 +1,4 @@ -import { createRouter, createWebHashHistory } from 'vue-router' +import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'; import Dashboard from '../components/Dashboard.vue'; import BasicInfo from '../pages/BasicInfo.vue'; import AboutUs from '../pages/AboutUs.vue'; @@ -8,25 +8,25 @@ import QQLogin from '../components/QQLogin.vue'; import WebUiLogin from '../components/WebUiLogin.vue'; import OtherConfig from '../pages/OtherConfig.vue'; -const routes = [ - { path: '/', redirect: '/webui' }, - { path: '/webui', component: WebUiLogin, name: 'WebUiLogin' }, - { path: '/qqlogin', component: QQLogin, name: 'QQLogin' }, - { - path: '/dashboard', - component: Dashboard, - children: [ - { path: '', redirect: 'basic-info' }, - { path: 'basic-info', component: BasicInfo, name: 'BasicInfo' }, - { path: 'network-config', component: NetWork, name: 'NetWork' }, - { path: 'log-view', component: LogView, name: 'LogView' }, - { path: 'other-config', component: OtherConfig, name: 'OtherConfig' }, - { path: 'about-us', component: AboutUs, name: 'AboutUs' } - ] - } -] +const routes: Array = [ + { path: '/', redirect: '/webui' }, + { path: '/webui', component: WebUiLogin, name: 'WebUiLogin' }, + { path: '/qqlogin', component: QQLogin, name: 'QQLogin' }, + { + path: '/dashboard', + component: Dashboard, + children: [ + { path: '', redirect: 'basic-info' }, + { path: 'basic-info', component: BasicInfo, name: 'BasicInfo' }, + { path: 'network-config', component: NetWork, name: 'NetWork' }, + { path: 'log-view', component: LogView, name: 'LogView' }, + { path: 'other-config', component: OtherConfig, name: 'OtherConfig' }, + { path: 'about-us', component: AboutUs, name: 'AboutUs' }, + ], + }, +]; export const router = createRouter({ - history: createWebHashHistory(), - routes, -}) \ No newline at end of file + history: createWebHashHistory(), + routes, +}); diff --git a/napcat.webui/src/shims-vue.d.ts b/napcat.webui/src/shims-vue.d.ts deleted file mode 100644 index ab70f827..00000000 --- a/napcat.webui/src/shims-vue.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -declare module '*.vue' { - import { DefineComponent } from 'vue'; - const component: DefineComponent<{}, {}, any>; - export default component; -} \ No newline at end of file diff --git a/napcat.webui/tsconfig.app.json b/napcat.webui/tsconfig.app.json deleted file mode 100644 index cb88a5a6..00000000 --- a/napcat.webui/tsconfig.app.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "compilerOptions": { - "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo", - "target": "ES2020", - "useDefineForClassFields": true, - "module": "ESNext", - "lib": ["ES2020", "DOM", "DOM.Iterable"], - "skipLibCheck": true, - - /* Bundler mode */ - "moduleResolution": "Bundler", - "allowImportingTsExtensions": true, - "isolatedModules": true, - "moduleDetection": "force", - "noEmit": true, - "jsx": "preserve", - - /* Linting */ - "strict": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, - "noUncheckedSideEffectImports": true - }, - "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"] -} diff --git a/napcat.webui/tsconfig.json b/napcat.webui/tsconfig.json index 1ffef600..bf12aee2 100644 --- a/napcat.webui/tsconfig.json +++ b/napcat.webui/tsconfig.json @@ -1,7 +1,34 @@ { - "files": [], - "references": [ - { "path": "./tsconfig.app.json" }, - { "path": "./tsconfig.node.json" } - ] + "compilerOptions": { + "target": "ESNext", + "jsx": "preserve", + "jsxImportSource": "vue", + "lib": [ + "DOM", + "DOM.Iterable" + ], + "baseUrl": ".", + "module": "esnext", + "moduleResolution": "bundler", + "paths": { + "@/*": [ + "src/*" + ] + }, + "resolveJsonModule": true, + "types": [ + "vite/client" + ], + "strict": true, + "strictNullChecks": true, + "noUnusedLocals": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "isolatedModules": true, + "experimentalDecorators": true, + "useDefineForClassFields": true + }, + "include": ["src"], + "exclude": ["node_modules"], + "references": [{"path": "./tsconfig.node.json"}] } diff --git a/napcat.webui/tsconfig.node.json b/napcat.webui/tsconfig.node.json index abcd7f0d..f026910e 100644 --- a/napcat.webui/tsconfig.node.json +++ b/napcat.webui/tsconfig.node.json @@ -1,24 +1,11 @@ { - "compilerOptions": { - "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", - "target": "ES2022", - "lib": ["ES2023"], - "module": "ESNext", - "skipLibCheck": true, - - /* Bundler mode */ - "moduleResolution": "Bundler", - "allowImportingTsExtensions": true, - "isolatedModules": true, - "moduleDetection": "force", - "noEmit": true, - - /* Linting */ - "strict": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, - "noUncheckedSideEffectImports": true - }, - "include": ["vite.config.ts"] + "compilerOptions": { + "composite": true, + "skipLibCheck": true, + "module": "ESNext", + "moduleResolution": "bundler", + "allowSyntheticDefaultImports": true, + "strictNullChecks": true + }, + "include": ["vite.config.ts"] } diff --git a/napcat.webui/vite.config.ts b/napcat.webui/vite.config.ts index 64327ab8..22d3b08e 100644 --- a/napcat.webui/vite.config.ts +++ b/napcat.webui/vite.config.ts @@ -1,8 +1,8 @@ -import { defineConfig } from 'vite' -import vue from '@vitejs/plugin-vue' +import { defineConfig } from 'vite'; +import vue from '@vitejs/plugin-vue'; // https://vite.dev/config/ export default defineConfig({ - plugins: [vue()], - base: './' -}) + plugins: [vue()], + base: './', +}); diff --git a/package.json b/package.json index 30999567..3977ddca 100644 --- a/package.json +++ b/package.json @@ -48,9 +48,9 @@ }, "dependencies": { "express": "^5.0.0", - "silk-wasm": "^3.6.1", - "ws": "^8.18.0", + "fluent-ffmpeg": "^2.1.2", "qrcode-terminal": "^0.12.0", - "fluent-ffmpeg": "^2.1.2" + "silk-wasm": "^3.6.1", + "ws": "^8.18.0" } -} \ No newline at end of file +} diff --git a/src/core/apis/file.ts b/src/core/apis/file.ts index 17fc0036..5954b657 100644 --- a/src/core/apis/file.ts +++ b/src/core/apis/file.ts @@ -300,18 +300,18 @@ export class NTQQFileApi { element.elementType === ElementType.FILE ) { switch (element.elementType) { - case ElementType.PIC: + case ElementType.PIC: element.picElement!.sourcePath = elementResults[elementIndex]; - break; - case ElementType.VIDEO: + break; + case ElementType.VIDEO: element.videoElement!.filePath = elementResults[elementIndex]; - break; - case ElementType.PTT: + break; + case ElementType.PTT: element.pttElement!.filePath = elementResults[elementIndex]; - break; - case ElementType.FILE: + break; + case ElementType.FILE: element.fileElement!.filePath = elementResults[elementIndex]; - break; + break; } elementIndex++; } diff --git a/src/onebot/action/go-cqhttp/GetFriendMsgHistory.ts b/src/onebot/action/go-cqhttp/GetFriendMsgHistory.ts index 7efd553a..15cc53cb 100644 --- a/src/onebot/action/go-cqhttp/GetFriendMsgHistory.ts +++ b/src/onebot/action/go-cqhttp/GetFriendMsgHistory.ts @@ -45,7 +45,7 @@ export default class GetFriendMsgHistory extends BaseAction { await Promise.all(msgList.map(async msg => { msg.id = MessageUnique.createUniqueMsgId({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId); })); - let network = Object.values(this.obContext.configLoader.configData.network) as Array; + const network = Object.values(this.obContext.configLoader.configData.network) as Array; //烘焙消息 const ob11MsgList = (await Promise.all( msgList.map(msg => this.obContext.apis.MsgApi.parseMessage(msg, network.flat().find(e => e.name === adapter)?.messagePostFormat ?? 'array'))) diff --git a/src/onebot/action/go-cqhttp/GetGroupMsgHistory.ts b/src/onebot/action/go-cqhttp/GetGroupMsgHistory.ts index 2f1fbd2c..63047433 100644 --- a/src/onebot/action/go-cqhttp/GetGroupMsgHistory.ts +++ b/src/onebot/action/go-cqhttp/GetGroupMsgHistory.ts @@ -43,9 +43,9 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction { msg.id = MessageUnique.createUniqueMsgId({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId); })); - let network = Object.values(this.obContext.configLoader.configData.network) as Array; + const network = Object.values(this.obContext.configLoader.configData.network) as Array; //烘焙消息 - let msgFormat = network.flat().find(e => e.name === adapter)?.messagePostFormat ?? 'array'; + const msgFormat = network.flat().find(e => e.name === adapter)?.messagePostFormat ?? 'array'; const ob11MsgList = (await Promise.all( msgList.map(msg => this.obContext.apis.MsgApi.parseMessage(msg, msgFormat))) ).filter(msg => msg !== undefined); diff --git a/src/onebot/action/group/GetGroupEssence.ts b/src/onebot/action/group/GetGroupEssence.ts index 602c8325..374874b8 100644 --- a/src/onebot/action/group/GetGroupEssence.ts +++ b/src/onebot/action/group/GetGroupEssence.ts @@ -31,8 +31,8 @@ export class GetGroupEssence extends BaseAction { } async _handle(payload: Payload, adapter: string) { - let network = Object.values(this.obContext.configLoader.configData.network) as Array; - let msgFormat = network.flat().find(e => e.name === adapter)?.messagePostFormat ?? 'array'; + const network = Object.values(this.obContext.configLoader.configData.network) as Array; + const msgFormat = network.flat().find(e => e.name === adapter)?.messagePostFormat ?? 'array'; const msglist = (await this.core.apis.WebApi.getGroupEssenceMsgAll(payload.group_id.toString())).flatMap((e) => e.data.msg_list); if (!msglist) { throw new Error('获取失败'); diff --git a/src/onebot/action/msg/GetMsg.ts b/src/onebot/action/msg/GetMsg.ts index c32f9c5f..58f61eea 100644 --- a/src/onebot/action/msg/GetMsg.ts +++ b/src/onebot/action/msg/GetMsg.ts @@ -24,8 +24,8 @@ class GetMsg extends BaseAction { async _handle(payload: Payload, adapter: string) { // log("history msg ids", Object.keys(msgHistory)); - let network = Object.values(this.obContext.configLoader.configData.network) as Array; - let msgFormat = network.flat().find(e => e.name === adapter)?.messagePostFormat ?? 'array'; + const network = Object.values(this.obContext.configLoader.configData.network) as Array; + const msgFormat = network.flat().find(e => e.name === adapter)?.messagePostFormat ?? 'array'; if (!payload.message_id) { throw Error('参数message_id不能为空'); } diff --git a/src/onebot/action/user/GetRecentContact.ts b/src/onebot/action/user/GetRecentContact.ts index 706a97ec..8ce2c58d 100644 --- a/src/onebot/action/user/GetRecentContact.ts +++ b/src/onebot/action/user/GetRecentContact.ts @@ -17,9 +17,9 @@ export default class GetRecentContact extends BaseAction { async _handle(payload: Payload, adapter: string) { const ret = await this.core.apis.UserApi.getRecentContactListSnapShot(+(payload.count || 10)); - let network = Object.values(this.obContext.configLoader.configData.network) as Array; + const network = Object.values(this.obContext.configLoader.configData.network) as Array; //烘焙消息 - let msgFormat = network.flat().find(e => e.name === adapter)?.messagePostFormat ?? 'array'; + const msgFormat = network.flat().find(e => e.name === adapter)?.messagePostFormat ?? 'array'; return await Promise.all(ret.info.changedList.map(async (t) => { const FastMsg = await this.core.apis.MsgApi.getMsgsByMsgId({ chatType: t.chatType, peerUid: t.peerUid }, [t.msgId]); if (FastMsg.msgList.length > 0) { diff --git a/src/onebot/config/config.ts b/src/onebot/config/config.ts index 66dae188..be5b4220 100644 --- a/src/onebot/config/config.ts +++ b/src/onebot/config/config.ts @@ -85,7 +85,7 @@ export const defaultOnebotConfig = createDefaultConfig({ }, musicSignUrl: "", enableLocalFile2Url: false -}) +}); export const mergeNetworkDefaultConfig = { httpServers: httpServerDefaultConfigs, httpClients: httpClientDefaultConfigs, diff --git a/src/onebot/index.ts b/src/onebot/index.ts index 7d5d75a8..aeaafdaf 100644 --- a/src/onebot/index.ts +++ b/src/onebot/index.ts @@ -100,7 +100,7 @@ export class NapCatOneBot11Adapter { this.context.logger.setLogSelfInfo(selfInfo); }).catch(this.context.logger.logError.bind(this.context.logger)); - let serviceInfo = await this.creatOneBotLog(ob11Config); + const serviceInfo = await this.creatOneBotLog(ob11Config); this.context.logger.log(`[Notice] [OneBot11] ${serviceInfo}`); // //创建NetWork服务 @@ -497,14 +497,14 @@ export class NapCatOneBot11Adapter { } private async emitMsg(message: RawMessage) { - let network = Object.values(this.configLoader.configData.network) as Array; + const network = Object.values(this.configLoader.configData.network) as Array; this.context.logger.logDebug('收到新消息 RawMessage', message); this.apis.MsgApi.parseMessageV2(message).then((ob11Msg) => { if (!ob11Msg) return; const isSelfMsg = ob11Msg.stringMsg.user_id.toString() == this.core.selfInfo.uin || ob11Msg.arrayMsg.user_id.toString() == this.core.selfInfo.uin; this.context.logger.logDebug('转化为 OB11Message', ob11Msg); - let msgMap: Map = new Map(); - let enable_client: string[] = []; + const msgMap: Map = new Map(); + const enable_client: string[] = []; network.flat().filter(e => e.enable).map(e => { enable_client.push(e.name); if (e.messagePostFormat == 'string') { @@ -518,7 +518,7 @@ export class NapCatOneBot11Adapter { } }); - let debug_network = network.flat().filter(e => e.enable && e.debug); + const debug_network = network.flat().filter(e => e.enable && e.debug); if (debug_network.length > 0) { for (const adapter of debug_network) { if (adapter.name) { @@ -534,7 +534,7 @@ export class NapCatOneBot11Adapter { return; } - let notreportSelf_network = network.flat().filter(e => e.enable && !e.reportSelfMessage); + const notreportSelf_network = network.flat().filter(e => e.enable && !e.reportSelfMessage); if (isSelfMsg) { for (const adapter of notreportSelf_network) { msgMap.delete(adapter.name); diff --git a/src/onebot/network/index.ts b/src/onebot/network/index.ts index 57c0b0eb..7373a9bb 100644 --- a/src/onebot/network/index.ts +++ b/src/onebot/network/index.ts @@ -38,7 +38,7 @@ export class OB11NetworkManager { return Promise.all(Array.from(map.entries()).map(([name, event]) => { const adapter = this.adapters.get(name); if (adapter) { - return adapter.onEvent(event); + return adapter.onEvent(event); } })); } diff --git a/src/webui/index.ts b/src/webui/index.ts index de9c83c1..68ac18b1 100644 --- a/src/webui/index.ts +++ b/src/webui/index.ts @@ -37,6 +37,7 @@ export async function InitWebUi(logger: LogWrapper, pathWrapper: NapCatPathWrapp app.use(config.prefix + '/webui', express.static(pathWrapper.staticPath)); //挂载API接口 // 添加CORS支持 + // TODO: app.use((req, res, next) => { res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'); @@ -47,22 +48,22 @@ export async function InitWebUi(logger: LogWrapper, pathWrapper: NapCatPathWrapp app.listen(config.port, config.host, async () => { log(`[NapCat] [WebUi] Current WebUi is running at http://${config.host}:${config.port}${config.prefix}`); log(`[NapCat] [WebUi] Login Token is ${config.token}`); - log(`[NapCat] [WebUi] WebUi User Panel Url: http://${config.host}:${config.port}${config.prefix}/webui?token=${config.token}`); - log(`[NapCat] [WebUi] WebUi Local Panel Url: http://127.0.0.1:${config.port}${config.prefix}/webui?token=${config.token}`); + log( + `[NapCat] [WebUi] WebUi User Panel Url: http://${config.host}:${config.port}${config.prefix}/webui?token=${config.token}` + ); + log( + `[NapCat] [WebUi] WebUi Local Panel Url: http://127.0.0.1:${config.port}${config.prefix}/webui?token=${config.token}` + ); //获取上网Ip //https://www.ip.cn/api/index?ip&type=0 - RequestUtil.HttpGetJson<{ IP: {IP:string} }>( - 'https://ip.011102.xyz/', - 'GET', - {}, - {}, - true, - true - ).then((data) => { - log(`[NapCat] [WebUi] WebUi Publish Panel Url: http://${data.IP.IP}:${config.port}${config.prefix}/webui/?token=${config.token}`); - }).catch((err) => { - logger.logError.bind(logger)(`[NapCat] [WebUi] Get Publish Panel Url Error: ${err}`); - }); - + RequestUtil.HttpGetJson<{ IP: { IP: string } }>('https://ip.011102.xyz/', 'GET', {}, {}, true, true) + .then((data) => { + log( + `[NapCat] [WebUi] WebUi Publish Panel Url: http://${data.IP.IP}:${config.port}${config.prefix}/webui/?token=${config.token}` + ); + }) + .catch((err) => { + logger.logError.bind(logger)(`[NapCat] [WebUi] Get Publish Panel Url Error: ${err}`); + }); }); }