Skip to content

Commit

Permalink
refactor: clear logic
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Jan 25, 2024
1 parent 4bc7b57 commit a23410d
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/lib/expand-unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,22 @@ export const expandCrossbellNote = async ({
expandedNote.metadata.content.contentHTML = rendered.toHTML()
}
}
expandedNote.metadata.content.cover =
expandedNote.metadata?.content?.attachments?.find(
(attachment) => attachment.name === "cover",
)?.address || (disableAutofill ? "" : renderedMetadata?.images?.[0])

expandedNote.metadata.content.images = []

const cover = expandedNote.metadata?.content?.attachments?.find(
const attachmentsCover = expandedNote.metadata?.content?.attachments?.find(
(attachment) => attachment.name === "cover",
)?.address
if (cover) {
expandedNote.metadata.content.images.push(cover)
}

const attachmentsImages = expandedNote.metadata?.content?.attachments
?.filter(
(attachment) => attachment.name === "image" && attachment.address,
)
.map((attachment) => attachment.address!)

expandedNote.metadata.content.images = []

if (attachmentsCover) {
expandedNote.metadata.content.images.push(attachmentsCover)
}

expandedNote.metadata.content.images =
expandedNote.metadata.content.images.concat(attachmentsImages || [])

Expand All @@ -149,6 +146,9 @@ export const expandCrossbellNote = async ({
...new Set(expandedNote.metadata.content.images),
]

expandedNote.metadata.content.cover =
attachmentsCover || (disableAutofill ? "" : renderedMetadata?.images?.[0])

if (useImageDimensions) {
try {
const imageDimensions = await (
Expand Down

0 comments on commit a23410d

Please sign in to comment.