Update api.ts
This commit is contained in:
parent
3cb555649c
commit
b6abc3608a
|
@ -56,13 +56,12 @@ export function api<E extends keyof Misskey.Endpoints, P extends Misskey.Endpoin
|
||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function apiExternal<E extends keyof Misskey.Endpoints, P extends Misskey.Endpoints[E]['req']>(
|
export async function apiExternal<E extends keyof Misskey.Endpoints, P extends Misskey.Endpoints[E]['req']>(
|
||||||
hostUrl: string,
|
host: string,
|
||||||
endpoint: E, data: P = {} as any,
|
endpoint: E, data: P = {} as any,
|
||||||
token?: string | null | undefined,
|
token?: string | null | undefined,
|
||||||
signal?: AbortSignal,
|
signal?: AbortSignal,
|
||||||
): Promise<Misskey.api.SwitchCaseResponseType<E, P>> {
|
): Promise<Misskey.api.SwitchCaseResponseType<E, P>> {
|
||||||
if (!/^https?:\/\//.test(hostUrl)) throw new Error('invalid host name');
|
|
||||||
if (endpoint.includes('://')) throw new Error('invalid endpoint');
|
if (endpoint.includes('://')) throw new Error('invalid endpoint');
|
||||||
const [hostName, hostUrl] = await (new Promise(resolve => resolve(URL(host))))
|
const [hostName, hostUrl] = await (new Promise(resolve => resolve(URL(host))))
|
||||||
.then(url => {
|
.then(url => {
|
||||||
|
|
Loading…
Reference in New Issue