feat: support null for Mk:api() token argument
This commit is contained in:
parent
f748c9144c
commit
8a3a42109c
|
|
@ -35,11 +35,13 @@ export function createAiScriptEnv(opts) {
|
||||||
}),
|
}),
|
||||||
'Mk:api': values.FN_NATIVE(async ([ep, param, token]) => {
|
'Mk:api': values.FN_NATIVE(async ([ep, param, token]) => {
|
||||||
if (token) {
|
if (token) {
|
||||||
utils.assertString(token);
|
if (token.type !== 'null') {
|
||||||
// バグがあればundefinedもあり得るため念のため
|
utils.assertString(token);
|
||||||
if (typeof token.value !== 'string') throw new Error('invalid 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 => {
|
return os.api(ep.value, utils.valToJs(param), (token ? token.value : opts.token) ?? null).then(res => {
|
||||||
return utils.jsToVal(res);
|
return utils.jsToVal(res);
|
||||||
}, err => {
|
}, err => {
|
||||||
return values.ERROR('request_failed', utils.jsToVal(err));
|
return values.ERROR('request_failed', utils.jsToVal(err));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue