fix: relax fetch typing for Bun

This commit is contained in:
Peter Steinberger
2026-01-10 04:01:06 +01:00
parent 8466e53b5d
commit f241859c98
2 changed files with 9 additions and 4 deletions

View File

@@ -8,9 +8,14 @@ type FetchMediaResult = {
fileName?: string; fileName?: string;
}; };
export type FetchLike = (
input: RequestInfo | URL,
init?: RequestInit,
) => Promise<Response>;
type FetchMediaOptions = { type FetchMediaOptions = {
url: string; url: string;
fetchImpl?: typeof fetch; fetchImpl?: FetchLike;
filePathHint?: string; filePathHint?: string;
}; };
@@ -57,7 +62,7 @@ export async function fetchRemoteMedia(
options: FetchMediaOptions, options: FetchMediaOptions,
): Promise<FetchMediaResult> { ): Promise<FetchMediaResult> {
const { url, fetchImpl, filePathHint } = options; const { url, fetchImpl, filePathHint } = options;
const fetcher = fetchImpl ?? globalThis.fetch; const fetcher: FetchLike | undefined = fetchImpl ?? globalThis.fetch;
if (!fetcher) { if (!fetcher) {
throw new Error("fetch is not available"); throw new Error("fetch is not available");
} }

View File

@@ -45,7 +45,7 @@ import {
import { danger, logVerbose, shouldLogVerbose } from "../globals.js"; import { danger, logVerbose, shouldLogVerbose } from "../globals.js";
import { enqueueSystemEvent } from "../infra/system-events.js"; import { enqueueSystemEvent } from "../infra/system-events.js";
import { getChildLogger } from "../logging.js"; import { getChildLogger } from "../logging.js";
import { fetchRemoteMedia } from "../media/fetch.js"; import { fetchRemoteMedia, type FetchLike } from "../media/fetch.js";
import { saveMediaBuffer } from "../media/store.js"; import { saveMediaBuffer } from "../media/store.js";
import { buildPairingReply } from "../pairing/pairing-messages.js"; import { buildPairingReply } from "../pairing/pairing-messages.js";
import { import {
@@ -355,7 +355,7 @@ async function resolveSlackMedia(params: {
const url = file.url_private_download ?? file.url_private; const url = file.url_private_download ?? file.url_private;
if (!url) continue; if (!url) continue;
try { try {
const fetchImpl: typeof fetch = (input, init) => { const fetchImpl: FetchLike = (input, init) => {
const headers = new Headers(init?.headers); const headers = new Headers(init?.headers);
headers.set("Authorization", `Bearer ${params.token}`); headers.set("Authorization", `Bearer ${params.token}`);
return fetch(input, { ...init, headers }); return fetch(input, { ...init, headers });