Only list keys starting with / (#14)

This commit is contained in:
Kot 2023-04-25 19:05:57 -07:00 committed by GitHub
parent 3d5ceaf054
commit 0f036f799f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -90,13 +90,13 @@ app.get('/', async (c) => {
} }
let { prefix, cursor, limit: limitStr } = c.req.query() let { prefix, cursor, limit: limitStr } = c.req.query()
prefix = prefix ? decodeURIComponent(prefix) : '' prefix = prefix ? decodeURIComponent(prefix) : '/'
cursor = cursor ? decodeURIComponent(cursor) : '' cursor = cursor ? decodeURIComponent(cursor) : ''
let limit = limitStr ? parseInt(decodeURIComponent(limitStr)) : 1000 let limit = limitStr ? parseInt(decodeURIComponent(limitStr)) : 1000
let { keys, ...list } = await c.env.KV.list({ let { keys, ...list } = await c.env.KV.list({
limit, limit,
prefix, prefix: prefix.startsWith('/') ? prefix : '/' + prefix,
cursor, cursor,
}) })