From 30b231225c85abd269c005153167e6827bfc7921 Mon Sep 17 00:00:00 2001 From: FineArchs <133759614+FineArchs@users.noreply.github.com> Date: Sun, 24 Sep 2023 14:41:41 +0900 Subject: [PATCH] =?UTF-8?q?Mk:api=E3=81=A7=E5=A4=96=E9=83=A8=E3=82=B5?= =?UTF-8?q?=E3=83=BC=E3=83=90=E3=83=BC=E3=81=A8=E3=81=AE=E6=8E=A5=E7=B6=9A?= =?UTF-8?q?=E3=82=92=E7=A6=81=E6=AD=A2=20(#11883)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Mk:url(): no automatic token attaching when ep is url * Limit requests to external servers by Mk:api * remove unused import * Update CHANGELOG.md * Update packages/frontend/src/scripts/aiscript/api.ts Co-authored-by: syuilo --------- Co-authored-by: syuilo --- CHANGELOG.md | 1 + packages/frontend/src/scripts/aiscript/api.ts | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3e2053f2e..a0c5ea293d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -86,6 +86,7 @@ - Fix: 複数の階層があるメニューで、短くタップすると正常に動かない場合がある問題を修正 - Fix: アニメーションがオフのとき、スマホで子メニューの選択ができない問題を修正 - Fix: ドロワーメニューで、親メニュー項目をマウスでホバーすると子メニューが表示されてしまう問題を修正 +- Fix: AiScriptでMk:apiが外部と通信できる問題を修正 ### Server - Change: cacheRemoteFilesの初期値はfalseになりました diff --git a/packages/frontend/src/scripts/aiscript/api.ts b/packages/frontend/src/scripts/aiscript/api.ts index 0bb9185936..9f60e52cea 100644 --- a/packages/frontend/src/scripts/aiscript/api.ts +++ b/packages/frontend/src/scripts/aiscript/api.ts @@ -34,12 +34,15 @@ export function createAiScriptEnv(opts) { return confirm.canceled ? values.FALSE : values.TRUE; }), 'Mk:api': values.FN_NATIVE(async ([ep, param, token]) => { + utils.assertString(ep); + if (ep.value.includes('://')) throw new Error('invalid endpoint'); if (token) { utils.assertString(token); // バグがあればundefinedもあり得るため念のため if (typeof token.value !== 'string') throw new Error('invalid token'); } - return os.api(ep.value, utils.valToJs(param), token ? token.value : (opts.token ?? null)).then(res => { + const actualToken: string|null = token?.value ?? opts.token ?? null; + return os.api(ep.value, utils.valToJs(param), actualToken).then(res => { return utils.jsToVal(res); }, err => { return values.ERROR('request_failed', utils.jsToVal(err));