fix: adjust cursor handling for KV pagination

Moves undefined fallback from client to server side for cursor parameter
Ensures consistent pagination behavior when fetching links from KV storage

This prevents potential edge cases where undefined cursor values could be handled differently between client and server.
This commit is contained in:
ccbikai 2024-12-08 11:37:04 +08:00
parent 639368a8ba
commit 19e18546de
2 changed files with 2 additions and 2 deletions

View file

@ -11,7 +11,7 @@ async function getLinks() {
const data = await useAPI('/api/link/list', {
query: {
limit,
cursor: cursor || undefined,
cursor,
},
})
links.value = links.value.concat(data.links).filter(Boolean) // Sometimes cloudflare will return null, filter out

View file

@ -10,7 +10,7 @@ export default eventHandler(async (event) => {
const list = await KV.list({
prefix: `link:`,
limit,
cursor,
cursor: cursor || undefined,
})
if (Array.isArray(list.keys)) {
list.links = await Promise.all(list.keys.map(async (key: { name: string }) => {