|
1 | 1 | import type { R2Bucket, R2ListOptions } from '@cloudflare/workers-types/experimental' |
2 | | -import type { EventHandlerRequest, H3Event } from 'h3' |
| 2 | +import type { BlobObject } from '~/_nuxthub/types' |
3 | 3 | import mime from 'mime' |
4 | | -import { imageMeta } from 'image-meta' |
| 4 | +// import { imageMeta } from 'image-meta' |
5 | 5 | import { defu } from 'defu' |
6 | 6 | import { randomUUID } from 'uncrypto' |
7 | 7 | import { parse } from 'pathe' |
@@ -36,7 +36,7 @@ export function useBlob () { |
36 | 36 | if (proxy) { |
37 | 37 | const query: Record<string, any> = {} |
38 | 38 |
|
39 | | - return $fetch<R2Object[]>('/api/_hub/bucket', { baseURL: proxy, method: 'GET', query }) |
| 39 | + return $fetch<BlobObject[]>('/api/_hub/bucket', { baseURL: proxy, method: 'GET', query }) |
40 | 40 | } else { |
41 | 41 | const bucket = useBucket() |
42 | 42 |
|
@@ -132,35 +132,19 @@ function getContentType (pathOrExtension?: string) { |
132 | 132 | return (pathOrExtension && mime.getType(pathOrExtension)) || 'application/octet-stream' |
133 | 133 | } |
134 | 134 |
|
135 | | -export function getMetadata (filename: string, buffer: Buffer) { |
136 | | - const metadata: Record<string, any> = { |
137 | | - contentType: getContentType(filename) |
138 | | - } |
| 135 | +// function getMetadata (filename: string, buffer: Buffer) { |
| 136 | +// const metadata: Record<string, any> = { |
| 137 | +// contentType: getContentType(filename) |
| 138 | +// } |
139 | 139 |
|
140 | | - if (metadata.contentType.startsWith('image/')) { |
141 | | - Object.assign(metadata, imageMeta(buffer)) |
142 | | - } |
| 140 | +// if (metadata.contentType.startsWith('image/')) { |
| 141 | +// Object.assign(metadata, imageMeta(buffer)) |
| 142 | +// } |
143 | 143 |
|
144 | | - return metadata |
145 | | -} |
146 | | - |
147 | | -export function toArrayBuffer (buffer: Buffer) { |
148 | | - const arrayBuffer = new ArrayBuffer(buffer.length) |
149 | | - const view = new Uint8Array(arrayBuffer) |
150 | | - for (let i = 0; i < buffer.length; ++i) { |
151 | | - view[i] = buffer[i] |
152 | | - } |
153 | | - return arrayBuffer |
154 | | -} |
155 | | - |
156 | | -export async function readFiles (event: H3Event<EventHandlerRequest>) { |
157 | | - const files = (await readMultipartFormData(event) || []) |
158 | | - |
159 | | - // Filter only files |
160 | | - return files.filter((file) => Boolean(file.filename)) |
161 | | -} |
| 144 | +// return metadata |
| 145 | +// } |
162 | 146 |
|
163 | | -function mapR2ObjectToBlob (object: R2Object) { |
| 147 | +function mapR2ObjectToBlob (object: R2Object): BlobObject { |
164 | 148 | return { |
165 | 149 | pathname: object.key, |
166 | 150 | contentType: object.httpMetadata?.contentType, |
|
0 commit comments