Skip to content

Commit

Permalink
fix: better handle remote storage for utils
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed Mar 1, 2024
1 parent ab7e216 commit 178d95c
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/server/api/_hub/database/[command].post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ export default eventHandler(async (event) => {
const { query, params, colName } = await readValidatedBody(event, z.object({
query: z.string().min(1).max(1e6).trim(),
params: z.any().array(),
colName: z.string()
colName: z.string().optional()
}).parse)
return db.prepare(query).bind(...params).first(colName)
if (colName) {
return db.prepare(query).bind(...params).first(colName)
}
return db.prepare(query).bind(...params).first()
}

if (command === 'batch') {
Expand Down
2 changes: 1 addition & 1 deletion src/server/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function _useDataset() {

export function hubAnalytics() {
const hub = useRuntimeConfig().hub
if (import.meta.dev && hub.projectUrl) {
if (import.meta.dev && hub.remote && hub.projectUrl) {
return proxyHubAnalytics(hub.projectUrl, hub.projectSecretKey || hub.userToken)
}
const dataset = _useDataset()
Expand Down
2 changes: 1 addition & 1 deletion src/server/utils/blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function _useBucket() {

export function hubBlob() {
const hub = useRuntimeConfig().hub
if (import.meta.dev && hub.projectUrl) {
if (import.meta.dev && hub.remote && hub.projectUrl) {
return proxyHubBlob(hub.projectUrl, hub.projectSecretKey || hub.userToken)
}
const bucket = _useBucket()
Expand Down
2 changes: 1 addition & 1 deletion src/server/utils/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function hubDatabase(): D1Database {
return _db
}
const hub = useRuntimeConfig().hub
if (import.meta.dev && hub.projectUrl) {
if (import.meta.dev && hub.remote && hub.projectUrl) {
_db = proxyHubDatabase(hub.projectUrl, hub.projectSecretKey || hub.userToken)
return _db
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/utils/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const hubHooks = createHooks<HubHooks>()

export function onHubReady (cb: HubHooks['bindings:ready']) {
const hub = useRuntimeConfig().hub
if (import.meta.dev && !hub.projectUrl) {
if (import.meta.dev && !hub.remote) {
return hubHooks.hookOnce('bindings:ready', cb)
}
cb()
Expand Down
2 changes: 1 addition & 1 deletion src/server/utils/kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function hubKV(): HubKV {
return _kv
}
const hub = useRuntimeConfig().hub
if (import.meta.dev && hub.projectUrl) {
if (import.meta.dev && hub.remote && hub.projectUrl) {
return proxyHubKV(hub.projectUrl, hub.projectSecretKey || hub.userToken)
}
// @ts-ignore
Expand Down

0 comments on commit 178d95c

Please sign in to comment.