From c47b29c5096da23b60bcc4e69dadace4e12ffed5 Mon Sep 17 00:00:00 2001 From: Tony Date: Wed, 15 Feb 2023 12:25:57 +0100 Subject: [PATCH] fix(route): crossbell replace punycode domain (#11872) --- lib/v2/crossbell/feeds/following.js | 31 ++++++++++++++++++----------- lib/v2/crossbell/notes/utils.js | 26 ++++++++++++++---------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/lib/v2/crossbell/feeds/following.js b/lib/v2/crossbell/feeds/following.js index 65cea84d46..5037fe0c6a 100644 --- a/lib/v2/crossbell/feeds/following.js +++ b/lib/v2/crossbell/feeds/following.js @@ -6,17 +6,24 @@ module.exports = async (ctx) => { ctx.state.data = { title: 'Crossbell Feeds of ' + characterId, link: 'https://crossbell.io/', - item: response.data?.list?.map((item) => ({ - title: `${item.type} ${item.character.metadata?.content?.name}@${item.character.handle}`, - description: `${item.type} ${item.note && `
Note: ${item.note.metadata?.content?.title || item.note.metadata?.content?.content}`}${ - item.character && `
Character: ${item.character.metadata?.content?.name}@${item.character.handle}` - }`, - link: item.note ? item.note?.metadata?.content?.external_urls || `https://crossbell.io/notes/${item.note?.characterId}-${item.note?.noteId}` : 'https://xchar.app/' + item.character?.handle, - pubDate: item.createdAt, - updated: item.updatedAt, - author: item.note?.metadata?.content?.authors?.[0] || item.note?.character?.metadata?.content?.name || item.note?.character?.handle || item.owner, - guid: item.transactionHash + item.logIndex + item.type, - category: [...(item.note?.metadata?.content?.sources || []), ...(item.note?.metadata?.content?.tags || [])], - })), + item: response.data?.list?.map((item) => { + let link = item.note ? item.note.metadata?.content?.external_urls?.[0] || `https://crossbell.io/notes/${item.note.characterId}-${item.note.noteId}` : 'https://xchar.app/' + item.character.handle; + if (link.startsWith('https://xn--')) { + link = `https://crossbell.io/notes/${item.note?.characterId}-${item.note?.noteId}`; + } + + return { + title: `${item.type} ${item.character && item.character.metadata?.content?.name}@${item.character && item.character.handle}`, + description: `${item.type} ${item.note && `
Note: ${item.note.metadata?.content?.title || item.note.metadata?.content?.content}`}${ + item.character && `
Character: ${item.character.metadata?.content?.name}@${item.character.handle}` + }`, + link, + pubDate: item.createdAt, + updated: item.updatedAt, + author: item.note?.metadata?.content?.authors?.[0] || item.note?.character?.metadata?.content?.name || item.note?.character?.handle || item.owner, + guid: item.transactionHash + item.logIndex + item.type, + category: [...(item.note?.metadata?.content?.sources || []), ...(item.note?.metadata?.content?.tags || [])], + }; + }), }; }; diff --git a/lib/v2/crossbell/notes/utils.js b/lib/v2/crossbell/notes/utils.js index a1f45e9eab..f6f79899e6 100644 --- a/lib/v2/crossbell/notes/utils.js +++ b/lib/v2/crossbell/notes/utils.js @@ -1,12 +1,18 @@ module.exports = { - getItem: (note) => ({ - title: note.metadata?.content?.title || '', - description: note.metadata?.content?.content, - link: note.metadata?.content?.external_urls || `https://crossbell.io/notes/${note.characterId}-${note.noteId}`, - pubDate: note.metadata?.content?.publishedAt, - updated: note.metadata?.content?.updatedAt, - author: note.metadata?.content?.authors?.[0] || note.character?.metadata?.content?.name || note.character?.handle, - guid: `${note.characterId}-${note.noteId}`, - category: [...(note.metadata?.content?.sources || []), ...(note.metadata?.content?.tags || [])], - }), + getItem: (note) => { + let link = note.metadata?.content?.external_urls?.[0] ?? `https://crossbell.io/notes/${note.characterId}-${note.noteId}`; + if (link.startsWith('https://xn--')) { + link = `https://crossbell.io/notes/${note.characterId}-${note.noteId}`; + } + return { + title: note.metadata?.content?.title || '', + description: note.metadata?.content?.content, + link, + pubDate: note.metadata?.content?.publishedAt, + updated: note.metadata?.content?.updatedAt, + author: note.metadata?.content?.authors?.[0] || note.character?.metadata?.content?.name || note.character?.handle, + guid: `https://crossbell.io/notes/${note.characterId}-${note.noteId}`, + category: [...(note.metadata?.content?.sources || []), ...(note.metadata?.content?.tags || [])], + }; + }, };