From 1aa3a8bcf407c7d2e4e3327321c33777e1323f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Tue, 22 Oct 2024 22:55:31 +0200 Subject: [PATCH] feat(blob): expose more data --- docs/content/1.docs/2.features/blob.md | 6 ++++-- src/runtime/blob/server/utils/blob.ts | 2 ++ src/types/blob.ts | 12 ++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/content/1.docs/2.features/blob.md b/docs/content/1.docs/2.features/blob.md index a6377cf8..81e7cfe0 100644 --- a/docs/content/1.docs/2.features/blob.md +++ b/docs/content/1.docs/2.features/blob.md @@ -754,8 +754,10 @@ interface BlobObject { pathname: string contentType: string | undefined size: number - uploadedAt: Date, - customMetadata?: Record | undefined + httpEtag: string + uploadedAt: Date + httpMetadata: Record + customMetadata: Record } ``` diff --git a/src/runtime/blob/server/utils/blob.ts b/src/runtime/blob/server/utils/blob.ts index 95e2105e..35209e0b 100644 --- a/src/runtime/blob/server/utils/blob.ts +++ b/src/runtime/blob/server/utils/blob.ts @@ -638,7 +638,9 @@ function mapR2ObjectToBlob(object: R2Object): BlobObject { pathname: object.key, contentType: object.httpMetadata?.contentType, size: object.size, + httpEtag: object.httpEtag, uploadedAt: object.uploaded, + httpMetadata: object.httpMetadata || {}, customMetadata: object.customMetadata || {} } } diff --git a/src/types/blob.ts b/src/types/blob.ts index 5b07c2e0..450e46a5 100644 --- a/src/types/blob.ts +++ b/src/types/blob.ts @@ -1,4 +1,4 @@ -import type { ReadableStream } from '@cloudflare/workers-types/experimental' +import type { ReadableStream, R2HTTPMetadata } from '@cloudflare/workers-types/experimental' import type { MimeType } from '@uploadthing/mime-types' // Credits from shared utils of https://github.com/pingdotgg/uploadthing @@ -21,14 +21,22 @@ export interface BlobObject { * The size of the blob in bytes. */ size: number + /** + * The blob's etag, in quotes so as to be returned as a header. + */ + httpEtag: string /** * The date the blob was uploaded at. */ uploadedAt: Date + /** + * The HTTP metadata of the blob. + */ + httpMetadata: R2HTTPMetadata /** * The custom metadata of the blob. */ - customMetadata?: Record + customMetadata: Record } export interface BlobUploadedPart {