From eb5c22d0b24012800fde19fba38d1e8d95bcc89c Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 9 Jan 2023 17:33:29 +0000 Subject: [PATCH] :v: --- packages/frontend/src/scripts/api.ts | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/frontend/src/scripts/api.ts b/packages/frontend/src/scripts/api.ts index a9ae821d27..82b1ba3cea 100644 --- a/packages/frontend/src/scripts/api.ts +++ b/packages/frontend/src/scripts/api.ts @@ -1,21 +1,18 @@ -import * as Misskey from 'misskey-js'; +import { Endpoints } from 'misskey-js/built/api.types'; import { ref } from 'vue'; -import { apiUrl, url } from '@/config'; +import { apiUrl } from '@/config'; import { $i } from '@/account'; export const pendingApiRequestsCount = ref(0); -const apiClient = new Misskey.api.APIClient({ - origin: url, -}); - -export const api = ((endpoint: string, data: Record = {}, token?: string | null | undefined) => { +// Implements Misskey.api.ApiClient.request +export function api(endpoint: E, data: P = {} as any, token?: string | null | undefined): Promise { pendingApiRequestsCount.value++; const onFinally = () => { pendingApiRequestsCount.value--; }; - const promise = new Promise((resolve, reject) => { + const promise = new Promise((resolve, reject) => { // Append a credential if ($i) (data as any).i = $i.token; if (token !== undefined) (data as any).i = token; @@ -45,18 +42,19 @@ export const api = ((endpoint: string, data: Record = {}, token?: s promise.then(onFinally, onFinally); return promise; -}) as typeof apiClient.request; +}; -export const apiGet = ((endpoint: string, data: Record = {}) => { +// Implements Misskey.api.ApiClient.request +export function apiGet(endpoint: E, data: P = {} as any): Promise { pendingApiRequestsCount.value++; const onFinally = () => { pendingApiRequestsCount.value--; }; - const query = new URLSearchParams(data); + const query = new URLSearchParams(data as any); - const promise = new Promise((resolve, reject) => { + const promise = new Promise((resolve, reject) => { // Send request window.fetch(`${apiUrl}/${endpoint}?${query}`, { method: 'GET', @@ -78,4 +76,4 @@ export const apiGet = ((endpoint: string, data: Record = {}) => { promise.then(onFinally, onFinally); return promise; -}) as typeof apiClient.request; +};