From 24d802626c5cf8f763f463b1d598227454d8e1e3 Mon Sep 17 00:00:00 2001 From: enncy <877526278@qq.com> Date: Wed, 13 Dec 2023 15:08:01 +0800 Subject: [PATCH] =?UTF-8?q?perf(script):=20=E6=B7=BB=E5=8A=A0=20TikuAdapte?= =?UTF-8?q?r=20=E9=85=8D=E7=BD=AE=E5=9F=9F=E5=90=8D=E7=99=BD=E5=90=8D?= =?UTF-8?q?=E5=8D=95=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/scripts/src/projects/common.ts | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/packages/scripts/src/projects/common.ts b/packages/scripts/src/projects/common.ts index da4806ea..02f7e171 100644 --- a/packages/scripts/src/projects/common.ts +++ b/packages/scripts/src/projects/common.ts @@ -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题库', @@ -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: '题库配置不能为空,请重新配置。' });