From 36cc02a811ca904e9be2bf3e1005695aebb3674c Mon Sep 17 00:00:00 2001 From: chezhe Date: Fri, 24 Jun 2022 14:38:50 +0800 Subject: [PATCH] optimize rss.xml parser --- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/tauri.conf.json | 2 +- src/utils/format.ts | 4 ---- src/utils/network.ts | 38 +++++++++++++++++++++++++++++--------- 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index ee045a3..65f1219 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -36,7 +36,7 @@ dependencies = [ [[package]] name = "aleph" -version = "0.6.0" +version = "0.7.0" dependencies = [ "serde", "serde_json", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 58ab3d8..df0fd44 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aleph" -version = "0.6.0" +version = "0.7.0" description = "A Tauri App" authors = ["chezhe"] license = "" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index f07c5ba..18ced8d 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "package": { "productName": "aleph", - "version": "0.6.0" + "version": "0.7.0" }, "build": { "distDir": "../build", diff --git a/src/utils/format.ts b/src/utils/format.ts index 2f7bbcf..daf060d 100644 --- a/src/utils/format.ts +++ b/src/utils/format.ts @@ -37,7 +37,3 @@ export const stripURL = (url?: string) => { } return result } - -// export const diffConcat = (a: Episode[], b: Episode[]) => { - -// } diff --git a/src/utils/network.ts b/src/utils/network.ts index e351ffa..275ee2c 100644 --- a/src/utils/network.ts +++ b/src/utils/network.ts @@ -38,11 +38,16 @@ export async function fetchFeed(feed: Feed): Promise { const extra = { image: jObj.rss?.channel?.image, } - return ( - jObj.rss?.channel?.item.map((item: any) => - formatEpisode(item, feed, extra) - ) || [] - ) + + let items = [] + if (Array.isArray(jObj?.feed?.entry)) { + items = jObj?.feed?.entry + } else if (Array.isArray(jObj.rss?.channel?.item)) { + items = jObj.rss?.channel?.item + } + console.log('fetchFeed', items) + + return items.map((item: any) => formatEpisode(item, feed, extra)) }) .catch((err) => { console.log(err) @@ -94,16 +99,31 @@ export function formatEpisode( cover = newItem.image.url || newItem.image['@_href'] || '' } - const link = `${newItem.link}?${guid}` + let link = '' + if (typeof newItem.link === 'string') { + link = `${newItem.link}?${guid}` + } else { + link = newItem.id || newItem.link['@_href'] + } + + let author = '' + if (newItem.author) { + author = newItem.author.name ?? (newItem.author || newItem['itunes:author']) + } + + let description = newItem['content:encoded'] || newItem.description || '' + if (newItem.content) { + description = newItem.content['#text'] + } newItem = { link, - author: newItem.author || newItem['itunes:author'] || '', - pubDate: newItem.pubDate || '', + author, + pubDate: newItem.pubDate || newItem.published || '', cover, podurl, title: newItem.title || '', - description: newItem['content:encoded'] || newItem.description || '', + description, guid: guid || '', feedid: feed.id, readed: false,