From b7f2b6c322141e788643ed1bad9eb376ea000b20 Mon Sep 17 00:00:00 2001 From: ThinaticSystem Date: Sun, 19 Jun 2022 20:52:46 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=AA=E3=83=97=E3=82=B7=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E3=82=92=E3=82=AA=E3=83=96=E3=82=B8=E3=82=A7=E3=82=AF=E3=83=88?= =?UTF-8?q?=E3=81=A7=E5=8F=97=E3=81=91=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/client/src/scripts/aiscript/api.ts | 31 +++++++-------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/packages/client/src/scripts/aiscript/api.ts b/packages/client/src/scripts/aiscript/api.ts index cc309ab4f..784f60bbe 100644 --- a/packages/client/src/scripts/aiscript/api.ts +++ b/packages/client/src/scripts/aiscript/api.ts @@ -39,27 +39,16 @@ export function createAiScriptEnv(opts) { utils.assertString(key); return utils.jsToVal(JSON.parse(localStorage.getItem('aiscript:' + opts.storageKey + ':' + key.value))); }), - 'Mk:fetch': values.FN_NATIVE(async ([url, method, body, headers]) => { - const init: {method?: string, body?: string, headers?: Headers} = new Object(); - utils.assertString(url); - if (method) { - utils.assertString(method); - init.method = method.value; - } - if (body) { - utils.assertString(body); - init.body = body.value; - } - if (headers) { - utils.assertObject(headers); - const typedHeaders = new Headers(); - headers.value.forEach((value, key) => { - typedHeaders.set(key, utils.valToString(value)); - }); - init.headers = typedHeaders; - } - - const response = await fetch(url.value, init); + 'Mk:fetch': values.FN_NATIVE(async ([resource, init]) => { + utils.assertString(resource); + const response = await (async () => { + if (init) { + utils.assertObject(init); + return await fetch(resource.value, utils.valToJs(init)); + } else { + return await fetch(resource.value); + } + })(); // Parsing Section const contentType = response.headers.get('Content-Type');