( filename: string, data: string, contentType: string, environment: AuthenticatedEnvironment )
| 18 | } |
| 19 | |
| 20 | export async function uploadToObjectStore( |
| 21 | filename: string, |
| 22 | data: string, |
| 23 | contentType: string, |
| 24 | environment: AuthenticatedEnvironment |
| 25 | ): Promise<string> { |
| 26 | if (!r2) { |
| 27 | throw new Error("Object store credentials are not set"); |
| 28 | } |
| 29 | |
| 30 | if (!env.OBJECT_STORE_BASE_URL) { |
| 31 | throw new Error("Object store base URL is not set"); |
| 32 | } |
| 33 | |
| 34 | const url = new URL(env.OBJECT_STORE_BASE_URL); |
| 35 | url.pathname = `/packets/${environment.project.externalRef}/${environment.slug}/${filename}`; |
| 36 | |
| 37 | logger.debug("Uploading to object store", { url: url.href }); |
| 38 | |
| 39 | const response = await r2.fetch(url.toString(), { |
| 40 | method: "PUT", |
| 41 | headers: { |
| 42 | "Content-Type": contentType, |
| 43 | }, |
| 44 | body: data, |
| 45 | }); |
| 46 | |
| 47 | if (!response.ok) { |
| 48 | throw new Error(`Failed to upload output to ${url}: ${response.statusText}`); |
| 49 | } |
| 50 | |
| 51 | return url.href; |
| 52 | } |
no test coverage detected
searching dependent graphs…