Skip to content

Commit

Permalink
perf(script): 添加 TikuAdapter 配置域名白名单提示
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed Dec 13, 2023
1 parent 017b3e2 commit 24d8026
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions packages/scripts/src/projects/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,22 @@ export const CommonProject = Project.create({
el('button', '确定', (btn) => {
btn.className = 'modal-confirm-button';
btn.onclick = async () => {
// @ts-ignore
const connects: string[] = $gm.getInfos()?.script.connects;

const value = textarea.value;

if (value) {
try {
const awsResult: AnswererWrapper[] = [];
if (select.value === 'TikuAdapter') {
if (value.startsWith('http') === false) {
$modal('alert', {
content:
'格式错误,TikuAdapter解析器只能解析 url 链接,请重新输入!或者查看 https://github.com/DokiDoki1103/tikuAdapter 文档说明'
});
return;
}
select.value = '默认';
awsResult.push({
name: 'TikuAdapter题库',
Expand Down Expand Up @@ -276,6 +286,42 @@ export const CommonProject = Project.create({
])
});

// 检测是否有域名白名单
const notAllowed: string[] = [];
console.log(connects);

for (const aw of awsResult) {
if (
connects.some((connect) => new URL(aw.url).hostname.includes(connect)) === false
) {
notAllowed.push(aw.url);
}
}
if (notAllowed.length) {
$modal('alert', {
width: 600,
maskCloseable: false,
title: '⚠️警告',
content: el('div', [
el('div', [
'配置成功,但检测到以下 域名/ip 不在脚本的白名单中,请安装 : ',
el(
'a',
{
href: 'https://docs.ocsjs.com/docs/other/api#全域名通用版本'
},
'OCS全域名通用版本'
),
',或者手动添加 @connect ,否则无法进行请求。',
el(
'ul',
notAllowed.map((url) => el('li', new URL(url).hostname))
)
])
])
});
}

textarea.value = JSON.stringify(awsResult, null, 4);
} else {
$modal('alert', { content: '题库配置不能为空,请重新配置。' });
Expand Down

0 comments on commit 24d8026

Please sign in to comment.