From 3c796054603e533990a7e1dbeeaba251af1fe598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BE=E3=81=A3=E3=81=A1=E3=82=83=E3=81=A8=E3=83=BC?= =?UTF-8?q?=E3=81=AB=E3=82=85?= <17376330+u1-liquid@users.noreply.github.com> Date: Fri, 8 Dec 2023 17:47:54 +0900 Subject: [PATCH] =?UTF-8?q?Revert=20"Feat:=20AiScript=E3=81=A7=E3=83=AA?= =?UTF-8?q?=E3=83=A2=E3=83=BC=E3=83=88=E3=82=B5=E3=83=BC=E3=83=90=E3=83=BC?= =?UTF-8?q?=E3=81=AEAPI=E3=82=92=E5=8F=A9=E3=81=8F=E9=96=A2=E6=95=B0?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0=20(#11887)"=20(MisskeyIO#281)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Revert "Feat: AiScriptでリモートサーバーのAPIを叩く関数を追加 (#11887)" This reverts commit f269841a83002daf6743f8ed2c173da66a662618. --- packages/frontend/src/os.ts | 4 +- packages/frontend/src/scripts/aiscript/api.ts | 10 ----- packages/frontend/src/scripts/api.ts | 43 ------------------- 3 files changed, 2 insertions(+), 55 deletions(-) diff --git a/packages/frontend/src/os.ts b/packages/frontend/src/os.ts index 58976b3eb8..48861192b9 100644 --- a/packages/frontend/src/os.ts +++ b/packages/frontend/src/os.ts @@ -5,8 +5,8 @@ // TODO: なんでもかんでもos.tsに突っ込むのやめたいのでよしなに分割する -import { pendingApiRequestsCount, api, apiExternal, apiGet } from '@/scripts/api.js'; -export { pendingApiRequestsCount, api, apiExternal, apiGet }; +import { pendingApiRequestsCount, api, apiGet } from '@/scripts/api.js'; +export { pendingApiRequestsCount, api, apiGet }; import { Component, markRaw, Ref, ref, defineAsyncComponent } from 'vue'; import { EventEmitter } from 'eventemitter3'; import insertTextAtCursor from 'insert-text-at-cursor'; diff --git a/packages/frontend/src/scripts/aiscript/api.ts b/packages/frontend/src/scripts/aiscript/api.ts index fb7ab924b7..20f37ae0c2 100644 --- a/packages/frontend/src/scripts/aiscript/api.ts +++ b/packages/frontend/src/scripts/aiscript/api.ts @@ -50,16 +50,6 @@ export function createAiScriptEnv(opts) { 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); miLocalStorage.setItem(`aiscript:${opts.storageKey}:${key.value}`, JSON.stringify(utils.valToJs(value))); diff --git a/packages/frontend/src/scripts/api.ts b/packages/frontend/src/scripts/api.ts index 080977e5e4..d7fd0b374f 100644 --- a/packages/frontend/src/scripts/api.ts +++ b/packages/frontend/src/scripts/api.ts @@ -51,49 +51,6 @@ export function api(hostUrl: string, endpoint: E, data: P = {} as any, token?: string | null | undefined, signal?: AbortSignal): Promise { - if (!/^https?:\/\//.test(hostUrl)) throw new Error('invalid host name'); - if (endpoint.includes('://')) throw new Error('invalid endpoint'); - pendingApiRequestsCount.value++; - - const onFinally = () => { - pendingApiRequestsCount.value--; - }; - - const promise = new Promise((resolve, reject) => { - // Append a credential - (data as any).i = token; - - const fullUrl = (hostUrl.slice(-1) === '/' ? hostUrl.slice(0, -1) : hostUrl) - + '/api/' + (endpoint.slice(0, 1) === '/' ? endpoint.slice(1) : endpoint); - // Send request - window.fetch(fullUrl, { - method: 'POST', - body: JSON.stringify(data), - credentials: 'omit', - cache: 'no-cache', - headers: { - 'Content-Type': 'application/json', - }, - signal, - }).then(async (res) => { - const body = res.status === 204 ? null : await res.json(); - - if (res.status === 200) { - resolve(body); - } else if (res.status === 204) { - resolve(); - } else { - reject(body.error); - } - }).catch(reject); - }); - - promise.then(onFinally, onFinally); - - return promise; -} - // Implements Misskey.api.ApiClient.request export function apiGet (endpoint: E, data: P = {} as any): Promise { pendingApiRequestsCount.value++;