From 83d0a84a6d5da716e272e2310814c5197aaf9ece Mon Sep 17 00:00:00 2001 From: ThinaticSystem Date: Sat, 18 Jun 2022 21:53:05 +0900 Subject: [PATCH] =?UTF-8?q?=E3=81=A8=E3=82=8A=E3=81=82=E3=81=88=E3=81=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/client/src/scripts/aiscript/api.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/client/src/scripts/aiscript/api.ts b/packages/client/src/scripts/aiscript/api.ts index 01b8fd05f..36dc9ee25 100644 --- a/packages/client/src/scripts/aiscript/api.ts +++ b/packages/client/src/scripts/aiscript/api.ts @@ -30,6 +30,23 @@ export function createAiScriptEnv(opts) { const res = await os.api(ep.value, utils.valToJs(param), token ? token.value : (opts.token || null)); return utils.jsToVal(res); }), + 'Mk:restApi': values.FN_NATIVE(async ([url, method, body, headers]) => { + utils.assertString(url); + utils.assertString(method); + utils.assertString(body); + utils.assertObject(headers); + + const typedHeaders = new Headers(); + headers.value.forEach((value, key) => { + typedHeaders.set(key, utils.valToString(value)); + }); + const response = await fetch(url.value, { + method: method.value, + headers: typedHeaders, + body: body.value, + }); + return utils.jsToVal(response.json()); + }), 'Mk:save': values.FN_NATIVE(([key, value]) => { utils.assertString(key); localStorage.setItem('aiscript:' + opts.storageKey + ':' + key.value, JSON.stringify(utils.valToJs(value)));