export type CreateApiApiV2CollectionsSlugMediaPlacementArgs = {slug: string, placement: string, content_type: string}; export type CreateApiApiV2CollectionsSlugMediaPlacementOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, WalletAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Upload collection page media * * POST /api/v2/collections/{slug}/media/{placement} */ export const createApiApiV2CollectionsSlugMediaPlacement = async (args: CreateApiApiV2CollectionsSlugMediaPlacementArgs, options?: CreateApiApiV2CollectionsSlugMediaPlacementOptions) => { const {baseUrl = "https://api.opensea.io", fetch: fetchFn = fetch, ApiKeyAuth, WalletAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "*/*") if (args.content_type != null) query.append("content_type", String(args.content_type)) if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) if (WalletAuth !== undefined) headers.set('authorization', `Bearer ${WalletAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/collections/${encodeURIComponent(String(args.slug))}/media/${encodeURIComponent(String(args.placement))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };