@@ -2,7 +2,7 @@ import * as fs from "fs";
2
2
import * as path from "path" ;
3
3
import * as opmlToJSON from "opml-to-json" ;
4
4
import * as rimraf from "rimraf" ;
5
-
5
+ import { timeout } from "promise-timeout" ;
6
6
import * as Parser from "rss-parser" ;
7
7
8
8
import { OPML } from "./opml" ;
@@ -39,24 +39,64 @@ async function Process({ source, output }: { source: string; output: string }) {
39
39
folder . children &&
40
40
folder . children . map ( async feed => {
41
41
try {
42
- const url = new URL ( feed . htmlurl ) ;
42
+ await timeout (
43
+ new Promise ( async ( resolve , reject ) => {
44
+ try {
45
+ const url = new URL ( feed . htmlurl ) ;
46
+
47
+ const items = await parser . parseURL ( feed . xmlurl ) ;
43
48
44
- const items = await parser . parseURL ( feed . xmlurl ) ;
49
+ await fs . mkdirSync (
50
+ path . join ( __dirname , output , url . hostname ) ,
51
+ {
52
+ recursive : true ,
53
+ }
54
+ ) ;
45
55
46
- await fs . mkdirSync ( path . join ( __dirname , output , url . hostname ) , {
47
- recursive : true ,
48
- } ) ;
56
+ await fs . writeFileSync (
57
+ path . join ( __dirname , output , url . hostname , "feed.json" ) ,
58
+ JSON . stringify ( { ...feed , ...items } , null , 2 ) ,
59
+ { encoding : "utf8" }
60
+ ) ;
49
61
50
- await fs . writeFileSync (
51
- path . join ( __dirname , output , url . hostname , "feed.json" ) ,
52
- JSON . stringify ( { ...feed , ...items } , null , 2 ) ,
53
- { encoding : "utf8" }
62
+ resolve ( ) ;
63
+ } catch ( err ) {
64
+ reject ( err ) ;
65
+ }
66
+ } ) ,
67
+ 60000
54
68
) ;
55
69
return true ;
56
70
} catch ( err ) {
57
- // console.error(err);
58
- // If this blog continues to error, we'll remove it
59
- console . error ( "FAILED: " , feed . xmlurl ) ;
71
+ if ( ! err . toString ( ) . includes ( "429" ) ) {
72
+ console . error ( "FAILED: " , feed . xmlurl ) ;
73
+
74
+ console . error ( err ) ;
75
+ // If this blog continues to error, we'll remove it
76
+ const opmlRaw = fs . readFileSync ( path . join ( __dirname , source ) ) ;
77
+
78
+ const opmlLines = opmlRaw . toString ( ) . split ( "\n" ) ;
79
+
80
+ const opmlUpdate = opmlLines
81
+ . map ( line => {
82
+ if ( line . includes ( feed . xmlurl ) ) {
83
+ return ;
84
+ }
85
+
86
+ return line ;
87
+ } )
88
+ . filter ( Boolean )
89
+ . join ( "\n" ) ;
90
+
91
+ await fs . writeFileSync (
92
+ path . join ( __dirname , source ) ,
93
+ opmlUpdate ,
94
+ {
95
+ encoding : "utf8" ,
96
+ }
97
+ ) ;
98
+ }
99
+
60
100
return true ;
61
101
}
62
102
} )
0 commit comments