This commit is contained in:
syuilo
2023-09-20 16:44:12 +09:00
parent b9c6992aac
commit 8e2d47b2e8
5 changed files with 13 additions and 11 deletions

View File

@@ -3,21 +3,21 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { Endpoints } from 'misskey-js/built/api.types';
import * as Misskey from 'misskey-js';
import { ref } from 'vue';
import { apiUrl } from '@/config.js';
import { $i } from '@/account.js';
export const pendingApiRequestsCount = ref(0);
// Implements Misskey.api.ApiClient.request
export function api<E extends keyof Endpoints, P extends Endpoints[E]['req']>(endpoint: E, data: P = {} as any, token?: string | null | undefined, signal?: AbortSignal): Promise<Endpoints[E]['res']> {
export function api<E extends keyof Misskey.Endpoints, P extends Misskey.Endpoints[E]['req']>(endpoint: E, data: P = {} as any, token?: string | null | undefined, signal?: AbortSignal): Promise<Misskey.Endpoints[E]['res']> {
pendingApiRequestsCount.value++;
const onFinally = () => {
pendingApiRequestsCount.value--;
};
const promise = new Promise<Endpoints[E]['res'] | void>((resolve, reject) => {
const promise = new Promise<Misskey.Endpoints[E]['res'] | void>((resolve, reject) => {
// Append a credential
if ($i) (data as any).i = $i.token;
if (token !== undefined) (data as any).i = token;
@@ -51,7 +51,7 @@ export function api<E extends keyof Endpoints, P extends Endpoints[E]['req']>(en
}
// Implements Misskey.api.ApiClient.request
export function apiGet <E extends keyof Endpoints, P extends Endpoints[E]['req']>(endpoint: E, data: P = {} as any): Promise<Endpoints[E]['res']> {
export function apiGet <E extends keyof Misskey.Endpoints, P extends Misskey.Endpoints[E]['req']>(endpoint: E, data: P = {} as any): Promise<Misskey.Endpoints[E]['res']> {
pendingApiRequestsCount.value++;
const onFinally = () => {
@@ -60,7 +60,7 @@ export function apiGet <E extends keyof Endpoints, P extends Endpoints[E]['req']
const query = new URLSearchParams(data as any);
const promise = new Promise<Endpoints[E]['res'] | void>((resolve, reject) => {
const promise = new Promise<Misskey.Endpoints[E]['res'] | void>((resolve, reject) => {
// Send request
window.fetch(`${apiUrl}/${endpoint}?${query}`, {
method: 'GET',