Skip to content

Commit

Permalink
Fix NFT metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
livid committed Feb 14, 2024
1 parent 88b1ab5 commit 3b2bcba
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Planet/Entities/DraftModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ class DraftModel: Identifiable, Equatable, Hashable, Codable, ObservableObject {
article.attachments = currentAttachments
article.heroImage = heroImage
article.tags = tags
article.cids = article.getCIDs()
article.cids = article.getCIDs(for: currentAttachments)
article.videoFilename = videoFilename
article.audioFilename = audioFilename
if let contentHTML = CMarkRenderer.renderMarkdownHTML(markdown: article.content),
Expand Down
6 changes: 3 additions & 3 deletions Planet/Entities/MyArticleModel+Save.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ extension MyArticleModel {
}

/// Get CIDs of all attachments
func getCIDs() -> [String: String] {
if let attachments = self.attachments, attachments.count > 0 {
func getCIDs(for attachmentsToProcess: [String]) -> [String: String] {
if attachmentsToProcess.count > 0 {
var cids: [String: String] = [:]
for attachment in attachments {
for attachment in attachmentsToProcess {
if let attachmentURL = getAttachmentURL(name: attachment) {
if let attachmentCID = try? IPFSDaemon.shared.getFileCIDv0(url: attachmentURL) {
debugPrint("CID for \(attachment): \(attachmentCID)")
Expand Down
15 changes: 11 additions & 4 deletions Planet/Entities/MyArticleModel+SavePublic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,17 @@ extension MyArticleModel {
}
}
}
var attachmentsToProcess: [String] = []
if let attachments = self.attachments {
attachmentsToProcess = attachments
}
if attachmentsToProcess.count == 0, self.planet.templateName == "Croptop" {
attachmentsToProcess = ["_cover.png"]
}
var attachmentCIDs: [String: String] = self.cids ?? [:]
let needsToUpdateCIDs = {
if let cids = self.cids, cids.count > 0 {
for attachment in self.attachments ?? [] {
for attachment in attachmentsToProcess {
if cids[attachment] == nil {
debugPrint(
"CID Update for \(self.title): NEEDED because \(attachment) is missing"
Expand All @@ -112,15 +119,15 @@ extension MyArticleModel {
}
return false
}
if self.attachments?.count ?? 0 > 0 {
if attachmentsToProcess.count > 0 {
debugPrint("CID Update for \(self.title): NEEDED because cids is nil")
return true
}
return false
}()
if needsToUpdateCIDs {
debugPrint("CID Update for \(self.title): NEEDED")
attachmentCIDs = getCIDs()
attachmentCIDs = getCIDs(for: attachmentsToProcess)
self.cids = attachmentCIDs
try? self.save()
}
Expand Down Expand Up @@ -206,7 +213,7 @@ extension MyArticleModel {
image: "https://ipfs.io/ipfs/\(imageCID)",
external_url: (self.externalLink ?? self.browserURL?.absoluteString) ?? "",
mimeType: self.getAttachmentMimeType(name: firstKey),
animation_url: "https://ipfs.io/ipfs/\(animationCID)" ?? nil,
animation_url: animationCID != nil ? "https://ipfs.io/ipfs/\(animationCID)" : nil,
attributes: attributes
)
let nftData = try JSONEncoder.shared.encode(nft)
Expand Down
2 changes: 1 addition & 1 deletion Planet/versioning.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CURRENT_PROJECT_VERSION = 1862
CURRENT_PROJECT_VERSION = 1863
2 changes: 1 addition & 1 deletion PlanetLite/AppSidebarItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ struct AppSidebarItemView: View {
Button {
openVSCode(template)
} label: {
Image(systemName: "curlybraces")
Image(systemName: "chevron.left.slash.chevron.right")
Text("Open Template in VSCode")
}
}
Expand Down

0 comments on commit 3b2bcba

Please sign in to comment.