feat: 重构解析黑名单 && 锅巴配置文件添加解析黑名单

This commit is contained in:
zhiyu1998 2024-12-04 14:06:33 +08:00
parent a93c8b7bf6
commit ae4e134fc0
3 changed files with 33 additions and 10 deletions

View File

@ -239,6 +239,8 @@ export class tools extends plugin {
this.defaultPath = this.toolsConfig.defaultPath; this.defaultPath = this.toolsConfig.defaultPath;
// 视频限制大小 // 视频限制大小
this.videoSizeLimit = this.toolsConfig.videoSizeLimit; this.videoSizeLimit = this.toolsConfig.videoSizeLimit;
// 获取全局禁用的解析
this.globalBlackList = this.toolsConfig.globalBlackList;
// 魔法接口 // 魔法接口
this.proxyAddr = this.toolsConfig.proxyAddr; this.proxyAddr = this.toolsConfig.proxyAddr;
this.proxyPort = this.toolsConfig.proxyPort; this.proxyPort = this.toolsConfig.proxyPort;
@ -3125,18 +3127,15 @@ export class tools extends plugin {
* @returns {Promise<boolean>} * @returns {Promise<boolean>}
*/ */
async isEnableResolve(resolveName) { async isEnableResolve(resolveName) {
const controller = await redisExistAndGetKey(REDIS_YUNZAI_RESOLVE_CONTROLLER); const controller = this.globalBlackList;
// 如果不存在说明用户没有启动过webui,那么直接放行 // 如果不存在,那么直接放行
if (controller == null) { if (controller == null) {
return true; return true;
} }
const foundItem = controller.find(item => item.label === resolveName); // 找到禁用列表中是否包含 `resolveName`
// 未知解析,可能是写错,放行 const foundItem = controller.find(item => item === resolveName);
if (!foundItem) { // 如果 undefined 说明不在禁用列表就放行
logger.warn(`[R插件][启用解析] 未知解析,可能存在写错`); return foundItem === undefined;
return true;
}
return foundItem.value === 1;
} }
/** /**

View File

@ -1,3 +1,5 @@
globalBlackList: [] # 全局白名单解析
defaultPath: './data/rcmp4/' # 保存视频的位置 defaultPath: './data/rcmp4/' # 保存视频的位置
videoSizeLimit: 70 # 视频大小限制单位MB超过大小则转换成群文件上传 videoSizeLimit: 70 # 视频大小限制单位MB超过大小则转换成群文件上传
proxyAddr: '127.0.0.1' # 魔法地址 proxyAddr: '127.0.0.1' # 魔法地址

View File

@ -1,12 +1,15 @@
import _ from "lodash"; import _ from "lodash";
import path from "path"; import path from "path";
import { BILI_CDN_SELECT_LIST, BILI_DOWNLOAD_METHOD, BILI_RESOLUTION_LIST, YOUTUBE_GRAPHICS_LIST, NETEASECLOUD_QUALITY_LIST } from "./constants/constant.js"; import { BILI_CDN_SELECT_LIST, BILI_DOWNLOAD_METHOD, BILI_RESOLUTION_LIST, YOUTUBE_GRAPHICS_LIST, NETEASECLOUD_QUALITY_LIST } from "./constants/constant.js";
import { RESOLVE_CONTROLLER_NAME_ENUM } from "./constants/resolve.js";
import model from "./model/config.js"; import model from "./model/config.js";
const pluginName = `rconsole-plugin`; const pluginName = `rconsole-plugin`;
const _path = process.cwd() + `/plugins/${pluginName}`; const _path = process.cwd() + `/plugins/${pluginName}`;
export function supportGuoba() { export function supportGuoba() {
let globalWhitelist = Object.values(RESOLVE_CONTROLLER_NAME_ENUM).map(value => ({ value }));
const globalWhitelistComponent = globalWhitelist.length === 0 ? 'GTags' : 'Select'
return { return {
pluginInfo: { pluginInfo: {
name: "R插件", name: "R插件",
@ -29,6 +32,18 @@ export function supportGuoba() {
}, },
configInfo: { configInfo: {
schemas: [ schemas: [
{
field: 'tools.globalBlackList',
label: '全局解析黑名单',
component: globalWhitelistComponent,
bottomHelpMessage: '添加后将全局禁用',
componentProps: {
allowAdd: true,
allowDel: true,
mode: 'multiple',
options: globalWhitelist,
},
},
{ {
field: "tools.proxyAddr", field: "tools.proxyAddr",
label: "魔法地址", label: "魔法地址",
@ -428,10 +443,17 @@ export function supportGuoba() {
}, },
setConfigData(data, { Result }) { setConfigData(data, { Result }) {
let config = {}; let config = {};
let cfg = model.getConfig("tools");
for (let [key, value] of Object.entries(data)) { for (let [key, value] of Object.entries(data)) {
// 特殊处理这个,需要全覆盖
if (key === "tools.globalBlackList") {
_.set(cfg, "globalBlackList", value);
}
_.set(config, key, value); _.set(config, key, value);
} }
config = _.merge({}, model.getConfig("tools"), config.tools); // 合并配置项
config = _.merge({}, cfg, config.tools);
// 保存
model.saveAllConfig("tools", config); model.saveAllConfig("tools", config);
return Result.ok({}, "保存成功~"); return Result.ok({}, "保存成功~");
}, },