Skip to content

Commit

Permalink
feat: support null for Mk:api() token argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Sayamame-beans committed Sep 22, 2023
1 parent f748c91 commit 8a3a421
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/frontend/src/scripts/aiscript/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ export function createAiScriptEnv(opts) {
}),
'Mk:api': values.FN_NATIVE(async ([ep, param, token]) => {
if (token) {
utils.assertString(token);
// バグがあればundefinedもあり得るため念のため
if (typeof token.value !== 'string') throw new Error('invalid token');
if (token.type !== 'null') {
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 => {
return os.api(ep.value, utils.valToJs(param), (token ? token.value : opts.token) ?? null).then(res => {
return utils.jsToVal(res);
}, err => {
return values.ERROR('request_failed', utils.jsToVal(err));
Expand Down

0 comments on commit 8a3a421

Please sign in to comment.