Skip to content

Commit

Permalink
chore: remove kv prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
smarroufin committed Jan 31, 2024
1 parent 7f5833e commit 3b4ee43
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
6 changes: 1 addition & 5 deletions _nuxthub/server/utils/kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { joinURL } from 'ufo'

let _kv: Storage

export function useKV (prefix?: string) {
export function useKV () {
if (!_kv) {
if (process.env.KV) {
// kv in production
Expand Down Expand Up @@ -39,9 +39,5 @@ export function useKV (prefix?: string) {
}
}

if (prefix) {
return prefixStorage(_kv, prefix)
}

return _kv
}
4 changes: 2 additions & 2 deletions server/api/entries/[key].delete.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useValidatedParams, z } from 'h3-zod'

export default eventHandler(async (event) => {
const session = await requireUserSession(event)
await requireUserSession(event)
const { key } = await useValidatedParams(event, {
key: z.string().min(1).max(100)
})

// Delete entry for the current user
const storage = await useKV(String(session.user!.id))
const storage = await useKV()

await storage.removeItem(key)

Expand Down
4 changes: 2 additions & 2 deletions server/api/entries/index.get.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export default eventHandler(async (event) => {
const session = await requireUserSession(event)
await requireUserSession(event)

// List entries for the current user
const storage = await useKV(String(session.user!.id))
const storage = await useKV()

const keys = await storage.getKeys()
// const items = await storage.getItems(keys)
Expand Down
4 changes: 2 additions & 2 deletions server/api/entries/index.put.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { z } from 'zod'

export default eventHandler(async (event) => {
const session = await requireUserSession(event)
await requireUserSession(event)
const { key, value } = await readValidatedBody(event, z.object({
key: z.string().min(1).max(100),
value: z.any()
}).parse)

// Set entry for the current user
const storage = await useKV(String(session.user!.id))
const storage = await useKV()

await storage.setItem(key, value)

Expand Down

0 comments on commit 3b4ee43

Please sign in to comment.