mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-01-31 15:37:09 +01:00
feat: user page & $dropFetch util
This commit is contained in:
37
composables/request.ts
Normal file
37
composables/request.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import type {
|
||||
$Fetch,
|
||||
ExtractedRouteMethod,
|
||||
NitroFetchOptions,
|
||||
NitroFetchRequest,
|
||||
TypedInternalResponse,
|
||||
} from "nitropack/types";
|
||||
|
||||
interface DropFetch<
|
||||
DefaultT = unknown,
|
||||
DefaultR extends NitroFetchRequest = NitroFetchRequest
|
||||
> {
|
||||
<
|
||||
T = DefaultT,
|
||||
R extends NitroFetchRequest = DefaultR,
|
||||
O extends NitroFetchOptions<R> = NitroFetchOptions<R>
|
||||
>(
|
||||
request: R,
|
||||
opts?: O
|
||||
): Promise<
|
||||
// @ts-ignore
|
||||
TypedInternalResponse<
|
||||
R,
|
||||
T,
|
||||
NitroFetchOptions<R> extends O ? "get" : ExtractedRouteMethod<R, O>
|
||||
>
|
||||
>;
|
||||
}
|
||||
|
||||
export const $dropFetch: DropFetch = async (request, opts) => {
|
||||
if (!getCurrentInstance()?.proxy) {
|
||||
return (await $fetch(request, opts)) as any;
|
||||
}
|
||||
const { data, error } = await useFetch(request, opts as any);
|
||||
if (error.value) throw error.value;
|
||||
return data.value as any;
|
||||
};
|
||||
Reference in New Issue
Block a user