Skip to content

Commit f0c52ec

Browse files
committed
chore: handle fresh env variable
1 parent 718b624 commit f0c52ec

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

server/utils/blob.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import { joinURL } from 'ufo'
1010

1111
const _r2_buckets: Record<string, R2Bucket> = {}
1212

13-
function _useBucket () {
13+
function _useBucket() {
1414
const name = 'BLOB'
15-
if (_r2_buckets[name]) {
15+
if (_r2_buckets[name] && !process.env.NUXT_HUB_FRESH) {
1616
return _r2_buckets[name]
1717
}
1818

@@ -26,15 +26,15 @@ function _useBucket () {
2626
return _r2_buckets[name]
2727
}
2828

29-
export function useBlob () {
29+
export function useBlob() {
3030
const proxyURL = import.meta.dev && process.env.NUXT_HUB_URL
3131
let bucket: R2Bucket
3232
if (!proxyURL) {
3333
bucket = _useBucket()
3434
}
3535

3636
return {
37-
async list (options: BlobListOptions = { limit: 1000 }) {
37+
async list(options: BlobListOptions = { limit: 1000 }) {
3838
if (proxyURL) {
3939
return ofetch<BlobObject[]>('/api/_hub/blob', {
4040
baseURL: proxyURL,
@@ -66,7 +66,7 @@ export function useBlob () {
6666

6767
return listed.objects.map(mapR2ObjectToBlob)
6868
},
69-
async serve (event: H3Event, pathname: string) {
69+
async serve(event: H3Event, pathname: string) {
7070
pathname = decodeURI(pathname)
7171
if (proxyURL) {
7272
return ofetch<ReadableStreamDefaultReader<any>>(`/api/_hub/blob/${pathname}`, {
@@ -86,7 +86,7 @@ export function useBlob () {
8686

8787
return object.body
8888
},
89-
async put (pathname: string, body: string | ReadableStream<any> | ArrayBuffer | ArrayBufferView | Blob, options: { contentType?: string, contentLength?: string, addRandomSuffix?: boolean, [key: string]: any } = { addRandomSuffix: true }) {
89+
async put(pathname: string, body: string | ReadableStream<any> | ArrayBuffer | ArrayBufferView | Blob, options: { contentType?: string, contentLength?: string, addRandomSuffix?: boolean, [key: string]: any } = { addRandomSuffix: true }) {
9090
pathname = decodeURI(pathname)
9191
if (proxyURL) {
9292
const { contentType, contentLength, ...query } = options
@@ -119,7 +119,7 @@ export function useBlob () {
119119

120120
return mapR2ObjectToBlob(object)
121121
},
122-
async head (pathname: string) {
122+
async head(pathname: string) {
123123
pathname = decodeURI(pathname)
124124
if (proxyURL) {
125125
const { headers } = await ofetch.raw<void>(joinURL('/api/_hub/blob', pathname), {
@@ -137,7 +137,7 @@ export function useBlob () {
137137

138138
return mapR2ObjectToBlob(object)
139139
},
140-
async delete (pathname: string) {
140+
async delete(pathname: string) {
141141
pathname = decodeURI(pathname)
142142
if (proxyURL) {
143143
await ofetch<void>(`/api/_hub/blob/${pathname}`, {
@@ -163,7 +163,7 @@ export function useBlob () {
163163
// prefix: ''
164164
// })
165165

166-
function getContentType (pathOrExtension?: string) {
166+
function getContentType(pathOrExtension?: string) {
167167
return (pathOrExtension && mime.getType(pathOrExtension)) || 'application/octet-stream'
168168
}
169169

@@ -195,7 +195,7 @@ function getContentType (pathOrExtension?: string) {
195195
// return arrayBuffer
196196
// }
197197

198-
function mapR2ObjectToBlob (object: R2Object): BlobObject {
198+
function mapR2ObjectToBlob(object: R2Object): BlobObject {
199199
return {
200200
pathname: object.key,
201201
contentType: object.httpMetadata?.contentType,

server/utils/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { joinURL } from 'ufo'
88

99
let _configKV: Storage
1010

11-
export function useConfigKV () {
12-
if (_configKV) {
11+
export function useConfigKV() {
12+
if (_configKV && !process.env.NUXT_HUB_FRESH) {
1313
return _configKV
1414
}
1515
if (import.meta.dev && process.env.NUXT_HUB_URL) {

server/utils/database.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export * as tables from '~/server/database/schema'
1313
let _db: DrizzleD1Database | BetterSQLite3Database | SqliteRemoteDatabase
1414
let _client: D1Database
1515

16-
export function useDatabase () {
17-
if (_db) {
16+
export function useDatabase() {
17+
if (_db && !process.env.NUXT_HUB_FRESH) {
1818
return _db
1919
}
2020
if (import.meta.dev && process.env.NUXT_HUB_URL) {
@@ -51,8 +51,8 @@ export function useDatabase () {
5151
return _db
5252
}
5353

54-
export function useDatabaseClient () {
55-
if (!_client) {
54+
export function useDatabaseClient() {
55+
if (!_client || process.env.NUXT_HUB_FRESH) {
5656
useDatabase()
5757
}
5858
return _client

server/utils/kv.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { joinURL } from 'ufo'
66

77
let _kv: Storage
88

9-
export function useKV () {
10-
if (_kv) {
9+
export function useKV() {
10+
if (_kv && !process.env.NUXT_HUB_FRESH) {
1111
return _kv
1212
}
1313
if (import.meta.dev && process.env.NUXT_HUB_URL) {

0 commit comments

Comments
 (0)