chore: run a full eslint

This commit is contained in:
Wesley F. Young
2024-08-10 19:58:31 +08:00
parent 9a9511aad6
commit 116a04e081
198 changed files with 8187 additions and 7744 deletions

View File

@@ -1,2 +1,3 @@
# The Path of NapCatQQ
Tiny WebUi for NapCatQQ
Tiny WebUi for NapCatQQ

View File

@@ -1,14 +1,12 @@
import express from 'express';
import { NextFunction, Request, Response } from 'express';
import { AuthHelper } from './src/helper/SignToken';
import { resolve } from 'node:path';
import { dirname, resolve } from 'node:path';
import { ALLRouter } from './src/router';
import { WebUiConfig } from './src/helper/config';
const app = express();
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { log } from '@/common/utils/log';
const app = express();
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

View File

@@ -2,6 +2,7 @@ import { RequestHandler } from 'express';
import { AuthHelper } from '../helper/SignToken';
import { WebUiConfig } from '../helper/config';
import { WebUiDataRuntime } from '../helper/Data';
const isEmpty = (data: any) => data === undefined || data === null || data === '';
export const LoginHandler: RequestHandler = async (req, res) => {
const WebUiConfigData = await WebUiConfig.GetWebUIConfig();
@@ -9,14 +10,14 @@ export const LoginHandler: RequestHandler = async (req, res) => {
if (isEmpty(token)) {
res.json({
code: -1,
message: 'token is empty'
message: 'token is empty',
});
return;
}
}
if (!await WebUiDataRuntime.checkLoginRate(WebUiConfigData.loginRate)) {
res.json({
code: -1,
message: 'login rate limit'
message: 'login rate limit',
});
return;
}
@@ -24,7 +25,7 @@ export const LoginHandler: RequestHandler = async (req, res) => {
if (WebUiConfigData.token !== token) {
res.json({
code: -1,
message: 'token is invalid'
message: 'token is invalid',
});
return;
}
@@ -33,8 +34,8 @@ export const LoginHandler: RequestHandler = async (req, res) => {
code: 0,
message: 'success',
data: {
'Credential': signCredential
}
'Credential': signCredential,
},
});
return;
};
@@ -42,7 +43,7 @@ export const LogoutHandler: RequestHandler = (req, res) => {
// 这玩意无状态销毁个灯 得想想办法
res.json({
code: 0,
message: 'success'
message: 'success',
});
return;
};
@@ -50,18 +51,18 @@ export const checkHandler: RequestHandler = async (req, res) => {
const WebUiConfigData = await WebUiConfig.GetWebUIConfig();
const authorization = req.headers.authorization;
try {
const CredentialBase64:string = authorization?.split(' ')[1] as string;
const CredentialBase64: string = authorization?.split(' ')[1] as string;
const Credential = JSON.parse(Buffer.from(CredentialBase64, 'base64').toString());
await AuthHelper.validateCredentialWithinOneHour(WebUiConfigData.token,Credential);
await AuthHelper.validateCredentialWithinOneHour(WebUiConfigData.token, Credential);
res.json({
code: 0,
message: 'success'
message: 'success',
});
return;
} catch (e) {
res.json({
code: -1,
message: 'failed'
message: 'failed',
});
}
return;

View File

@@ -14,7 +14,7 @@ export const GetLogFileListHandler: RequestHandler = async (req, res) => {
const LogFiles = await readdir(LogsPath);
res.json({
code: 0,
data: LogFiles
data: LogFiles,
});
} catch (error) {
res.json({ code: -1, msg: 'Failed to retrieve log file list.' });
@@ -51,4 +51,4 @@ export const GetLogFileHandler: RequestHandler = async (req, res) => {
// export function isValidFileName(fileName: string): boolean {
// const invalidChars = /[\.\:\*\?\"\<\>\|\/\\]/;
// return !invalidChars.test(fileName);
// }
// }

View File

@@ -1,9 +1,8 @@
import { RequestHandler } from 'express';
import { WebUiDataRuntime } from '../helper/Data';
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { existsSync, readFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { OB11Config } from '@/webui/ui/components/WebUiApiOB11Config';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -29,7 +28,7 @@ export const OB11GetConfigHandler: RequestHandler = async (req, res) => {
data = JSON.parse(
existsSync(configFilePath)
? readFileSync(configFilePath).toString()
: readFileSync(resolve(__dirname, './config/onebot11.json')).toString()
: readFileSync(resolve(__dirname, './config/onebot11.json')).toString(),
);
} catch (e) {
data = {} as OB11Config;

View File

@@ -1,12 +1,12 @@
import { RequestHandler } from 'express';
import { WebUiDataRuntime } from '../helper/Data';
import { sleep } from '@/common/utils/helper';
const isEmpty = (data: any) => data === undefined || data === null || data === '';
export const QQGetQRcodeHandler: RequestHandler = async (req, res) => {
if (await WebUiDataRuntime.getQQLoginStatus()) {
res.send({
code: -1,
message: 'QQ Is Logined'
message: 'QQ Is Logined',
});
return;
}
@@ -14,7 +14,7 @@ export const QQGetQRcodeHandler: RequestHandler = async (req, res) => {
if (isEmpty(qrcodeUrl)) {
res.send({
code: -1,
message: 'QRCode Get Error'
message: 'QRCode Get Error',
});
return;
}
@@ -22,8 +22,8 @@ export const QQGetQRcodeHandler: RequestHandler = async (req, res) => {
code: 0,
message: 'success',
data: {
qrcode: qrcodeUrl
}
qrcode: qrcodeUrl,
},
});
return;
};
@@ -32,8 +32,8 @@ export const QQCheckLoginStatusHandler: RequestHandler = async (req, res) => {
code: 0,
message: 'success',
data: {
isLogin: await WebUiDataRuntime.getQQLoginStatus()
}
isLogin: await WebUiDataRuntime.getQQLoginStatus(),
},
});
};
export const QQSetQuickLoginHandler: RequestHandler = async (req, res) => {
@@ -42,14 +42,14 @@ export const QQSetQuickLoginHandler: RequestHandler = async (req, res) => {
if (isLogin) {
res.send({
code: -1,
message: 'QQ Is Logined'
message: 'QQ Is Logined',
});
return;
}
if (isEmpty(uin)) {
res.send({
code: -1,
message: 'uin is empty'
message: 'uin is empty',
});
return;
}
@@ -57,7 +57,7 @@ export const QQSetQuickLoginHandler: RequestHandler = async (req, res) => {
if (!result) {
res.send({
code: -1,
message: message
message: message,
});
return;
}
@@ -65,13 +65,13 @@ export const QQSetQuickLoginHandler: RequestHandler = async (req, res) => {
//isLogin = await WebUiDataRuntime.getQQLoginStatus();
res.send({
code: 0,
message: 'success'
message: 'success',
});
};
export const QQGetQuickLoginListHandler: RequestHandler = async (req, res) => {
const quickLoginList = await WebUiDataRuntime.getQQQuickLoginList();
res.send({
code: 0,
data: quickLoginList
data: quickLoginList,
});
};
};

View File

@@ -10,8 +10,9 @@ interface LoginRuntimeType {
CoreQuickLoginCall: (uin: string) => Promise<{ result: boolean, message: string }>;
SetOb11ConfigCall: (ob11: OB11Config) => Promise<void>;
QQLoginList: string[]
}
};
}
const LoginRuntime: LoginRuntimeType = {
LoginCurrentTime: Date.now(),
LoginCurrentRate: 0,
@@ -19,13 +20,17 @@ const LoginRuntime: LoginRuntimeType = {
QQQRCodeURL: '',
QQLoginUin: '',
NapCatHelper: {
SetOb11ConfigCall: async (ob11: OB11Config) => { return; },
CoreQuickLoginCall: async (uin: string) => { return { result: false, message: '' }; },
QQLoginList: []
}
SetOb11ConfigCall: async (ob11: OB11Config) => {
return;
},
CoreQuickLoginCall: async (uin: string) => {
return { result: false, message: '' };
},
QQLoginList: [],
},
};
export const WebUiDataRuntime = {
checkLoginRate: async function (RateLimit: number): Promise<boolean> {
checkLoginRate: async function(RateLimit: number): Promise<boolean> {
LoginRuntime.LoginCurrentRate++;
//console.log(RateLimit, LoginRuntime.LoginCurrentRate, Date.now() - LoginRuntime.LoginCurrentTime);
if (Date.now() - LoginRuntime.LoginCurrentTime > 1000 * 60) {
@@ -39,45 +44,45 @@ export const WebUiDataRuntime = {
return false;
}
,
getQQLoginStatus: async function (): Promise<boolean> {
getQQLoginStatus: async function(): Promise<boolean> {
return LoginRuntime.QQLoginStatus;
}
,
setQQLoginStatus: async function (status: boolean): Promise<void> {
setQQLoginStatus: async function(status: boolean): Promise<void> {
LoginRuntime.QQLoginStatus = status;
}
,
setQQLoginQrcodeURL: async function (url: string): Promise<void> {
setQQLoginQrcodeURL: async function(url: string): Promise<void> {
LoginRuntime.QQQRCodeURL = url;
}
,
getQQLoginQrcodeURL: async function (): Promise<string> {
getQQLoginQrcodeURL: async function(): Promise<string> {
return LoginRuntime.QQQRCodeURL;
}
,
setQQLoginUin: async function (uin: string): Promise<void> {
setQQLoginUin: async function(uin: string): Promise<void> {
LoginRuntime.QQLoginUin = uin;
}
,
getQQLoginUin: async function (): Promise<string> {
getQQLoginUin: async function(): Promise<string> {
return LoginRuntime.QQLoginUin;
},
getQQQuickLoginList: async function (): Promise<any[]> {
getQQQuickLoginList: async function(): Promise<any[]> {
return LoginRuntime.NapCatHelper.QQLoginList;
},
setQQQuickLoginList: async function (list: string[]): Promise<void> {
setQQQuickLoginList: async function(list: string[]): Promise<void> {
LoginRuntime.NapCatHelper.QQLoginList = list;
},
setQQQuickLoginCall(func: (uin: string) => Promise<{ result: boolean, message: string }>): void {
LoginRuntime.NapCatHelper.CoreQuickLoginCall = func;
},
getQQQuickLogin: async function (uin: string): Promise<{ result: boolean, message: string }> {
getQQQuickLogin: async function(uin: string): Promise<{ result: boolean, message: string }> {
return await LoginRuntime.NapCatHelper.CoreQuickLoginCall(uin);
},
setOB11ConfigCall: async function (func: (ob11: OB11Config) => Promise<void>): Promise<void> {
setOB11ConfigCall: async function(func: (ob11: OB11Config) => Promise<void>): Promise<void> {
LoginRuntime.NapCatHelper.SetOb11ConfigCall = func;
},
setOB11Config: async function (ob11: OB11Config): Promise<void> {
setOB11Config: async function(ob11: OB11Config): Promise<void> {
await LoginRuntime.NapCatHelper.SetOb11ConfigCall(ob11);
}
};
},
};

View File

@@ -65,4 +65,4 @@ export class AuthHelper {
return timeDifference <= 3600 && credentialJson.Data.TokenEncoded === token;
}
}
}

View File

@@ -1,7 +1,6 @@
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { dirname, resolve } from 'node:path';
import * as net from 'node:net';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -73,14 +72,17 @@ export interface WebUiConfigType {
port: number;
prefix: string;
token: string;
loginRate: number
loginRate: number;
}
// 读取当前目录下名为 webui.json 的配置文件,如果不存在则创建初始化配置文件
class WebUiConfigWrapper {
WebUiConfigData: WebUiConfigType | undefined = undefined;
private applyDefaults<T>(obj: Partial<T>, defaults: T): T {
return { ...defaults, ...obj };
}
async GetWebUIConfig(): Promise<WebUiConfigType> {
if (this.WebUiConfigData) {
return this.WebUiConfigData;
@@ -90,7 +92,7 @@ class WebUiConfigWrapper {
port: 6099,
prefix: '',
token: '', // 默认先填空,空密码无法登录
loginRate: 3
loginRate: 3,
};
try {
defaultconfig.token = Math.random().toString(36).slice(2); //生成随机密码
@@ -138,4 +140,5 @@ class WebUiConfigWrapper {
return defaultconfig; // 理论上这行代码到不了,到了只能返回默认配置了
}
}
export const WebUiConfig = new WebUiConfigWrapper();

View File

@@ -1,6 +1,7 @@
import { Router } from 'express';
import { OB11GetConfigHandler,OB11SetConfigHandler } from '../api/OB11Config';
import { OB11GetConfigHandler, OB11SetConfigHandler } from '../api/OB11Config';
const router = Router();
router.post('/GetConfig', OB11GetConfigHandler);
router.post('/SetConfig', OB11SetConfigHandler);
export { router as OB11ConfigRouter };
export { router as OB11ConfigRouter };

View File

@@ -1,8 +1,14 @@
import { Router } from 'express';
import { QQCheckLoginStatusHandler, QQGetQRcodeHandler, QQGetQuickLoginListHandler, QQSetQuickLoginHandler } from '../api/QQLogin';
import {
QQCheckLoginStatusHandler,
QQGetQRcodeHandler,
QQGetQuickLoginListHandler,
QQSetQuickLoginHandler,
} from '../api/QQLogin';
const router = Router();
router.all('/GetQuickLoginList', QQGetQuickLoginListHandler);
router.post('/CheckLoginStatus', QQCheckLoginStatusHandler);
router.post('/GetQQLoginQrcode', QQGetQRcodeHandler);
router.post('/SetQuickLogin', QQSetQuickLoginHandler);
export { router as QQLoginRouter };
export { router as QQLoginRouter };

View File

@@ -1,9 +1,9 @@
import { Router } from 'express';
import { LoginHandler, LogoutHandler, checkHandler } from '../api/Auth';
import { checkHandler, LoginHandler, LogoutHandler } from '../api/Auth';
const router = Router();
router.post('/login', LoginHandler);
router.post('/check', checkHandler);
router.post('/logout', LogoutHandler);
export { router as AuthRouter };
export { router as AuthRouter };

View File

@@ -1,11 +1,12 @@
import { Router } from 'express';
import { NextFunction, Request, Response, Router } from 'express';
import { AuthHelper } from '../../src/helper/SignToken';
import { NextFunction, Request, Response } from 'express';
import { QQLoginRouter } from './QQLogin';
import { AuthRouter } from './auth';
import { OB11ConfigRouter } from './OB11Config';
import { WebUiConfig } from '../helper/config';
const router = Router();
export async function AuthApi(req: Request, res: Response, next: NextFunction) {
//判断当前url是否为/login 如果是跳过鉴权
if (req.url == '/auth/login') {
@@ -52,6 +53,7 @@ export async function AuthApi(req: Request, res: Response, next: NextFunction) {
});
return;
}
router.use(AuthApi);
router.all('/test', (req, res) => {
res.json({
@@ -62,4 +64,4 @@ router.all('/test', (req, res) => {
router.use('/auth', AuthRouter);
router.use('/QQLogin', QQLoginRouter);
router.use('/OB11Config', OB11ConfigRouter);
export { router as ALLRouter };
export { router as ALLRouter };

View File

@@ -4,6 +4,7 @@ import { SettingButton } from './components/SettingButton';
import { SettingSwitch } from './components/SettingSwitch';
import { SettingSelect } from './components/SettingSelect';
import { OB11Config, OB11ConfigWrapper } from './components/WebUiApiOB11Config';
async function onSettingWindowCreated(view: Element) {
const isEmpty = (value: any) => value === undefined || value === undefined || value === '';
await OB11ConfigWrapper.Init(localStorage.getItem('auth') as string);
@@ -15,7 +16,7 @@ async function onSettingWindowCreated(view: Element) {
} else if (configKey.length === 3) {
ob11Config[configKey[1]][configKey[2]] = value;
}
// OB11ConfigWrapper.SetOB11Config(ob11Config); // 只有当点保存时才下发配置,而不是在修改值后立即下发
// OB11ConfigWrapper.SetOB11Config(ob11Config); // 只有当点保存时才下发配置,而不是在修改值后立即下发
};
const parser = new DOMParser();
@@ -29,7 +30,7 @@ async function onSettingWindowCreated(view: Element) {
SettingItem(
'<span id="napcat-update-title">Napcat</span>',
undefined,
SettingButton('V1.8.3', 'napcat-update-button', 'secondary')
SettingButton('V1.8.3', 'napcat-update-button', 'secondary'),
),
]),
SettingList([
@@ -38,28 +39,28 @@ async function onSettingWindowCreated(view: Element) {
undefined,
SettingSwitch('ob11.http.enable', ob11Config.http.enable, {
'control-display-id': 'config-ob11-http-port',
})
}),
),
SettingItem(
'HTTP 服务监听端口',
undefined,
`<div class="q-input"><input class="q-input__inner" data-config-key="ob11.http.port" type="number" min="1" max="65534" value="${ob11Config.http.port}" placeholder="${ob11Config.http.port}" /></div>`,
'config-ob11-http-port',
ob11Config.http.enable
ob11Config.http.enable,
),
SettingItem(
'启用 HTTP 心跳',
undefined,
SettingSwitch('ob11.http.enableHeart', ob11Config.http.enableHeart, {
'control-display-id': 'config-ob11-HTTP.enableHeart',
})
}),
),
SettingItem(
'启用 HTTP 事件上报',
undefined,
SettingSwitch('ob11.http.enablePost', ob11Config.http.enablePost, {
'control-display-id': 'config-ob11-http-postUrls',
})
}),
),
`<div class="config-host-list" id="config-ob11-http-postUrls" ${ob11Config.http.enablePost ? '' : 'is-hidden'
}>
@@ -85,21 +86,21 @@ async function onSettingWindowCreated(view: Element) {
undefined,
SettingSwitch('ob11.ws.enable', ob11Config.ws.enable, {
'control-display-id': 'config-ob11-ws-port',
})
}),
),
SettingItem(
'正向 WebSocket 服务监听端口',
undefined,
`<div class="q-input"><input class="q-input__inner" data-config-key="ob11.ws.port" type="number" min="1" max="65534" value="${ob11Config.ws.port}" placeholder="${ob11Config.ws.port}" /></div>`,
'config-ob11-ws-port',
ob11Config.ws.enable
ob11Config.ws.enable,
),
SettingItem(
'启用反向 WebSocket 服务',
undefined,
SettingSwitch('ob11.reverseWs.enable', ob11Config.reverseWs.enable, {
'control-display-id': 'config-ob11-reverseWs-urls',
})
}),
),
`<div class="config-host-list" id="config-ob11-reverseWs-urls" ${ob11Config.reverseWs.enable ? '' : 'is-hidden'}>
<setting-item data-direction="row">
@@ -113,12 +114,12 @@ async function onSettingWindowCreated(view: Element) {
SettingItem(
' WebSocket 服务心跳间隔',
'控制每隔多久发送一个心跳包,单位为毫秒',
`<div class="q-input"><input class="q-input__inner" data-config-key="ob11.heartInterval" type="number" min="1000" value="${ob11Config.heartInterval}" placeholder="${ob11Config.heartInterval}" /></div>`
`<div class="q-input"><input class="q-input__inner" data-config-key="ob11.heartInterval" type="number" min="1000" value="${ob11Config.heartInterval}" placeholder="${ob11Config.heartInterval}" /></div>`,
),
SettingItem(
'Access token',
undefined,
`<div class="q-input" style="width:210px;"><input class="q-input__inner" data-config-key="ob11.token" type="text" value="${ob11Config.token}" placeholder="未设置" /></div>`
`<div class="q-input" style="width:210px;"><input class="q-input__inner" data-config-key="ob11.token" type="text" value="${ob11Config.token}" placeholder="未设置" /></div>`,
),
SettingItem(
'新消息上报格式',
@@ -129,21 +130,21 @@ async function onSettingWindowCreated(view: Element) {
{ text: 'CQ码', value: 'string' },
],
'ob11.messagePostFormat',
ob11Config.messagePostFormat
)
ob11Config.messagePostFormat,
),
),
SettingItem(
'音乐卡片签名地址',
undefined,
`<div class="q-input" style="width:210px;"><input class="q-input__inner" data-config-key="ob11.musicSignUrl" type="text" value="${ob11Config.musicSignUrl}" placeholder="未设置" /></div>`,
'ob11.musicSignUrl'
'ob11.musicSignUrl',
),
SettingItem(
'启用本地进群时间与发言时间记录',
undefined,
SettingSwitch('ob11.GroupLocalTime.Record', ob11Config.GroupLocalTime.Record, {
'control-display-id': 'config-ob11-GroupLocalTime-RecordList',
})
}),
),
`<div class="config-host-list" id="config-ob11-GroupLocalTime-RecordList" ${ob11Config.GroupLocalTime.Record ? '' : 'is-hidden'}>
<setting-item data-direction="row">
@@ -157,37 +158,37 @@ async function onSettingWindowCreated(view: Element) {
SettingItem(
'',
undefined,
SettingButton('保存', 'config-ob11-save', 'primary')
SettingButton('保存', 'config-ob11-save', 'primary'),
),
]),
SettingList([
SettingItem(
'上报 Bot 自身发送的消息',
'上报 event 为 message_sent',
SettingSwitch('ob11.reportSelfMessage', ob11Config.reportSelfMessage)
SettingSwitch('ob11.reportSelfMessage', ob11Config.reportSelfMessage),
),
]),
SettingList([
SettingItem(
'GitHub 仓库',
'https://github.com/NapNeko/NapCatQQ',
SettingButton('点个星星', 'open-github')
SettingButton('点个星星', 'open-github'),
),
SettingItem('NapCat 文档', '', SettingButton('看看文档', 'open-docs')),
SettingItem(
'Telegram 群',
'https://t.me/+nLZEnpne-pQ1OWFl',
SettingButton('进去逛逛', 'open-telegram')
SettingButton('进去逛逛', 'open-telegram'),
),
SettingItem(
'QQ 群',
'545402644',
SettingButton('我要进去', 'open-qq-group')
SettingButton('我要进去', 'open-qq-group'),
),
]),
'</div>',
].join(''),
'text/html'
'text/html',
);
// 外链按钮
@@ -208,7 +209,7 @@ async function onSettingWindowCreated(view: Element) {
type: string,
host: string,
index: number,
inputAttrs: any = {}
inputAttrs: any = {},
) => {
const dom = {
container: document.createElement('setting-item'),
@@ -224,7 +225,7 @@ async function onSettingWindowCreated(view: Element) {
dom.input.value = host;
dom.input.addEventListener('input', () => {
ob11Config[type.split('-')[0]][type.split('-')[1]][index] =
dom.input.value;
dom.input.value;
});
dom.inputContainer.classList.add('q-input');
@@ -245,7 +246,7 @@ async function onSettingWindowCreated(view: Element) {
const buildHostList = (
hosts: string[],
type: string,
inputAttr: any = {}
inputAttr: any = {},
) => {
const result: HTMLElement[] = [];
@@ -258,32 +259,32 @@ async function onSettingWindowCreated(view: Element) {
const addReverseHost = (
type: string,
doc: Document = document,
inputAttr: any = {}
inputAttr: any = {},
) => {
type = type.replace(/\./g, '-');//替换操作
const hostContainerDom = doc.body.querySelector(
`#config-ob11-${type}-list`
`#config-ob11-${type}-list`,
);
hostContainerDom?.appendChild(
buildHostListItem(
type,
'',
ob11Config[type.split('-')[0]][type.split('-')[1]].length,
inputAttr
)
inputAttr,
),
);
ob11Config[type.split('-')[0]][type.split('-')[1]].push('');
};
const initReverseHost = (type: string, doc: Document = document) => {
type = type.replace(/\./g, '-');//替换操作
const hostContainerDom = doc.body?.querySelector(
`#config-ob11-${type}-list`
`#config-ob11-${type}-list`,
);
if (hostContainerDom) {
[...hostContainerDom.childNodes].forEach((dom) => dom.remove());
buildHostList(
ob11Config[type.split('-')[0]][type.split('-')[1]],
type
type,
).forEach((dom) => {
hostContainerDom?.appendChild(dom);
});
@@ -299,7 +300,7 @@ async function onSettingWindowCreated(view: Element) {
?.addEventListener('click', () =>
addReverseHost('http.postUrls', document, {
placeholder: '如http://127.0.0.1:5140/onebot',
})
}),
);
doc
@@ -307,21 +308,21 @@ async function onSettingWindowCreated(view: Element) {
?.addEventListener('click', () =>
addReverseHost('reverseWs.urls', document, {
placeholder: '如ws://127.0.0.1:5140/onebot',
})
}),
);
doc
.querySelector('#config-ob11-GroupLocalTime-RecordList-add')
?.addEventListener('click', () =>
addReverseHost('GroupLocalTime.RecordList', document, {
placeholder: '此处填写群号 -1为全部',
})
}),
);
doc.querySelector('#config-ffmpeg-select')?.addEventListener('click', () => {
//选择ffmpeg
//选择ffmpeg
});
doc.querySelector('#config-open-log-path')?.addEventListener('click', () => {
//打开日志
//打开日志
});
// 开关
@@ -338,7 +339,7 @@ async function onSettingWindowCreated(view: Element) {
if (!isEmpty(dom.dataset.controlDisplayId)) {
const displayDom = document.querySelector(
//@ts-expect-error 等待修复
`#${dom.dataset.controlDisplayId}`
`#${dom.dataset.controlDisplayId}`,
);
if (active) displayDom?.removeAttribute('is-hidden');
else displayDom?.setAttribute('is-hidden', '');
@@ -349,7 +350,7 @@ async function onSettingWindowCreated(view: Element) {
// 输入框
doc
.querySelectorAll(
'setting-item .q-input input.q-input__inner[data-config-key]'
'setting-item .q-input input.q-input__inner[data-config-key]',
)
.forEach((dom: Element) => {
dom.addEventListener('input', () => {
@@ -357,11 +358,11 @@ async function onSettingWindowCreated(view: Element) {
//@ts-expect-error等待修复
const configKey = dom.dataset.configKey;
const configValue =
Type === 'number'
? parseInt((dom as HTMLInputElement).value) >= 1
? parseInt((dom as HTMLInputElement).value)
: 1
: (dom as HTMLInputElement).value;
Type === 'number'
? parseInt((dom as HTMLInputElement).value) >= 1
? parseInt((dom as HTMLInputElement).value)
: 1
: (dom as HTMLInputElement).value;
setOB11Config(configKey, configValue);
});
@@ -389,4 +390,5 @@ async function onSettingWindowCreated(view: Element) {
view.appendChild(node);
});
}
export { onSettingWindowCreated };

View File

@@ -1,7 +1,7 @@
import { SettingOption } from './SettingOption';
interface MouseEventExtend extends MouseEvent {
target: HTMLElement
target: HTMLElement;
}
// <ob-setting-select>
@@ -81,4 +81,4 @@ export const SettingSelect = (items: Array<{ text: string; value: string }>, con
})
.join('')}
</ob-setting-select>`;
};
};

View File

@@ -1,42 +1,45 @@
export interface OB11Config {
[key: string]: any;
http: {
enable: boolean;
host: '';
port: number;
secret: '';
enableHeart: boolean;
enablePost: boolean;
postUrls: string[];
};
ws: {
enable: boolean;
host: '';
port: number;
};
reverseWs: {
enable: boolean;
urls: string[];
};
GroupLocalTime: {
Record: boolean,
RecordList: Array<string>
};
debug: boolean;
heartInterval: number;
messagePostFormat: 'array' | 'string';
enableLocalFile2Url: boolean;
musicSignUrl: '';
reportSelfMessage: boolean;
token: '';
[key: string]: any;
http: {
enable: boolean;
host: '';
port: number;
secret: '';
enableHeart: boolean;
enablePost: boolean;
postUrls: string[];
};
ws: {
enable: boolean;
host: '';
port: number;
};
reverseWs: {
enable: boolean;
urls: string[];
};
GroupLocalTime: {
Record: boolean,
RecordList: Array<string>
};
debug: boolean;
heartInterval: number;
messagePostFormat: 'array' | 'string';
enableLocalFile2Url: boolean;
musicSignUrl: '';
reportSelfMessage: boolean;
token: '';
}
class WebUiApiOB11ConfigWrapper {
private retCredential: string = '';
async Init(Credential: string) {
this.retCredential = Credential;
}
async GetOB11Config(): Promise<OB11Config> {
const ConfigResponse = await fetch('../api/OB11Config/GetConfig', {
method: 'POST',
@@ -53,6 +56,7 @@ class WebUiApiOB11ConfigWrapper {
}
return {} as OB11Config;
}
async SetOB11Config(config: OB11Config): Promise<boolean> {
const ConfigResponse = await fetch('../api/OB11Config/SetConfig', {
method: 'POST',
@@ -71,4 +75,5 @@ class WebUiApiOB11ConfigWrapper {
return false;
}
}
export const OB11ConfigWrapper = new WebUiApiOB11ConfigWrapper();

View File

@@ -1,13 +1,13 @@
import { defineConfig } from 'vite';
export default defineConfig({
build:{
build: {
target: 'esnext',
minify: false,
lib: {
entry: 'ui/NapCat.ts',
formats: ['es'],
fileName: () => 'renderer.js',
}
}
});
},
},
});

View File

@@ -4,5 +4,4 @@
"prefix": "",
"token": "random",
"loginRate": 3
}
}