mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-12-18 20:30:08 +08:00
feat: 所有的类型检查
This commit is contained in:
parent
19888d52dc
commit
df824d77ae
@ -9,7 +9,7 @@
|
|||||||
"build:framework": "pnpm --filter napcat-framework run build || exit 1",
|
"build:framework": "pnpm --filter napcat-framework run build || exit 1",
|
||||||
"build:webui": "pnpm --filter napcat-webui-frontend run build || exit 1",
|
"build:webui": "pnpm --filter napcat-webui-frontend run build || exit 1",
|
||||||
"dev:shell": "pnpm --filter napcat-develop run dev || exit 1",
|
"dev:shell": "pnpm --filter napcat-develop run dev || exit 1",
|
||||||
"typecheck": "pnpm -w -r --filter napcat-shell --filter napcat-framework run typecheck"
|
"typecheck": "pnpm -w -r --filter napcat-shell --filter napcat-framework --filter napcat-webui-backend --filter napcat-onebot --filter napcat-core --filter napcat-webui-frontend run typecheck"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-node-resolve": "^16.0.3",
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
||||||
|
|||||||
@ -4,6 +4,9 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "src/index.ts",
|
"main": "src/index.ts",
|
||||||
|
"scripts": {
|
||||||
|
"typecheck": "tsc --noEmit --skipLibCheck -p tsconfig.json"
|
||||||
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"import": "./src/index.ts"
|
"import": "./src/index.ts"
|
||||||
|
|||||||
@ -2,9 +2,9 @@ import fsPromise from 'fs/promises';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
import { EncodeResult, getDuration, getWavFileInfo, isSilk, isWav } from 'silk-wasm';
|
import { EncodeResult, getDuration, getWavFileInfo, isSilk, isWav } from 'silk-wasm';
|
||||||
import { LogWrapper } from '@/napcat-common/log';
|
import { LogWrapper } from '@/napcat-common/src/log';
|
||||||
import { EncodeArgs } from '@/napcat-common/audio-worker';
|
import { EncodeArgs } from '@/napcat-common/src/audio-worker';
|
||||||
import { FFmpegService } from '@/napcat-common/ffmpeg';
|
import { FFmpegService } from '@/napcat-common/src/ffmpeg';
|
||||||
import { runTask } from './worker';
|
import { runTask } from './worker';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import fs from 'fs';
|
|||||||
import { stat } from 'fs/promises';
|
import { stat } from 'fs/promises';
|
||||||
import crypto, { randomUUID } from 'crypto';
|
import crypto, { randomUUID } from 'crypto';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { solveProblem } from '@/napcat-common/helper';
|
import { solveProblem } from '@/napcat-common/src/helper';
|
||||||
|
|
||||||
export interface HttpDownloadOptions {
|
export interface HttpDownloadOptions {
|
||||||
url: string;
|
url: string;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { LogWrapper } from '@/napcat-common/log';
|
import { LogWrapper } from '@/napcat-common/src/log';
|
||||||
|
|
||||||
export function proxyHandlerOf (logger: LogWrapper) {
|
export function proxyHandlerOf (logger: LogWrapper) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import { systemPlatform } from '@/napcat-common/system';
|
import { systemPlatform } from '@/napcat-common/src/system';
|
||||||
import { getDefaultQQVersionConfigInfo, getQQPackageInfoPath, getQQVersionConfigPath, parseAppidFromMajor } from './helper';
|
import { getDefaultQQVersionConfigInfo, getQQPackageInfoPath, getQQVersionConfigPath, parseAppidFromMajor } from './helper';
|
||||||
import AppidTable from 'napcat-core/external/appid.json';
|
import AppidTable from 'napcat-core/external/appid.json';
|
||||||
import { LogWrapper } from '@/napcat-common/log';
|
import { LogWrapper } from '@/napcat-common/src/log';
|
||||||
import { getMajorPath } from 'napcat-core';
|
import { getMajorPath } from 'napcat-core';
|
||||||
import { QQAppidTableType, QQPackageInfoType, QQVersionConfigType } from './types';
|
import { QQAppidTableType, QQPackageInfoType, QQVersionConfigType } from './types';
|
||||||
|
|
||||||
|
|||||||
@ -36,8 +36,8 @@
|
|||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/napcat-common/*": [
|
"@/*": [
|
||||||
"src/*"
|
"../*"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { FriendRequest, FriendV2 } from 'napcat-core/types';
|
import { FriendRequest, FriendV2 } from '@/napcat-core/types';
|
||||||
import { BuddyListReqType, InstanceContext, NapCatCore } from 'napcat-core/index';
|
import { BuddyListReqType, InstanceContext, NapCatCore } from '@/napcat-core/index';
|
||||||
import { LimitedHashTable } from 'napcat-common/src/message-unique';
|
import { LimitedHashTable } from 'napcat-common/src/message-unique';
|
||||||
|
|
||||||
export class NTQQFriendApi {
|
export class NTQQFriendApi {
|
||||||
|
|||||||
272
packages/napcat-core/helper/event.ts
Normal file
272
packages/napcat-core/helper/event.ts
Normal file
@ -0,0 +1,272 @@
|
|||||||
|
import { NodeIQQNTWrapperSession } from '@/napcat-core/wrapper';
|
||||||
|
import { randomUUID } from 'crypto';
|
||||||
|
import { ListenerNamingMapping, ServiceNamingMapping } from '@/napcat-core/index';
|
||||||
|
|
||||||
|
interface InternalMapKey {
|
||||||
|
timeout: number;
|
||||||
|
createtime: number;
|
||||||
|
func: (...arg: any[]) => any;
|
||||||
|
checker: ((...args: any[]) => boolean) | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
type EnsureFunc<T> = T extends (...args: any) => any ? T : never;
|
||||||
|
|
||||||
|
type FuncKeys<T> = Extract<
|
||||||
|
{
|
||||||
|
[K in keyof T]: EnsureFunc<T[K]> extends never ? never : K;
|
||||||
|
}[keyof T],
|
||||||
|
string
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type ListenerClassBase = Record<string, string>;
|
||||||
|
|
||||||
|
export class NTEventWrapper {
|
||||||
|
private readonly WrapperSession: NodeIQQNTWrapperSession | undefined; // WrapperSession
|
||||||
|
private readonly listenerManager: Map<string, ListenerClassBase> = new Map<string, ListenerClassBase>(); // ListenerName-Unique -> Listener实例
|
||||||
|
private readonly EventTask = new Map<string, Map<string, Map<string, InternalMapKey>>>(); // tasks ListenerMainName -> ListenerSubName-> uuid -> {timeout,createtime,func}
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
wrapperSession: NodeIQQNTWrapperSession
|
||||||
|
) {
|
||||||
|
this.WrapperSession = wrapperSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
createProxyDispatch(ListenerMainName: string) {
|
||||||
|
const dispatcherListenerFunc = this.dispatcherListener.bind(this);
|
||||||
|
return new Proxy(
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
get(target: any, prop: any, receiver: any) {
|
||||||
|
if (typeof target[prop] === 'undefined') {
|
||||||
|
// 如果方法不存在,返回一个函数,这个函数调用existentMethod
|
||||||
|
return (...args: any[]) => {
|
||||||
|
dispatcherListenerFunc(ListenerMainName, prop, ...args).then();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// 如果方法存在,正常返回
|
||||||
|
return Reflect.get(target, prop, receiver);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
createEventFunction<
|
||||||
|
Service extends keyof ServiceNamingMapping,
|
||||||
|
ServiceMethod extends FuncKeys<ServiceNamingMapping[Service]>,
|
||||||
|
T extends (...args: any) => any = EnsureFunc<ServiceNamingMapping[Service][ServiceMethod]>
|
||||||
|
>(eventName: `${Service}/${ServiceMethod}`): T | undefined {
|
||||||
|
const eventNameArr = eventName.split('/');
|
||||||
|
type eventType = {
|
||||||
|
[key: string]: () => { [key: string]: (...params: Parameters<T>) => Promise<ReturnType<T>>; };
|
||||||
|
};
|
||||||
|
if (eventNameArr.length > 1) {
|
||||||
|
const serviceName = 'get' + (eventNameArr[0]?.replace('NodeIKernel', '') ?? '');
|
||||||
|
const eventName = eventNameArr[1];
|
||||||
|
const services = (this.WrapperSession as unknown as eventType)[serviceName]?.();
|
||||||
|
if (!services || !eventName) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
let event = services[eventName];
|
||||||
|
|
||||||
|
// 重新绑定this
|
||||||
|
event = event?.bind(services);
|
||||||
|
if (event) {
|
||||||
|
return event as T;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
createListenerFunction<T> (listenerMainName: string, uniqueCode: string = ''): T {
|
||||||
|
const existListener = this.listenerManager.get(listenerMainName + uniqueCode);
|
||||||
|
if (!existListener) {
|
||||||
|
const Listener = this.createProxyDispatch(listenerMainName);
|
||||||
|
const ServiceSubName = /^NodeIKernel(.*?)Listener$/.exec(listenerMainName)![1];
|
||||||
|
const Service = `NodeIKernel${ServiceSubName}Service/addKernel${ServiceSubName}Listener`;
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
this.createEventFunction(Service)(Listener as T);
|
||||||
|
this.listenerManager.set(listenerMainName + uniqueCode, Listener);
|
||||||
|
return Listener as T;
|
||||||
|
}
|
||||||
|
return existListener as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 统一回调清理事件
|
||||||
|
async dispatcherListener(ListenerMainName: string, ListenerSubName: string, ...args: any[]) {
|
||||||
|
this.EventTask.get(ListenerMainName)
|
||||||
|
?.get(ListenerSubName)
|
||||||
|
?.forEach((task, uuid) => {
|
||||||
|
if (task.createtime + task.timeout < Date.now()) {
|
||||||
|
this.EventTask.get(ListenerMainName)?.get(ListenerSubName)?.delete(uuid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (task?.checker?.(...args)) {
|
||||||
|
task.func(...args);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async callNoListenerEvent<
|
||||||
|
Service extends keyof ServiceNamingMapping,
|
||||||
|
ServiceMethod extends FuncKeys<ServiceNamingMapping[Service]>,
|
||||||
|
EventType extends (...args: any) => any = EnsureFunc<ServiceNamingMapping[Service][ServiceMethod]>
|
||||||
|
>(
|
||||||
|
serviceAndMethod: `${Service}/${ServiceMethod}`,
|
||||||
|
...args: Parameters<EventType>
|
||||||
|
): Promise<Awaited<ReturnType<EventType>>> {
|
||||||
|
return (this.createEventFunction(serviceAndMethod))!(...args);
|
||||||
|
}
|
||||||
|
|
||||||
|
async registerListen<
|
||||||
|
Listener extends keyof ListenerNamingMapping,
|
||||||
|
ListenerMethod extends FuncKeys<ListenerNamingMapping[Listener]>,
|
||||||
|
ListenerType extends (...args: any) => any = EnsureFunc<ListenerNamingMapping[Listener][ListenerMethod]>
|
||||||
|
>(
|
||||||
|
listenerAndMethod: `${Listener}/${ListenerMethod}`,
|
||||||
|
checker: (...args: Parameters<ListenerType>) => boolean,
|
||||||
|
waitTimes = 1,
|
||||||
|
timeout = 5000
|
||||||
|
) {
|
||||||
|
return new Promise<Parameters<ListenerType>>((resolve, reject) => {
|
||||||
|
const ListenerNameList = listenerAndMethod.split('/');
|
||||||
|
const ListenerMainName = ListenerNameList[0] ?? '';
|
||||||
|
const ListenerSubName = ListenerNameList[1] ?? '';
|
||||||
|
const id = randomUUID();
|
||||||
|
let complete = 0;
|
||||||
|
let retData: Parameters<ListenerType> | undefined;
|
||||||
|
|
||||||
|
function sendDataCallback() {
|
||||||
|
if (complete === 0) {
|
||||||
|
reject(new Error(' ListenerName:' + listenerAndMethod + ' timeout'));
|
||||||
|
} else {
|
||||||
|
resolve(retData!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const timeoutRef = setTimeout(sendDataCallback, timeout);
|
||||||
|
const eventCallback = {
|
||||||
|
timeout,
|
||||||
|
createtime: Date.now(),
|
||||||
|
checker,
|
||||||
|
func: (...args: Parameters<ListenerType>) => {
|
||||||
|
complete++;
|
||||||
|
retData = args;
|
||||||
|
if (complete >= waitTimes) {
|
||||||
|
clearTimeout(timeoutRef);
|
||||||
|
sendDataCallback();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if (!this.EventTask.get(ListenerMainName)) {
|
||||||
|
this.EventTask.set(ListenerMainName, new Map());
|
||||||
|
}
|
||||||
|
if (!this.EventTask.get(ListenerMainName)?.get(ListenerSubName)) {
|
||||||
|
this.EventTask.get(ListenerMainName)?.set(ListenerSubName, new Map());
|
||||||
|
}
|
||||||
|
this.EventTask.get(ListenerMainName)?.get(ListenerSubName)?.set(id, eventCallback);
|
||||||
|
this.createListenerFunction(ListenerMainName);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async callNormalEventV2<
|
||||||
|
Service extends keyof ServiceNamingMapping,
|
||||||
|
ServiceMethod extends FuncKeys<ServiceNamingMapping[Service]>,
|
||||||
|
Listener extends keyof ListenerNamingMapping,
|
||||||
|
ListenerMethod extends FuncKeys<ListenerNamingMapping[Listener]>,
|
||||||
|
EventType extends (...args: any) => any = EnsureFunc<ServiceNamingMapping[Service][ServiceMethod]>,
|
||||||
|
ListenerType extends (...args: any) => any = EnsureFunc<ListenerNamingMapping[Listener][ListenerMethod]>
|
||||||
|
>(
|
||||||
|
serviceAndMethod: `${Service}/${ServiceMethod}`,
|
||||||
|
listenerAndMethod: `${Listener}/${ListenerMethod}`,
|
||||||
|
args: Parameters<EventType>,
|
||||||
|
checkerEvent: (ret: Awaited<ReturnType<EventType>>) => boolean = () => true,
|
||||||
|
checkerListener: (...args: Parameters<ListenerType>) => boolean = () => true,
|
||||||
|
callbackTimesToWait = 1,
|
||||||
|
timeout = 5000
|
||||||
|
) {
|
||||||
|
const id = randomUUID();
|
||||||
|
let complete = 0;
|
||||||
|
let retData: Parameters<ListenerType> | undefined;
|
||||||
|
let retEvent: any = {};
|
||||||
|
|
||||||
|
function sendDataCallback(resolve: any, reject: any) {
|
||||||
|
if (complete === 0) {
|
||||||
|
reject(
|
||||||
|
new Error(
|
||||||
|
'Timeout: NTEvent serviceAndMethod:' +
|
||||||
|
serviceAndMethod +
|
||||||
|
' ListenerName:' +
|
||||||
|
listenerAndMethod +
|
||||||
|
' EventRet:\n' +
|
||||||
|
JSON.stringify(retEvent, null, 4) +
|
||||||
|
'\n'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
resolve([retEvent as Awaited<ReturnType<EventType>>, ...retData!]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const ListenerNameList = listenerAndMethod.split('/');
|
||||||
|
const ListenerMainName = ListenerNameList[0] ?? '';
|
||||||
|
const ListenerSubName = ListenerNameList[1] ?? '';
|
||||||
|
|
||||||
|
return new Promise<[EventRet: Awaited<ReturnType<EventType>>, ...Parameters<ListenerType>]>(
|
||||||
|
(resolve, reject) => {
|
||||||
|
const timeoutRef = setTimeout(() => sendDataCallback(resolve, reject), timeout);
|
||||||
|
|
||||||
|
const eventCallback = {
|
||||||
|
timeout,
|
||||||
|
createtime: Date.now(),
|
||||||
|
checker: checkerListener,
|
||||||
|
func: (...args: any[]) => {
|
||||||
|
complete++;
|
||||||
|
retData = args as Parameters<ListenerType>;
|
||||||
|
if (complete >= callbackTimesToWait) {
|
||||||
|
clearTimeout(timeoutRef);
|
||||||
|
sendDataCallback(resolve, reject);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if (!this.EventTask.get(ListenerMainName)) {
|
||||||
|
this.EventTask.set(ListenerMainName, new Map());
|
||||||
|
}
|
||||||
|
if (!this.EventTask.get(ListenerMainName)?.get(ListenerSubName)) {
|
||||||
|
this.EventTask.get(ListenerMainName)?.set(ListenerSubName, new Map());
|
||||||
|
}
|
||||||
|
this.EventTask.get(ListenerMainName)?.get(ListenerSubName)?.set(id, eventCallback);
|
||||||
|
this.createListenerFunction(ListenerMainName);
|
||||||
|
|
||||||
|
const eventResult = this.createEventFunction(serviceAndMethod)!(...(args));
|
||||||
|
|
||||||
|
const eventRetHandle = (eventData: any) => {
|
||||||
|
retEvent = eventData;
|
||||||
|
if (!checkerEvent(retEvent) && timeoutRef.hasRef()) {
|
||||||
|
clearTimeout(timeoutRef);
|
||||||
|
reject(
|
||||||
|
new Error(
|
||||||
|
'EventChecker Failed: NTEvent serviceAndMethod:' +
|
||||||
|
serviceAndMethod +
|
||||||
|
' ListenerName:' +
|
||||||
|
listenerAndMethod +
|
||||||
|
' EventRet:\n' +
|
||||||
|
JSON.stringify(retEvent, null, 4) +
|
||||||
|
'\n'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (eventResult instanceof Promise) {
|
||||||
|
eventResult.then((eventResult: any) => {
|
||||||
|
eventRetHandle(eventResult);
|
||||||
|
})
|
||||||
|
.catch(reject);
|
||||||
|
} else {
|
||||||
|
eventRetHandle(eventResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
106
packages/napcat-core/helper/qq-basic-info.ts
Normal file
106
packages/napcat-core/helper/qq-basic-info.ts
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
import fs from 'node:fs';
|
||||||
|
import { systemPlatform } from 'napcat-common/src/system';
|
||||||
|
import { getDefaultQQVersionConfigInfo, getQQPackageInfoPath, getQQVersionConfigPath, parseAppidFromMajor } from 'napcat-common/src/helper';
|
||||||
|
import AppidTable from '@/napcat-core/external/appid.json';
|
||||||
|
import { LogWrapper } from 'napcat-common/src/log';
|
||||||
|
import { getMajorPath } from '@/napcat-core/index';
|
||||||
|
import { QQAppidTableType, QQPackageInfoType, QQVersionConfigType } from 'napcat-common/src/types';
|
||||||
|
|
||||||
|
export class QQBasicInfoWrapper {
|
||||||
|
QQMainPath: string | undefined;
|
||||||
|
QQPackageInfoPath: string | undefined;
|
||||||
|
QQVersionConfigPath: string | undefined;
|
||||||
|
isQuickUpdate: boolean | undefined;
|
||||||
|
QQVersionConfig: QQVersionConfigType | undefined;
|
||||||
|
QQPackageInfo: QQPackageInfoType | undefined;
|
||||||
|
QQVersionAppid: string | undefined;
|
||||||
|
QQVersionQua: string | undefined;
|
||||||
|
context: { logger: LogWrapper; };
|
||||||
|
|
||||||
|
constructor (context: { logger: LogWrapper; }) {
|
||||||
|
// 基础目录获取
|
||||||
|
this.context = context;
|
||||||
|
this.QQMainPath = process.execPath;
|
||||||
|
this.QQVersionConfigPath = getQQVersionConfigPath(this.QQMainPath);
|
||||||
|
|
||||||
|
// 基础信息获取 无快更则启用默认模板填充
|
||||||
|
this.isQuickUpdate = !!this.QQVersionConfigPath;
|
||||||
|
this.QQVersionConfig = this.isQuickUpdate
|
||||||
|
? JSON.parse(fs.readFileSync(this.QQVersionConfigPath!).toString())
|
||||||
|
: getDefaultQQVersionConfigInfo();
|
||||||
|
|
||||||
|
this.QQPackageInfoPath = getQQPackageInfoPath(this.QQMainPath, this.QQVersionConfig?.curVersion);
|
||||||
|
this.QQPackageInfo = JSON.parse(fs.readFileSync(this.QQPackageInfoPath).toString());
|
||||||
|
const { appid: IQQVersionAppid, qua: IQQVersionQua } = this.getAppidV2();
|
||||||
|
this.QQVersionAppid = IQQVersionAppid;
|
||||||
|
this.QQVersionQua = IQQVersionQua;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 基础函数
|
||||||
|
getQQBuildStr () {
|
||||||
|
return this.QQVersionConfig?.curVersion.split('-')[1] ?? this.QQPackageInfo?.buildVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
getFullQQVersion () {
|
||||||
|
const version = this.isQuickUpdate ? this.QQVersionConfig?.curVersion : this.QQPackageInfo?.version;
|
||||||
|
if (!version) throw new Error('QQ版本获取失败');
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
requireMinNTQQBuild (buildStr: string) {
|
||||||
|
const currentBuild = +(this.getQQBuildStr() ?? '0');
|
||||||
|
if (currentBuild === 0) throw new Error('QQBuildStr获取失败');
|
||||||
|
return currentBuild >= parseInt(buildStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 此方法不要直接使用
|
||||||
|
getQUAFallback () {
|
||||||
|
const platformMapping: Partial<Record<NodeJS.Platform, string>> = {
|
||||||
|
win32: `V1_WIN_${this.getFullQQVersion()}_${this.getQQBuildStr()}_GW_B`,
|
||||||
|
darwin: `V1_MAC_${this.getFullQQVersion()}_${this.getQQBuildStr()}_GW_B`,
|
||||||
|
linux: `V1_LNX_${this.getFullQQVersion()}_${this.getQQBuildStr()}_GW_B`,
|
||||||
|
};
|
||||||
|
return platformMapping[systemPlatform] ?? (platformMapping.win32)!;
|
||||||
|
}
|
||||||
|
|
||||||
|
getAppIdFallback () {
|
||||||
|
const platformMapping: Partial<Record<NodeJS.Platform, string>> = {
|
||||||
|
win32: '537246092',
|
||||||
|
darwin: '537246140',
|
||||||
|
linux: '537246140',
|
||||||
|
};
|
||||||
|
return platformMapping[systemPlatform] ?? '537246092';
|
||||||
|
}
|
||||||
|
|
||||||
|
getAppidV2 (): { appid: string; qua: string; } {
|
||||||
|
// 通过已有表 性能好
|
||||||
|
const appidTbale = AppidTable as unknown as QQAppidTableType;
|
||||||
|
const fullVersion = this.getFullQQVersion();
|
||||||
|
if (fullVersion) {
|
||||||
|
const data = appidTbale[fullVersion];
|
||||||
|
if (data) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 通过Major拉取 性能差
|
||||||
|
try {
|
||||||
|
const majorAppid = this.getAppidV2ByMajor(fullVersion);
|
||||||
|
if (majorAppid) {
|
||||||
|
this.context.logger.log('[QQ版本兼容性检测] 当前版本Appid未内置 通过Major获取 为了更好的性能请尝试更新NapCat');
|
||||||
|
return { appid: majorAppid, qua: this.getQUAFallback() };
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
this.context.logger.log('[QQ版本兼容性检测] 通过Major 获取Appid异常 请检测NapCat/QQNT是否正常');
|
||||||
|
}
|
||||||
|
// 最终兜底为老版本
|
||||||
|
this.context.logger.log('[QQ版本兼容性检测] 获取Appid异常 请检测NapCat/QQNT是否正常');
|
||||||
|
this.context.logger.log(`[QQ版本兼容性检测] ${fullVersion} 版本兼容性不佳,可能会导致一些功能无法正常使用`);
|
||||||
|
return { appid: this.getAppIdFallback(), qua: this.getQUAFallback() };
|
||||||
|
}
|
||||||
|
|
||||||
|
getAppidV2ByMajor (QQVersion: string) {
|
||||||
|
const majorPath = getMajorPath(QQVersion);
|
||||||
|
const appid = parseAppidFromMajor(majorPath);
|
||||||
|
return appid;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -6,7 +6,7 @@ import {
|
|||||||
NTQQSystemApi,
|
NTQQSystemApi,
|
||||||
NTQQUserApi,
|
NTQQUserApi,
|
||||||
NTQQWebApi,
|
NTQQWebApi,
|
||||||
} from 'napcat-core/apis';
|
} from '@/napcat-core/apis';
|
||||||
import { NTQQCollectionApi } from '@/napcat-core/apis/collection';
|
import { NTQQCollectionApi } from '@/napcat-core/apis/collection';
|
||||||
import {
|
import {
|
||||||
NodeIQQNTWrapperSession,
|
NodeIQQNTWrapperSession,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { ChatType, KickedOffLineInfo, RawMessage } from '@/napcat-core/types';
|
import { ChatType, KickedOffLineInfo, RawMessage } from '@/napcat-core/types';
|
||||||
import { CommonFileInfo } from 'napcat-core/index';
|
import { CommonFileInfo } from '@/napcat-core/index';
|
||||||
|
|
||||||
export interface OnRichMediaDownloadCompleteParams {
|
export interface OnRichMediaDownloadCompleteParams {
|
||||||
fileModelId: string,
|
fileModelId: string,
|
||||||
|
|||||||
@ -4,6 +4,9 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "index.ts",
|
"main": "index.ts",
|
||||||
|
"scripts": {
|
||||||
|
"typecheck": "tsc --noEmit --skipLibCheck -p tsconfig.json"
|
||||||
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"import": "./index.ts"
|
"import": "./index.ts"
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import {
|
|||||||
PacketMsgReplyElement,
|
PacketMsgReplyElement,
|
||||||
PacketMsgVideoElement,
|
PacketMsgVideoElement,
|
||||||
} from '@/napcat-core/packet/message/element';
|
} from '@/napcat-core/packet/message/element';
|
||||||
import { ChatType, MsgSourceType, NTMsgType, RawMessage } from 'napcat-core/index';
|
import { ChatType, MsgSourceType, NTMsgType, RawMessage } from '@/napcat-core/index';
|
||||||
import { MiniAppRawData, MiniAppReqParams } from '@/napcat-core/packet/entities/miniApp';
|
import { MiniAppRawData, MiniAppReqParams } from '@/napcat-core/packet/entities/miniApp';
|
||||||
import { AIVoiceChatType } from '@/napcat-core/packet/entities/aiChat';
|
import { AIVoiceChatType } from '@/napcat-core/packet/entities/aiChat';
|
||||||
import { NapProtoDecodeStructType, NapProtoEncodeStructType, NapProtoMsg } from 'napcat-protobuf';
|
import { NapProtoDecodeStructType, NapProtoEncodeStructType, NapProtoMsg } from 'napcat-protobuf';
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { PacketHighwayContext } from '@/napcat-core/packet/highway/highwayContext';
|
import { PacketHighwayContext } from '@/napcat-core/packet/highway/highwayContext';
|
||||||
import { NapCatCore } from 'napcat-core/index';
|
import { NapCatCore } from '@/napcat-core/index';
|
||||||
import { PacketLogger } from '@/napcat-core/packet/context/loggerContext';
|
import { PacketLogger } from '@/napcat-core/packet/context/loggerContext';
|
||||||
import { NapCoreContext } from '@/napcat-core/packet/context/napCoreContext';
|
import { NapCoreContext } from '@/napcat-core/packet/context/napCoreContext';
|
||||||
import { PacketClientContext } from '@/napcat-core/packet/context/clientContext';
|
import { PacketClientContext } from '@/napcat-core/packet/context/clientContext';
|
||||||
|
|||||||
@ -32,7 +32,7 @@ import {
|
|||||||
SendTextElement,
|
SendTextElement,
|
||||||
SendVideoElement,
|
SendVideoElement,
|
||||||
Peer,
|
Peer,
|
||||||
} from 'napcat-core/index';
|
} from '@/napcat-core/index';
|
||||||
import { ForwardMsgBuilder } from 'napcat-common/src/forward-msg-builder';
|
import { ForwardMsgBuilder } from 'napcat-common/src/forward-msg-builder';
|
||||||
import { PacketMsg, PacketSendMsgElement } from '@/napcat-core/packet/message/message';
|
import { PacketMsg, PacketSendMsgElement } from '@/napcat-core/packet/message/message';
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { IPacketMsgElement } from '@/napcat-core/packet/message/element';
|
import { IPacketMsgElement } from '@/napcat-core/packet/message/element';
|
||||||
import { SendMessageElement, SendMultiForwardMsgElement } from 'napcat-core/index';
|
import { SendMessageElement, SendMultiForwardMsgElement } from '@/napcat-core/index';
|
||||||
|
|
||||||
export type PacketSendMsgElement = SendMessageElement | SendMultiForwardMsgElement;
|
export type PacketSendMsgElement = SendMessageElement | SendMultiForwardMsgElement;
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { AnyCnameRecord } from 'node:dns';
|
import { AnyCnameRecord } from 'node:dns';
|
||||||
import { BizKey, ModifyProfileParams, NodeIKernelProfileListener, ProfileBizType, SimpleInfo, UserDetailInfoByUin, UserDetailInfoListenerArg, UserDetailSource } from 'napcat-core/index';
|
import { BizKey, ModifyProfileParams, NodeIKernelProfileListener, ProfileBizType, SimpleInfo, UserDetailInfoByUin, UserDetailInfoListenerArg, UserDetailSource } from '@/napcat-core/index';
|
||||||
import { GeneralCallResult } from '@/napcat-core/services/common';
|
import { GeneralCallResult } from '@/napcat-core/services/common';
|
||||||
|
|
||||||
export interface NodeIKernelProfileService {
|
export interface NodeIKernelProfileService {
|
||||||
|
|||||||
@ -36,8 +36,8 @@
|
|||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/napcat-core/*": [
|
"@/*": [
|
||||||
"*"
|
"../*"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import { SelfInfo } from 'napcat-core/types';
|
|||||||
import { NodeIKernelLoginListener } from 'napcat-core/listeners';
|
import { NodeIKernelLoginListener } from 'napcat-core/listeners';
|
||||||
import { NodeIKernelLoginService } from 'napcat-core/services';
|
import { NodeIKernelLoginService } from 'napcat-core/services';
|
||||||
import { NodeIQQNTWrapperSession, WrapperNodeApi } from 'napcat-core/wrapper';
|
import { NodeIQQNTWrapperSession, WrapperNodeApi } from 'napcat-core/wrapper';
|
||||||
import { InitWebUi, WebUiConfig, webUiRuntimePort } from 'napcat-webui-backend/src/index';
|
import { InitWebUi, WebUiConfig, webUiRuntimePort } from 'napcat-webui-backend/index';
|
||||||
import { NapCatOneBot11Adapter } from 'napcat-onebot/index';
|
import { NapCatOneBot11Adapter } from 'napcat-onebot/index';
|
||||||
import { FFmpegService } from 'napcat-common/src/ffmpeg';
|
import { FFmpegService } from 'napcat-common/src/ffmpeg';
|
||||||
import { NativePacketHandler } from 'napcat-core/packet/handler/client';
|
import { NativePacketHandler } from 'napcat-core/packet/handler/client';
|
||||||
|
|||||||
@ -36,10 +36,9 @@
|
|||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/napcat-onebot/*": ["../napcat-onebot/*"],
|
"@/*": [
|
||||||
"@/napcat-core/*": ["../napcat-core/*"],
|
"../*"
|
||||||
"@/napcat-common/*": ["../napcat-common/src/*"],
|
]
|
||||||
"@/napcat-webui-backend/*": ["../napcat-webui-backend/src/*"]
|
|
||||||
},
|
},
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"skipDefaultLibCheck": true
|
"skipDefaultLibCheck": true
|
||||||
|
|||||||
@ -46,10 +46,10 @@ const FrameworkBaseConfig = () =>
|
|||||||
conditions: ['node', 'default'],
|
conditions: ['node', 'default'],
|
||||||
alias: {
|
alias: {
|
||||||
'@/napcat-core': resolve(__dirname, '../napcat-core'),
|
'@/napcat-core': resolve(__dirname, '../napcat-core'),
|
||||||
'@/napcat-common': resolve(__dirname, '../napcat-common/src'),
|
'@/napcat-common': resolve(__dirname, '../napcat-common'),
|
||||||
'@/napcat-onebot': resolve(__dirname, '../napcat-onebot'),
|
'@/napcat-onebot': resolve(__dirname, '../napcat-onebot'),
|
||||||
'@/napcat-pty': resolve(__dirname, '../napcat-pty'),
|
'@/napcat-pty': resolve(__dirname, '../napcat-pty'),
|
||||||
'@/napcat-webui-backend': resolve(__dirname, '../napcat-webui-backend/src'),
|
'@/napcat-webui-backend': resolve(__dirname, '../napcat-webui-backend'),
|
||||||
'@/image-size': resolve(__dirname, '../image-size'),
|
'@/image-size': resolve(__dirname, '../image-size'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -36,8 +36,8 @@
|
|||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/napcat-webui-backend/*": [
|
"@/*": [
|
||||||
"src/*"
|
"../*"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
|
|||||||
@ -11,7 +11,6 @@ import {
|
|||||||
TipGroupElement,
|
TipGroupElement,
|
||||||
TipGroupElementType,
|
TipGroupElementType,
|
||||||
} from 'napcat-core';
|
} from 'napcat-core';
|
||||||
import { NapCatOneBot11Adapter } from '@/napcat-onebot/index';
|
|
||||||
import { OB11GroupBanEvent } from '@/napcat-onebot/event/notice/OB11GroupBanEvent';
|
import { OB11GroupBanEvent } from '@/napcat-onebot/event/notice/OB11GroupBanEvent';
|
||||||
import fastXmlParser from 'fast-xml-parser';
|
import fastXmlParser from 'fast-xml-parser';
|
||||||
import { OB11GroupMsgEmojiLikeEvent } from '@/napcat-onebot/event/notice/OB11MsgEmojiLikeEvent';
|
import { OB11GroupMsgEmojiLikeEvent } from '@/napcat-onebot/event/notice/OB11MsgEmojiLikeEvent';
|
||||||
@ -26,6 +25,7 @@ import { FileNapCatOneBotUUID } from 'napcat-common/src/file-uuid';
|
|||||||
import { OB11GroupIncreaseEvent } from '../event/notice/OB11GroupIncreaseEvent';
|
import { OB11GroupIncreaseEvent } from '../event/notice/OB11GroupIncreaseEvent';
|
||||||
import { NapProtoMsg } from 'napcat-protobuf';
|
import { NapProtoMsg } from 'napcat-protobuf';
|
||||||
import { GroupReactNotify, PushMsg } from 'napcat-core/packet/transformer/proto';
|
import { GroupReactNotify, PushMsg } from 'napcat-core/packet/transformer/proto';
|
||||||
|
import { NapCatOneBot11Adapter } from '..';
|
||||||
|
|
||||||
export class OneBotGroupApi {
|
export class OneBotGroupApi {
|
||||||
obContext: NapCatOneBot11Adapter;
|
obContext: NapCatOneBot11Adapter;
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import {
|
|||||||
NTMsgAtType,
|
NTMsgAtType,
|
||||||
} from 'napcat-core';
|
} from 'napcat-core';
|
||||||
import { OB11ConfigLoader } from '@/napcat-onebot/config';
|
import { OB11ConfigLoader } from '@/napcat-onebot/config';
|
||||||
import { pendingTokenToSend } from 'napcat-webui-backend/src/index';
|
import { pendingTokenToSend } from 'napcat-webui-backend/index';
|
||||||
import {
|
import {
|
||||||
OB11HttpClientAdapter,
|
OB11HttpClientAdapter,
|
||||||
OB11WebSocketClientAdapter,
|
OB11WebSocketClientAdapter,
|
||||||
|
|||||||
@ -4,6 +4,9 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "index.ts",
|
"main": "index.ts",
|
||||||
|
"scripts": {
|
||||||
|
"typecheck": "tsc --noEmit --skipLibCheck -p tsconfig.json"
|
||||||
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"import": "./index.ts"
|
"import": "./index.ts"
|
||||||
|
|||||||
@ -36,8 +36,8 @@
|
|||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/napcat-onebot/*": [
|
"@/*": [
|
||||||
"*"
|
"../*"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
|
|||||||
@ -14,12 +14,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@homebridge/node-pty-prebuilt-multiarch":"^0.12.0",
|
"@homebridge/node-pty-prebuilt-multiarch":"^0.12.0"
|
||||||
"napcat-core": "workspace:*",
|
|
||||||
"napcat-common": "workspace:*",
|
|
||||||
"napcat-onebot": "workspace:*",
|
|
||||||
"napcat-webui-backend": "workspace:*",
|
|
||||||
"napcat-qrcode": "workspace:*"
|
|
||||||
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@ -26,7 +26,7 @@ import os from 'os';
|
|||||||
import { LoginListItem, NodeIKernelLoginService } from 'napcat-core/services';
|
import { LoginListItem, NodeIKernelLoginService } from 'napcat-core/services';
|
||||||
import qrcode from 'napcat-qrcode/lib/main';
|
import qrcode from 'napcat-qrcode/lib/main';
|
||||||
import { NapCatOneBot11Adapter } from 'napcat-onebot/index';
|
import { NapCatOneBot11Adapter } from 'napcat-onebot/index';
|
||||||
import { InitWebUi } from 'napcat-webui-backend/src/index';
|
import { InitWebUi } from 'napcat-webui-backend/index';
|
||||||
import { WebUiDataRuntime } from 'napcat-webui-backend/src/helper/Data';
|
import { WebUiDataRuntime } from 'napcat-webui-backend/src/helper/Data';
|
||||||
import { napCatVersion } from 'napcat-common/src/version';
|
import { napCatVersion } from 'napcat-common/src/version';
|
||||||
import { NodeIO3MiscListener } from 'napcat-core/listeners/NodeIO3MiscListener';
|
import { NodeIO3MiscListener } from 'napcat-core/listeners/NodeIO3MiscListener';
|
||||||
|
|||||||
@ -36,10 +36,9 @@
|
|||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/napcat-onebot/*": ["../napcat-onebot/*"],
|
"@/*": [
|
||||||
"@/napcat-core/*": ["../napcat-core/*"],
|
"../*"
|
||||||
"@/napcat-common/*": ["../napcat-common/src/*"],
|
]
|
||||||
"@/napcat-webui-backend/*": ["../napcat-webui-backend/src/*"]
|
|
||||||
},
|
},
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"skipDefaultLibCheck": true
|
"skipDefaultLibCheck": true
|
||||||
|
|||||||
@ -41,10 +41,10 @@ const ShellBaseConfig = (source_map: boolean = false) =>
|
|||||||
conditions: ['node', 'default'],
|
conditions: ['node', 'default'],
|
||||||
alias: {
|
alias: {
|
||||||
'@/napcat-core': resolve(__dirname, '../napcat-core'),
|
'@/napcat-core': resolve(__dirname, '../napcat-core'),
|
||||||
'@/napcat-common': resolve(__dirname, '../napcat-common/src'),
|
'@/napcat-common': resolve(__dirname, '../napcat-common'),
|
||||||
'@/napcat-onebot': resolve(__dirname, '../napcat-onebot'),
|
'@/napcat-onebot': resolve(__dirname, '../napcat-onebot'),
|
||||||
'@/napcat-pty': resolve(__dirname, '../napcat-pty'),
|
'@/napcat-pty': resolve(__dirname, '../napcat-pty'),
|
||||||
'@/napcat-webui-backend': resolve(__dirname, '../napcat-webui-backend/src'),
|
'@/napcat-webui-backend': resolve(__dirname, '../napcat-webui-backend'),
|
||||||
'@/image-size': resolve(__dirname, '../image-size'),
|
'@/image-size': resolve(__dirname, '../image-size'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -3,22 +3,22 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import type { WebUiConfigType } from './types';
|
import type { WebUiConfigType } from './src/types';
|
||||||
import { createServer } from 'http';
|
import { createServer } from 'http';
|
||||||
import { randomUUID } from 'node:crypto';
|
import { randomUUID } from 'node:crypto';
|
||||||
import { createServer as createHttpsServer } from 'https';
|
import { createServer as createHttpsServer } from 'https';
|
||||||
import { LogWrapper } from 'napcat-common/src/log';
|
import { LogWrapper } from 'napcat-common/src/log';
|
||||||
import { NapCatPathWrapper } from 'napcat-common/src/path';
|
import { NapCatPathWrapper } from 'napcat-common/src/path';
|
||||||
import { WebUiConfigWrapper } from '@/napcat-webui-backend/helper/config';
|
import { WebUiConfigWrapper } from '@/napcat-webui-backend/src/helper/config';
|
||||||
import { ALLRouter } from '@/napcat-webui-backend/router';
|
import { ALLRouter } from '@/napcat-webui-backend/src/router';
|
||||||
import { cors } from '@/napcat-webui-backend/middleware/cors';
|
import { cors } from '@/napcat-webui-backend/src/middleware/cors';
|
||||||
import { createUrl, getRandomToken } from '@/napcat-webui-backend/utils/url';
|
import { createUrl, getRandomToken } from '@/napcat-webui-backend/src/utils/url';
|
||||||
import { sendError } from '@/napcat-webui-backend/utils/response';
|
import { sendError } from '@/napcat-webui-backend/src/utils/response';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { terminalManager } from '@/napcat-webui-backend/terminal/terminal_manager';
|
import { terminalManager } from '@/napcat-webui-backend/src/terminal/terminal_manager';
|
||||||
import multer from 'multer';
|
import multer from 'multer';
|
||||||
import * as net from 'node:net';
|
import * as net from 'node:net';
|
||||||
import { WebUiDataRuntime } from './helper/Data';
|
import { WebUiDataRuntime } from './src/helper/Data';
|
||||||
import { existsSync, readFileSync } from 'node:fs'; // 引入multer用于错误捕获
|
import { existsSync, readFileSync } from 'node:fs'; // 引入multer用于错误捕获
|
||||||
|
|
||||||
// 实例化Express
|
// 实例化Express
|
||||||
@ -3,7 +3,10 @@
|
|||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "src/index.ts",
|
"main": "index.ts",
|
||||||
|
"scripts": {
|
||||||
|
"typecheck": "tsc --noEmit --skipLibCheck -p tsconfig.json"
|
||||||
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"import": "./index.ts"
|
"import": "./index.ts"
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
import { RequestHandler } from 'express';
|
import { RequestHandler } from 'express';
|
||||||
|
import { AuthHelper } from '@/napcat-webui-backend/src/helper/SignToken';
|
||||||
|
import { WebUiDataRuntime } from '@/napcat-webui-backend/src/helper/Data';
|
||||||
|
import { sendSuccess, sendError } from '@/napcat-webui-backend/src/utils/response';
|
||||||
|
import { isEmpty } from '@/napcat-webui-backend/src/utils/check';
|
||||||
import { WebUiConfig, getInitialWebUiToken, setInitialWebUiToken } from '@/napcat-webui-backend/index';
|
import { WebUiConfig, getInitialWebUiToken, setInitialWebUiToken } from '@/napcat-webui-backend/index';
|
||||||
|
|
||||||
import { AuthHelper } from '@/napcat-webui-backend/helper/SignToken';
|
|
||||||
import { WebUiDataRuntime } from '@/napcat-webui-backend/helper/Data';
|
|
||||||
import { sendSuccess, sendError } from '@/napcat-webui-backend/utils/response';
|
|
||||||
import { isEmpty } from '@/napcat-webui-backend/utils/check';
|
|
||||||
|
|
||||||
// 登录
|
// 登录
|
||||||
export const LoginHandler: RequestHandler = async (req, res) => {
|
export const LoginHandler: RequestHandler = async (req, res) => {
|
||||||
// 获取WebUI配置
|
// 获取WebUI配置
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { RequestHandler } from 'express';
|
import { RequestHandler } from 'express';
|
||||||
import { WebUiDataRuntime } from '@/napcat-webui-backend/helper/Data';
|
import { WebUiDataRuntime } from '@/napcat-webui-backend/src/helper/Data';
|
||||||
|
|
||||||
import { sendSuccess } from '@/napcat-webui-backend/utils/response';
|
import { sendSuccess } from '@/napcat-webui-backend/src/utils/response';
|
||||||
import { WebUiConfig } from '@/napcat-webui-backend/index';
|
import { WebUiConfig } from '@/napcat-webui-backend/index';
|
||||||
|
|
||||||
export const GetNapCatVersion: RequestHandler = (_, res) => {
|
export const GetNapCatVersion: RequestHandler = (_, res) => {
|
||||||
|
|||||||
@ -3,9 +3,9 @@ import { existsSync, readFileSync } from 'node:fs';
|
|||||||
import { resolve } from 'node:path';
|
import { resolve } from 'node:path';
|
||||||
import { loadConfig, OneBotConfig } from 'napcat-onebot/config/config';
|
import { loadConfig, OneBotConfig } from 'napcat-onebot/config/config';
|
||||||
import { webUiPathWrapper } from '@/napcat-webui-backend/index';
|
import { webUiPathWrapper } from '@/napcat-webui-backend/index';
|
||||||
import { WebUiDataRuntime } from '@/napcat-webui-backend/helper/Data';
|
import { WebUiDataRuntime } from '@/napcat-webui-backend/src/helper/Data';
|
||||||
import { sendError, sendSuccess } from '@/napcat-webui-backend/utils/response';
|
import { sendError, sendSuccess } from '@/napcat-webui-backend/src/utils/response';
|
||||||
import { isEmpty } from '@/napcat-webui-backend/utils/check';
|
import { isEmpty } from '@/napcat-webui-backend/src/utils/check';
|
||||||
import json5 from 'json5';
|
import json5 from 'json5';
|
||||||
|
|
||||||
// 获取OneBot11配置
|
// 获取OneBot11配置
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import { RequestHandler } from 'express';
|
import { RequestHandler } from 'express';
|
||||||
|
|
||||||
import { WebUiDataRuntime } from '@/napcat-webui-backend/helper/Data';
|
import { WebUiDataRuntime } from '@/napcat-webui-backend/src/helper/Data';
|
||||||
import { isEmpty } from '@/napcat-webui-backend/utils/check';
|
import { isEmpty } from '@/napcat-webui-backend/src/utils/check';
|
||||||
import { sendError, sendSuccess } from '@/napcat-webui-backend/utils/response';
|
import { sendError, sendSuccess } from '@/napcat-webui-backend/src/utils/response';
|
||||||
import { WebUiConfig } from '@/napcat-webui-backend/index';
|
import { WebUiConfig } from '@/napcat-webui-backend/index';
|
||||||
|
|
||||||
// 获取QQ登录二维码
|
// 获取QQ登录二维码
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { RequestHandler } from 'express';
|
import { RequestHandler } from 'express';
|
||||||
import { WebUiConfig } from '@/napcat-webui-backend/index';
|
import { WebUiConfig } from '@/napcat-webui-backend/index';
|
||||||
import { sendError, sendSuccess } from '@/napcat-webui-backend/utils/response';
|
import { sendError, sendSuccess } from '@/napcat-webui-backend/src/utils/response';
|
||||||
import { isEmpty } from '@/napcat-webui-backend/utils/check';
|
import { isEmpty } from '@/napcat-webui-backend/src/utils/check';
|
||||||
|
|
||||||
// 获取WebUI基础配置
|
// 获取WebUI基础配置
|
||||||
export const GetWebUIConfigHandler: RequestHandler = async (_, res) => {
|
export const GetWebUIConfigHandler: RequestHandler = async (_, res) => {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import store from 'napcat-common/src/store';
|
import store from 'napcat-common/src/store';
|
||||||
import type { WebUiCredentialJson, WebUiCredentialInnerJson } from '@/napcat-webui-backend/types';
|
import type { WebUiCredentialJson, WebUiCredentialInnerJson } from '@/napcat-webui-backend/src/types';
|
||||||
export class AuthHelper {
|
export class AuthHelper {
|
||||||
private static readonly secretKey = Math.random().toString(36).slice(2);
|
private static readonly secretKey = Math.random().toString(36).slice(2);
|
||||||
|
|
||||||
|
|||||||
@ -2,9 +2,9 @@ import { NextFunction, Request, Response } from 'express';
|
|||||||
|
|
||||||
import { getInitialWebUiToken } from '@/napcat-webui-backend/index';
|
import { getInitialWebUiToken } from '@/napcat-webui-backend/index';
|
||||||
|
|
||||||
import { AuthHelper } from '@/napcat-webui-backend/helper/SignToken';
|
import { AuthHelper } from '@/napcat-webui-backend/src/helper/SignToken';
|
||||||
import { sendError } from '@/napcat-webui-backend/utils/response';
|
import { sendError } from '@/napcat-webui-backend/src/utils/response';
|
||||||
import type { WebUiCredentialJson } from '@/napcat-webui-backend/types';
|
import type { WebUiCredentialJson } from '@/napcat-webui-backend/src/types';
|
||||||
|
|
||||||
// 鉴权中间件
|
// 鉴权中间件
|
||||||
export async function auth (req: Request, res: Response, next: NextFunction) {
|
export async function auth (req: Request, res: Response, next: NextFunction) {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import { GetThemeConfigHandler, GetNapCatVersion, QQVersionHandler, SetThemeConfigHandler } from '../api/BaseInfo';
|
import { GetThemeConfigHandler, GetNapCatVersion, QQVersionHandler, SetThemeConfigHandler } from '../api/BaseInfo';
|
||||||
import { StatusRealTimeHandler } from '@/napcat-webui-backend/api/Status';
|
import { StatusRealTimeHandler } from '@/napcat-webui-backend/src/api/Status';
|
||||||
import { GetProxyHandler } from '../api/Proxy';
|
import { GetProxyHandler } from '../api/Proxy';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
|
|
||||||
import { OB11GetConfigHandler, OB11SetConfigHandler } from '@/napcat-webui-backend/api/OB11Config';
|
import { OB11GetConfigHandler, OB11SetConfigHandler } from '@/napcat-webui-backend/src/api/OB11Config';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
// router:读取配置
|
// router:读取配置
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import {
|
|||||||
getQQLoginInfoHandler,
|
getQQLoginInfoHandler,
|
||||||
getAutoLoginAccountHandler,
|
getAutoLoginAccountHandler,
|
||||||
setAutoLoginAccountHandler,
|
setAutoLoginAccountHandler,
|
||||||
} from '@/napcat-webui-backend/api/QQLogin';
|
} from '@/napcat-webui-backend/src/api/QQLogin';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
// router:获取快速登录列表
|
// router:获取快速登录列表
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import {
|
|||||||
GetDisableNonLANAccessHandler,
|
GetDisableNonLANAccessHandler,
|
||||||
UpdateDisableNonLANAccessHandler,
|
UpdateDisableNonLANAccessHandler,
|
||||||
UpdateWebUIConfigHandler,
|
UpdateWebUIConfigHandler,
|
||||||
} from '@/napcat-webui-backend/api/WebUIConfig';
|
} from '@/napcat-webui-backend/src/api/WebUIConfig';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import {
|
|||||||
LoginHandler,
|
LoginHandler,
|
||||||
LogoutHandler,
|
LogoutHandler,
|
||||||
UpdateTokenHandler,
|
UpdateTokenHandler,
|
||||||
} from '@/napcat-webui-backend/api/Auth';
|
} from '@/napcat-webui-backend/src/api/Auth';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
// router:登录
|
// router:登录
|
||||||
|
|||||||
@ -4,14 +4,14 @@
|
|||||||
|
|
||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
|
|
||||||
import { OB11ConfigRouter } from '@/napcat-webui-backend/router/OB11Config';
|
import { OB11ConfigRouter } from '@/napcat-webui-backend/src/router/OB11Config';
|
||||||
import { auth } from '@/napcat-webui-backend/middleware/auth';
|
import { auth } from '@/napcat-webui-backend/src/middleware/auth';
|
||||||
import { sendSuccess } from '@/napcat-webui-backend/utils/response';
|
import { sendSuccess } from '@/napcat-webui-backend/src/utils/response';
|
||||||
|
|
||||||
import { QQLoginRouter } from '@/napcat-webui-backend/router/QQLogin';
|
import { QQLoginRouter } from '@/napcat-webui-backend/src/router/QQLogin';
|
||||||
import { AuthRouter } from '@/napcat-webui-backend/router/auth';
|
import { AuthRouter } from '@/napcat-webui-backend/src/router/auth';
|
||||||
import { LogRouter } from '@/napcat-webui-backend/router/Log';
|
import { LogRouter } from '@/napcat-webui-backend/src/router/Log';
|
||||||
import { BaseRouter } from '@/napcat-webui-backend/router/Base';
|
import { BaseRouter } from '@/napcat-webui-backend/src/router/Base';
|
||||||
import { FileRouter } from './File';
|
import { FileRouter } from './File';
|
||||||
import { WebUIConfigRouter } from './WebUIConfig';
|
import { WebUIConfigRouter } from './WebUIConfig';
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
// import './init-dynamic-dirname';
|
// import './init-dynamic-dirname';
|
||||||
import { WebUiConfig } from '../index';
|
import { WebUiConfig } from '../../index';
|
||||||
import { AuthHelper } from '../helper/SignToken';
|
import { AuthHelper } from '../helper/SignToken';
|
||||||
import type { WebUiCredentialJson } from '@/napcat-webui-backend/types';
|
import type { WebUiCredentialJson } from '@/napcat-webui-backend/src/types';
|
||||||
import { LogWrapper } from 'napcat-common/src/log';
|
import { LogWrapper } from 'napcat-common/src/log';
|
||||||
import { WebSocket, WebSocketServer } from 'ws';
|
import { WebSocket, WebSocketServer } from 'ws';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import type { Response } from 'express';
|
import type { Response } from 'express';
|
||||||
|
|
||||||
import { ResponseCode, HttpStatusCode } from '@/napcat-webui-backend/const/status';
|
import { ResponseCode, HttpStatusCode } from '@/napcat-webui-backend/src/const/status';
|
||||||
|
|
||||||
export const sendResponse = <T>(
|
export const sendResponse = <T>(
|
||||||
res: Response,
|
res: Response,
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
],
|
],
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"outDir": "dist",
|
"outDir": "dist",
|
||||||
"rootDir": "src",
|
"rootDir": ".",
|
||||||
"noEmit": false,
|
"noEmit": false,
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
@ -36,14 +36,15 @@
|
|||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/napcat-webui-backend/*": [
|
"@/*": [
|
||||||
"src/*"
|
"../*"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"skipDefaultLibCheck": true
|
"skipDefaultLibCheck": true
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
|
"*.ts",
|
||||||
"src/**/*.ts",
|
"src/**/*.ts",
|
||||||
"src/**/*.d.ts"
|
"src/**/*.d.ts"
|
||||||
],
|
],
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite --host=0.0.0.0",
|
"dev": "vite --host=0.0.0.0",
|
||||||
"build": "tsc && vite build",
|
"build": "tsc && vite build",
|
||||||
|
"typecheck": "tsc --noEmit",
|
||||||
"lint": "eslint -c eslint.config.mjs ./src/**/**/*.{ts,tsx} --fix",
|
"lint": "eslint -c eslint.config.mjs ./src/**/**/*.{ts,tsx} --fix",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user