Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
fix: payload __map.json with special character slugs
Browse files Browse the repository at this point in the history
  • Loading branch information
SidStraw authored and DanSnow committed Dec 21, 2023
1 parent e34379b commit d5d49c7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/karbon/src/runtime/composables/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,12 @@ function getContextFor(type: Resources | string) {
}

async function convertToId(scope: PayloadScope, resourceID: any): Promise<string | null> {
const { id, slug, sid } = resourceID
const { id, slug: _slug, sid } = resourceID
if (id) {
return id
}
const idComparisonMap = await loadStoripressPayload<IdComparisonMap>(scope, '__map', true)
const slug = decodeURIComponent(_slug ?? '')
return (slug ? idComparisonMap.slugs[slug] : idComparisonMap.sids[sid]) ?? null
}

Expand Down
3 changes: 2 additions & 1 deletion packages/karbon/src/runtime/routes/payload-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export function definePayloadHandler<T extends Identifiable>({
const items = await listAll(true)
const initial = { slugs: {}, sids: {} }

return items.reduce((target, { id, slug, sid }) => {
return items.reduce((target, { id, slug: _slug, sid }) => {
const slug = decodeURIComponent(_slug ?? '')
slug && Object.assign(target.slugs, { [slug]: id })
sid && Object.assign(target.sids, { [sid]: id })
return target
Expand Down

0 comments on commit d5d49c7

Please sign in to comment.