From 215a79fd77654cb6081e61006cff0e9e9a50d7fc Mon Sep 17 00:00:00 2001 From: Sylvain Marroufin Date: Fri, 5 Apr 2024 13:04:36 +0200 Subject: [PATCH] fix(blob): move `HEAD /[path]` to `GET /head/[path]` (#48) --- .../server/api/_hub/blob/[...pathname].head.ts | 15 --------------- .../api/_hub/blob/head/[...pathname].get.ts | 11 +++++++++++ src/runtime/server/utils/blob.ts | 5 ++--- 3 files changed, 13 insertions(+), 18 deletions(-) delete mode 100644 src/runtime/server/api/_hub/blob/[...pathname].head.ts create mode 100644 src/runtime/server/api/_hub/blob/head/[...pathname].get.ts diff --git a/src/runtime/server/api/_hub/blob/[...pathname].head.ts b/src/runtime/server/api/_hub/blob/[...pathname].head.ts deleted file mode 100644 index 2ce5fae9..00000000 --- a/src/runtime/server/api/_hub/blob/[...pathname].head.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { eventHandler, getValidatedRouterParams, setHeader, sendNoContent } from 'h3' -import { z } from 'zod' -import { hubBlob } from '../../../utils/blob' - -export default eventHandler(async (event) => { - const { pathname } = await getValidatedRouterParams(event, z.object({ - pathname: z.string().min(1) - }).parse) - - const blob = await hubBlob().head(pathname) - - setHeader(event, 'x-blob', JSON.stringify(blob)) - - return sendNoContent(event) -}) diff --git a/src/runtime/server/api/_hub/blob/head/[...pathname].get.ts b/src/runtime/server/api/_hub/blob/head/[...pathname].get.ts new file mode 100644 index 00000000..a8b87682 --- /dev/null +++ b/src/runtime/server/api/_hub/blob/head/[...pathname].get.ts @@ -0,0 +1,11 @@ +import { eventHandler, getValidatedRouterParams } from 'h3' +import { z } from 'zod' +import { hubBlob } from '../../../../utils/blob' + +export default eventHandler(async (event) => { + const { pathname } = await getValidatedRouterParams(event, z.object({ + pathname: z.string().min(1) + }).parse) + + return hubBlob().head(pathname) +}) diff --git a/src/runtime/server/utils/blob.ts b/src/runtime/server/utils/blob.ts index 81298ff1..932d5b27 100644 --- a/src/runtime/server/utils/blob.ts +++ b/src/runtime/server/utils/blob.ts @@ -269,10 +269,9 @@ export function proxyHubBlob(projectUrl: string, secretKey?: string) { }) }, async head(pathname: string) { - const { headers } = await blobAPI.raw(decodeURI(pathname), { - method: 'HEAD' + return await blobAPI(`/head/${decodeURI(pathname)}`, { + method: 'GET' }) - return JSON.parse(headers.get('x-blob') || '{}') as BlobObject }, async del(pathnames: string | string[]) { if (Array.isArray(pathnames)) {