Skip to content

Commit

Permalink
Merge branch 'main' into fix/windows-driver
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux authored Oct 14, 2024
2 parents 49f67b5 + d95c2fe commit c71e573
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
7 changes: 7 additions & 0 deletions playground/app/pages/cached.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script setup>
const { data } = await useFetch('/api/cached')
</script>

<template>
<pre>{{ data }}</pre>
</template>
4 changes: 4 additions & 0 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export default defineNuxtConfig({
// projectUrl: ({ branch }) => branch === 'main' ? 'https://playground.nuxt.dev' : `https://${encodeHost(branch).replace(/\//g, '-')}.playground-to39.pages.dev`
},

routeRules: {
'/cached': { prerender: true }
},

basicAuth: {
enabled: process.env.NODE_ENV === 'production',
allowedRoutes: ['/api/_hub/'],
Expand Down
10 changes: 10 additions & 0 deletions src/features.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { execSync } from 'node:child_process'
import { resolvePath } from 'mlly'
import type { Nuxt } from '@nuxt/schema'
import { join } from 'pathe'
import { logger, addImportsDir, addServerImportsDir, addServerScanDir, createResolver } from '@nuxt/kit'
import { joinURL } from 'ufo'
import { defu } from 'defu'
Expand Down Expand Up @@ -169,6 +170,15 @@ export async function setupCache(nuxt: Nuxt) {
}
}
})
nuxt.hooks.hook('nitro:init', (nitro) => {
nitro.hooks.hook('prerender:config', (config) => {
config.devStorage ||= {}
config.devStorage.cache = {
driver: 'fs',
base: join(nuxt.options.rootDir, '.data/cache')
}
})
})

// Add Server scanning
addServerScanDir(resolve('./runtime/cache/server'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ export default eventHandler(async (event) => {
await requireNuxtHubAuthorization(event)
requireNuxtHubFeature('blob')

const query = getQuery(event)
const options = { ...getQuery(event) }
if (typeof options.customMetadata === 'string') {
try {
options.customMetadata = JSON.parse(options.customMetadata)
} catch (e) {
options.customMetadata = {}
}
}
return await hubBlob().handleMultipartUpload(event, {
...query
...options
})
})
11 changes: 5 additions & 6 deletions src/runtime/blob/server/utils/blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,17 +396,17 @@ export function proxyHubBlob(projectUrl: string, secretKey?: string): HubBlob {
return
},
async createMultipartUpload(pathname: string, options: BlobMultipartOptions = {}) {
return await blobAPI<BlobMultipartUpload>(`/multipart/${decodeURI(pathname)}`, {
return await blobAPI<BlobMultipartUpload>(`/multipart/create/${decodeURI(pathname)}`, {
method: 'POST',
body: options
query: options
})
},
resumeMultipartUpload(pathname: string, uploadId: string): BlobMultipartUpload {
return {
pathname,
uploadId,
async uploadPart(partNumber: number, body: string | ReadableStream<any> | ArrayBuffer | ArrayBufferView | Blob): Promise<BlobUploadedPart> {
return await blobAPI<BlobUploadedPart>(`/multipart/${decodeURI(pathname)}`, {
return await blobAPI<BlobUploadedPart>(`/multipart/upload/${decodeURI(pathname)}`, {
method: 'PUT',
query: {
uploadId,
Expand All @@ -416,18 +416,17 @@ export function proxyHubBlob(projectUrl: string, secretKey?: string): HubBlob {
})
},
async abort(): Promise<void> {
await blobAPI(`/multipart/${decodeURI(pathname)}`, {
await blobAPI(`/multipart/abort/${decodeURI(pathname)}`, {
method: 'DELETE',
query: {
uploadId
}
})
},
async complete(parts: BlobUploadedPart[]): Promise<BlobObject> {
return await blobAPI<BlobObject>('/multipart/complete', {
return await blobAPI<BlobObject>(`/multipart/complete/${decodeURI(pathname)}`, {
method: 'POST',
query: {
pathname,
uploadId
},
body: {
Expand Down

0 comments on commit c71e573

Please sign in to comment.