File tree Expand file tree Collapse file tree 4 files changed +36
-1
lines changed
Expand file tree Collapse file tree 4 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,7 @@ ctrl.rss = async (ctx, next) => {
7878 throw new Error ( 'NOT_SUB' ) ;
7979 }
8080 let builder = [ ] ;
81+
8182 builder . push ( `<strong>${ i18n [ 'SUB_LIST' ] } </strong>` ) ;
8283 if ( raw ) {
8384 feeds . forEach ( ( feed ) => {
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ module.exports = async (ctx, next) => {
1212 } else {
1313 try {
1414 const res = await got . get ( url ) ;
15+ // handle redirect
16+ ctx . state . feedUrl = decodeURI ( res . url ) ;
1517 const parser = new Parser ( ) ;
1618 let feed = await parser . parseString ( res . body ) ;
1719 delete feed . items ;
Original file line number Diff line number Diff line change @@ -220,4 +220,31 @@ px.getAllFeedsCount = async () => {
220220 }
221221} ;
222222
223+ px . handleRedirect = async ( url , realUrl ) => {
224+ try {
225+ const db = await dbPomise ;
226+ const oldFeed = await db . get ( `SELECT * FROM rss_feed WHERE url=?` , url ) ;
227+ const realFeed = await db . get (
228+ `SELECT * FROM rss_feed WHERE url=?` ,
229+ realUrl
230+ ) ;
231+ if ( realFeed ) {
232+ await db . run (
233+ `UPDATE subscribes SET feed_id=? WHERE feed_id=?` ,
234+ realFeed . feed_id ,
235+ oldFeed . feed_id
236+ ) ;
237+ await db . run ( `DELETE FROM rss_feed WHERE url=?` , oldFeed . url ) ;
238+ } else {
239+ await db . run (
240+ `UPDATE rss_feed SET url=? WHERE url=?` ,
241+ realUrl ,
242+ oldFeed . url
243+ ) ;
244+ }
245+ } catch ( e ) {
246+ throw new Error ( 'DB_ERROR' ) ;
247+ }
248+ } ;
249+
223250module . exports = px ;
Original file line number Diff line number Diff line change @@ -10,7 +10,8 @@ const {
1010 updateHashList,
1111 failAttempt,
1212 getFeedByUrl,
13- resetErrorCount
13+ resetErrorCount,
14+ handleRedirect
1415} = require ( '../proxies/rssFeed' ) ;
1516const {
1617 notify_error_count,
@@ -23,6 +24,10 @@ const fetch = async (feedUrl) => {
2324 try {
2425 logger . debug ( `fetching ${ feedUrl } ` ) ;
2526 const res = await got . get ( encodeURI ( feedUrl ) ) ;
27+ // handle redirect
28+ if ( encodeURI ( feedUrl ) !== res . url ) {
29+ await handleRedirect ( feedUrl , decodeURI ( res . url ) ) ;
30+ }
2631 const parser = new Parser ( ) ;
2732 const feed = await parser . parseString ( res . body ) ;
2833 const items = feed . items . slice ( 0 , item_num ) ;
You can’t perform that action at this time.
0 commit comments