@@ -125,51 +125,67 @@ interface entry {
125125/** 从 rss 链接解析 feed 对象 */
126126async function parseFeedByUrl ( url : string ) : Promise < feedByUrl | Error > {
127127 url = url . trim ( ) ;
128- const feed = await fetch ( url )
129- . then ( ( el ) => el . text ( ) )
130- . then ( ( data ) => {
131- var parser = new DOMParser ( ) ;
132- var xmlDoc = parser . parseFromString ( data , "text/xml" ) ;
133- return xmlDoc ;
134- } )
135- . then ( ( dom ) => {
136- if ( dom . querySelector ( "feed" ) ) {
137- return {
138- title : elText ( dom , "feed > title" ) ,
139- subtitle : elText ( dom , "feed > subtitle" ) ,
140- updated : elText ( dom , "feed > updated" ) ,
141- entryList : Array . from ( dom . querySelectorAll ( "feed > entry" ) ) . map ( ( entry ) => {
142- return {
143- title : elText ( entry , "title" ) ,
144- published : elText ( entry , "published" ) ,
145- updated : elText ( entry , "updated" ) ,
146- summary : elText ( entry , "summary" ) ,
147- link : xssDefend ( entry . querySelector ( "link" ) ?. getAttribute ( "href" ) ) ,
148- } as entry ;
149- } ) ,
150- } ;
151- } else if ( dom . querySelector ( "channel" ) ) {
152- return {
153- title : elText ( dom , "channel > title" ) ,
154- subtitle : elText ( dom , "channel > description" ) ,
155- updated : elText ( dom , "channel > lastBuildDate" ) ,
156- entryList : Array . from ( dom . querySelectorAll ( "channel > item" ) ) . map ( ( entry ) => {
157- return {
158- title : elText ( entry , "title" ) ,
159- published : elText ( entry , "pubDate" ) ,
160- updated : elText ( entry , "updated" ) ,
161- summary : elText ( entry , "description" ) ,
162- link : elText ( entry , "link" ) ,
163- } as entry ;
164- } ) ,
165- } ;
166- } else {
167- console . log ( "rss解析失败" , url ) ;
168- return new Error (
169- `未知的格式,可以将此消息发送给开发者 admin@shenzilong.cn (feed_siyuan_plugin):${ url } ` ,
170- ) ;
171- }
172- } ) ;
128+ const feed = new Promise < Document > ( ( r , _j ) => {
129+ fetchPost (
130+ "/api/network/forwardProxy" ,
131+ {
132+ url : url ,
133+ method : "GET" ,
134+ timeout : 7000 ,
135+ contentType : "application/xml" ,
136+ headers : [ ] ,
137+ payload : { } ,
138+ payloadEncoding : "text" ,
139+ responseEncoding : "text" ,
140+ } ,
141+ ( res ) => {
142+ if ( res . code !== 0 && res . data . status !== 200 ) {
143+ _j ( new Error ( res . msg ) ) ;
144+ } else {
145+ var parser = new DOMParser ( ) ;
146+ var xmlDoc = parser . parseFromString ( res . data . body , "text/xml" ) ;
147+ r ( xmlDoc ) ;
148+ }
149+ } ,
150+ ) ;
151+ } ) . then ( ( dom ) => {
152+ if ( dom . querySelector ( "feed" ) ) {
153+ return {
154+ title : elText ( dom , "feed > title" ) ,
155+ subtitle : elText ( dom , "feed > subtitle" ) ,
156+ updated : elText ( dom , "feed > updated" ) ,
157+ entryList : Array . from ( dom . querySelectorAll ( "feed > entry" ) ) . map ( ( entry ) => {
158+ return {
159+ title : elText ( entry , "title" ) ,
160+ published : elText ( entry , "published" ) ,
161+ updated : elText ( entry , "updated" ) ,
162+ summary : elText ( entry , "summary" ) ,
163+ link : xssDefend ( entry . querySelector ( "link" ) ?. getAttribute ( "href" ) ) ,
164+ } as entry ;
165+ } ) ,
166+ } ;
167+ } else if ( dom . querySelector ( "channel" ) ) {
168+ return {
169+ title : elText ( dom , "channel > title" ) ,
170+ subtitle : elText ( dom , "channel > description" ) ,
171+ updated : elText ( dom , "channel > lastBuildDate" ) ,
172+ entryList : Array . from ( dom . querySelectorAll ( "channel > item" ) ) . map ( ( entry ) => {
173+ return {
174+ title : elText ( entry , "title" ) ,
175+ published : elText ( entry , "pubDate" ) ,
176+ updated : elText ( entry , "updated" ) ,
177+ summary : elText ( entry , "description" ) ,
178+ link : elText ( entry , "link" ) ,
179+ } as entry ;
180+ } ) ,
181+ } ;
182+ } else {
183+ console . log ( "rss解析失败" , url ) ;
184+ return new Error (
185+ `未知的格式,可以将此消息发送给开发者 admin@shenzilong.cn (feed_siyuan_plugin):${ url } ` ,
186+ ) ;
187+ }
188+ } ) ;
173189 return feed ;
174190 function elText ( el : Element | Document , selectors : string ) {
175191 return xssDefend ( el . querySelector ( selectors ) ?. textContent ) ;
@@ -268,7 +284,7 @@ function insertBlock(par: {
268284function sql ( stmt : string ) : Promise < IWebSocketData > {
269285 return new Promise ( ( r , _j ) => {
270286 fetchPost (
271- "http://127.0.0.1:6806 /api/query/sql" ,
287+ "/api/query/sql" ,
272288 {
273289 stmt,
274290 } ,
0 commit comments