Compare commits

...

2 Commits

2 changed files with 35 additions and 9 deletions

3
src/oss/blackapi.json Normal file
View File

@ -0,0 +1,3 @@
[
]

View File

@ -47,6 +47,12 @@ export async function createWs() {
G.argv.serverType == 'msg' && G.config.corssWsUrl && await createWsClient();
}
/**每分钟刷新一次黑名单API接口 */
setInterval(()=>{
getBlackList();
},60000);
getBlackList();
}
function getWssFile() {
@ -63,6 +69,21 @@ function getWssFile() {
}
const writeList = ['hongdian/Get']
/**当前锁定的API接口 */
let blackApi = [];
async function getBlackList(){
let confFile = resolve(__dirname, 'oss/blackapi.json');
if (existsSync(confFile)) {
try {
blackApi = await JSON.parse(readFileSync(confFile, 'utf-8'));
} catch (e) {
blackApi = [];
}
}else{
blackApi = [];
}
}
function setWs(server: WsServer<ServiceType>) {
@ -101,15 +122,17 @@ function setWs(server: WsServer<ServiceType>) {
//执行 API 接口实现之前
server.flows.preApiCallFlow.push(async call => {
// 临时停服维护方案
// let lng = {
// "zh-TW": "停服維護中,請等待!",
// "ko": "서버 점검 중, 잠시만 기다려 주세요.",
// "ja": "サーバーメンテナンス中、しばらくお待ちください。",
// "en": "Server under maintenance. Please wait.",
// }
// call.error("", {code: -1, message: lng[call.req.lng] || lng["ja"]})
// return null;
//判断是否是被关闭的API
if (blackApi.includes(call.service.name) || blackApi.includes("all")) {
let lng = {
"zh-TW": "維護中,請等待",
"ko": "유지 보수 중, 대기 중",
"ja": "メンテナンス中ですので、お待ちください",
"en": "Maintenance in progress, please wait",
}
call.error("", {code: -1, message: lng[call.req.lng] || lng["ja"]})
return null;
}
//是否短时间内重复请求某个api
// let timeIntervalLimit = call.service.conf?.timeIntervalLimit == undefined ? 500 : call.service.conf?.timeIntervalLimit;