オプションをオブジェクトで受けるように
This commit is contained in:
parent
3fbfd1a145
commit
b7f2b6c322
@ -39,27 +39,16 @@ export function createAiScriptEnv(opts) {
|
|||||||
utils.assertString(key);
|
utils.assertString(key);
|
||||||
return utils.jsToVal(JSON.parse(localStorage.getItem('aiscript:' + opts.storageKey + ':' + key.value)));
|
return utils.jsToVal(JSON.parse(localStorage.getItem('aiscript:' + opts.storageKey + ':' + key.value)));
|
||||||
}),
|
}),
|
||||||
'Mk:fetch': values.FN_NATIVE(async ([url, method, body, headers]) => {
|
'Mk:fetch': values.FN_NATIVE(async ([resource, init]) => {
|
||||||
const init: {method?: string, body?: string, headers?: Headers} = new Object();
|
utils.assertString(resource);
|
||||||
utils.assertString(url);
|
const response = await (async () => {
|
||||||
if (method) {
|
if (init) {
|
||||||
utils.assertString(method);
|
utils.assertObject(init);
|
||||||
init.method = method.value;
|
return await fetch(resource.value, utils.valToJs(init));
|
||||||
}
|
} else {
|
||||||
if (body) {
|
return await fetch(resource.value);
|
||||||
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);
|
|
||||||
|
|
||||||
// Parsing Section
|
// Parsing Section
|
||||||
const contentType = response.headers.get('Content-Type');
|
const contentType = response.headers.get('Content-Type');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user