Skip to content

Commit

Permalink
feat: fetch metadata content
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Nov 1, 2023
1 parent 381f53b commit bacfcf9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/lib/expand-unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export const expandCrossbellNote = async ({
useHTML?: boolean
disableAutofill?: boolean
}) => {
if (note.metadata?.uri && !note.metadata?.content) {
note.metadata.content = await (
await fetch(toGateway(note.metadata.uri))
).json()
}

const expandedNote: ExpandedNote = Object.assign(
{
metadata: {
Expand Down Expand Up @@ -169,7 +175,13 @@ export const expandCrossbellNote = async ({
return expandedNote
}

export const expandCrossbellCharacter = (site: CharacterEntity) => {
export const expandCrossbellCharacter = async (site: CharacterEntity) => {
if (site.metadata?.uri && !site.metadata?.content) {
site.metadata.content = await (
await fetch(toGateway(site.metadata.uri))
).json()
}

const expandedCharacter: ExpandedCharacter = Object.assign(
{
metadata: {
Expand Down
4 changes: 2 additions & 2 deletions src/models/site.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Contract = ReturnType<typeof useContract>
export const getSite = async (input: string) => {
const result = await indexer.character.getByHandle(input)
if (result) {
return expandCrossbellCharacter(result)
return await expandCrossbellCharacter(result)
}
}

Expand All @@ -23,7 +23,7 @@ export const getSiteByAddress = async (input: string) => {
})

if (result?.list?.[0]) {
return expandCrossbellCharacter(result.list[0])
return await expandCrossbellCharacter(result.list[0])
}
}

Expand Down

0 comments on commit bacfcf9

Please sign in to comment.