mirror of
https://github.com/misskey-dev/misskey.git
synced 2025-03-16 09:55:16 +09:00

* wip * bump misskey-dev/eslint-plugin * lint fixes (backend) * lint fixes (frontend) * lint fixes (frontend-embed) * rollback nsfwjs to 4.2.0 ref: infinitered/nsfwjs#904 * rollback openapi-typescript to v6 v7でOpenAPIのバリデーションが入るようになった関係でスコープ外での変更が避けられないため一時的に戻した * lint fixes (misskey-js) * temporarily disable errored lint rule (frontend-shared) * fix lint * temporarily ignore errored file for lint (frontend-shared) * rollback simplewebauthn/server to 12.0.0 v13 contains breaking changes that require some decision making * lint fixes (frontend-shared) * build misskey-js with types * fix(backend): migrate simplewebauthn/server to v12 * fix(misskey-js/autogen): ignore indent rules to generate consistent output * attempt to fix test changes due to capricorn86/happy-dom#1617 (XMLSerializer now produces valid XML) * attempt to fix test changes due to capricorn86/happy-dom#1617 (XMLSerializer now produces valid XML) * fix test * fix test * fix test * Apply suggestions from code review Co-authored-by: anatawa12 <anatawa12@icloud.com> * bump summaly to v5.2.0 * update tabler-icons to v3.30.0-based --------- Co-authored-by: かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com> Co-authored-by: anatawa12 <anatawa12@icloud.com>
126 lines
3.9 KiB
TypeScript
126 lines
3.9 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { errors, utils, values } from '@syuilo/aiscript';
|
|
import * as Misskey from 'misskey-js';
|
|
import { url, lang } from '@@/js/config.js';
|
|
import { assertStringAndIsIn } from './common.js';
|
|
import * as os from '@/os.js';
|
|
import { misskeyApi } from '@/scripts/misskey-api.js';
|
|
import { $i } from '@/account.js';
|
|
import { miLocalStorage } from '@/local-storage.js';
|
|
import { customEmojis } from '@/custom-emojis.js';
|
|
|
|
const DIALOG_TYPES = [
|
|
'error',
|
|
'info',
|
|
'success',
|
|
'warning',
|
|
'waiting',
|
|
'question',
|
|
] as const;
|
|
|
|
export function aiScriptReadline(q: string): Promise<string> {
|
|
return new Promise(ok => {
|
|
os.inputText({
|
|
title: q,
|
|
}).then(({ result: a }) => {
|
|
ok(a ?? '');
|
|
});
|
|
});
|
|
}
|
|
|
|
export function createAiScriptEnv(opts: { storageKey: string, token?: string }) {
|
|
return {
|
|
USER_ID: $i ? values.STR($i.id) : values.NULL,
|
|
USER_NAME: $i?.name ? values.STR($i.name) : values.NULL,
|
|
USER_USERNAME: $i ? values.STR($i.username) : values.NULL,
|
|
CUSTOM_EMOJIS: utils.jsToVal(customEmojis.value),
|
|
LOCALE: values.STR(lang),
|
|
SERVER_URL: values.STR(url),
|
|
'Mk:dialog': values.FN_NATIVE(async ([title, text, type]) => {
|
|
utils.assertString(title);
|
|
utils.assertString(text);
|
|
if (type != null) {
|
|
assertStringAndIsIn(type, DIALOG_TYPES);
|
|
}
|
|
await os.alert({
|
|
type: type ? type.value : 'info',
|
|
title: title.value,
|
|
text: text.value,
|
|
});
|
|
return values.NULL;
|
|
}),
|
|
'Mk:confirm': values.FN_NATIVE(async ([title, text, type]) => {
|
|
utils.assertString(title);
|
|
utils.assertString(text);
|
|
if (type != null) {
|
|
assertStringAndIsIn(type, DIALOG_TYPES);
|
|
}
|
|
const confirm = await os.confirm({
|
|
type: type ? type.value : 'question',
|
|
title: title.value,
|
|
text: text.value,
|
|
});
|
|
return confirm.canceled ? values.FALSE : values.TRUE;
|
|
}),
|
|
'Mk:api': values.FN_NATIVE(async ([ep, param, token]) => {
|
|
utils.assertString(ep);
|
|
if (ep.value.includes('://')) {
|
|
throw new errors.AiScriptRuntimeError('invalid endpoint');
|
|
}
|
|
if (token) {
|
|
utils.assertString(token);
|
|
// バグがあればundefinedもあり得るため念のため
|
|
if (typeof token.value !== 'string') throw new Error('invalid token');
|
|
}
|
|
const actualToken: string | null = token?.value ?? opts.token ?? null;
|
|
if (param == null) {
|
|
throw new errors.AiScriptRuntimeError('expected param');
|
|
}
|
|
utils.assertObject(param);
|
|
return misskeyApi(ep.value, utils.valToJs(param) as object, actualToken).then(res => {
|
|
return utils.jsToVal(res);
|
|
}, err => {
|
|
return values.ERROR('request_failed', utils.jsToVal(err));
|
|
});
|
|
}),
|
|
/* セキュリティ上の問題があるため無効化
|
|
'Mk:apiExternal': values.FN_NATIVE(async ([host, ep, param, token]) => {
|
|
utils.assertString(host);
|
|
utils.assertString(ep);
|
|
if (token) utils.assertString(token);
|
|
return os.apiExternal(host.value, ep.value, utils.valToJs(param), token?.value).then(res => {
|
|
return utils.jsToVal(res);
|
|
}, err => {
|
|
return values.ERROR('request_failed', utils.jsToVal(err));
|
|
});
|
|
}),
|
|
*/
|
|
'Mk:save': values.FN_NATIVE(([key, value]) => {
|
|
utils.assertString(key);
|
|
utils.expectAny(value);
|
|
miLocalStorage.setItem(`aiscript:${opts.storageKey}:${key.value}`, JSON.stringify(utils.valToJs(value)));
|
|
return values.NULL;
|
|
}),
|
|
'Mk:load': values.FN_NATIVE(([key]) => {
|
|
utils.assertString(key);
|
|
return utils.jsToVal(miLocalStorage.getItemAsJson(`aiscript:${opts.storageKey}:${key.value}`) ?? null);
|
|
}),
|
|
'Mk:remove': values.FN_NATIVE(([key]) => {
|
|
utils.assertString(key);
|
|
miLocalStorage.removeItem(`aiscript:${opts.storageKey}:${key.value}`);
|
|
return values.NULL;
|
|
}),
|
|
'Mk:url': values.FN_NATIVE(() => {
|
|
return values.STR(window.location.href);
|
|
}),
|
|
'Mk:nyaize': values.FN_NATIVE(([text]) => {
|
|
utils.assertString(text);
|
|
return values.STR(Misskey.nyaize(text.value));
|
|
}),
|
|
};
|
|
}
|