@@ -10,6 +10,7 @@ import {
1010 notifyIgnoreFailedRemoteSubFallback ,
1111 resolveIgnoreFailedRemoteSubMode ,
1212 shouldFallbackIgnoreFailedRemoteSub ,
13+ shouldNotifyIgnoreFailedRemoteSub ,
1314} from '@/restful/ignore-failed-remote-sub' ;
1415import {
1516 prepareMihomoProfileContent ,
@@ -82,14 +83,16 @@ async function compareSub(req, res) {
8283 try {
8384 const target = req . query . target || 'JSON' ;
8485 let content ;
86+ let sourceRaw ;
8587 if (
8688 sub . source === 'local' &&
8789 ! [ 'localFirst' , 'remoteFirst' ] . includes ( sub . mergeSources )
8890 ) {
8991 content = sub . content ;
92+ sourceRaw = sub . content ;
9093 } else {
9194 const errors = { } ;
92- content = await Promise . all (
95+ const downloaded = await Promise . all (
9396 sub . url
9497 . split ( / [ \r \n ] + / )
9598 . map ( ( i ) => i . trim ( ) )
@@ -105,6 +108,7 @@ async function compareSub(req, res) {
105108 undefined ,
106109 undefined ,
107110 true ,
111+ { returnRaw : true } ,
108112 ) ;
109113 } catch ( err ) {
110114 errors [ url ] = err ;
@@ -117,6 +121,8 @@ async function compareSub(req, res) {
117121 }
118122 } ) ,
119123 ) ;
124+ content = downloaded . map ( ( i ) => i . result ?? i ) ;
125+ sourceRaw = downloaded . map ( ( i ) => i . raw ?? i ) ;
120126
121127 if ( Object . keys ( errors ) . length > 0 ) {
122128 const message = `订阅 ${
@@ -138,8 +144,10 @@ async function compareSub(req, res) {
138144 }
139145 if ( sub . mergeSources === 'localFirst' ) {
140146 content . unshift ( sub . content ) ;
147+ sourceRaw . unshift ( sub . content ) ;
141148 } else if ( sub . mergeSources === 'remoteFirst' ) {
142149 content . push ( sub . content ) ;
150+ sourceRaw . push ( sub . content ) ;
143151 }
144152 }
145153 // parse proxies
@@ -160,6 +168,8 @@ async function compareSub(req, res) {
160168 sub . process || [ ] ,
161169 target ,
162170 { [ sub . name ] : sub } ,
171+ undefined ,
172+ sourceRaw ,
163173 ) ;
164174
165175 // produce
@@ -222,6 +232,7 @@ async function compareCollection(req, res) {
222232 }
223233 const results = { } ;
224234 const errors = { } ;
235+ const rawResults = { } ;
225236 await Promise . all (
226237 subnames . map ( async ( name ) => {
227238 const sub = findByName ( allSubs , name ) ;
@@ -230,16 +241,18 @@ async function compareCollection(req, res) {
230241 ) ;
231242 try {
232243 let raw ;
244+ let sourceRaw ;
233245 if (
234246 sub . source === 'local' &&
235247 ! [ 'localFirst' , 'remoteFirst' ] . includes (
236248 sub . mergeSources ,
237249 )
238250 ) {
239251 raw = sub . content ;
252+ sourceRaw = sub . content ;
240253 } else {
241254 const errors = { } ;
242- raw = await Promise . all (
255+ const downloaded = await Promise . all (
243256 sub . url
244257 . split ( / [ \r \n ] + / )
245258 . map ( ( i ) => i . trim ( ) )
@@ -255,6 +268,7 @@ async function compareCollection(req, res) {
255268 undefined ,
256269 undefined ,
257270 true ,
271+ { returnRaw : true } ,
258272 ) ;
259273 } catch ( err ) {
260274 errors [ url ] = err ;
@@ -269,6 +283,8 @@ async function compareCollection(req, res) {
269283 }
270284 } ) ,
271285 ) ;
286+ raw = downloaded . map ( ( i ) => i . result ?? i ) ;
287+ sourceRaw = downloaded . map ( ( i ) => i . raw ?? i ) ;
272288
273289 if ( Object . keys ( errors ) . length > 0 ) {
274290 const message = `订阅 ${
@@ -290,8 +306,10 @@ async function compareCollection(req, res) {
290306 }
291307 if ( sub . mergeSources === 'localFirst' ) {
292308 raw . unshift ( sub . content ) ;
309+ sourceRaw . unshift ( sub . content ) ;
293310 } else if ( sub . mergeSources === 'remoteFirst' ) {
294311 raw . push ( sub . content ) ;
312+ sourceRaw . push ( sub . content ) ;
295313 }
296314 }
297315 // parse proxies
@@ -307,13 +325,19 @@ async function compareCollection(req, res) {
307325 } ) ;
308326
309327 // apply processors
328+ const currentRaw = Array . isArray ( sourceRaw )
329+ ? sourceRaw
330+ : [ sourceRaw ] ;
310331 currentProxies = await ProxyUtils . process (
311332 currentProxies ,
312333 sub . process || [ ] ,
313334 'JSON' ,
314335 { [ sub . name ] : sub , _collection : collection } ,
336+ undefined ,
337+ currentRaw ,
315338 ) ;
316339 results [ name ] = currentProxies ;
340+ rawResults [ name ] = currentRaw ;
317341 } catch ( err ) {
318342 if ( shouldFallbackIgnoreFailedRemoteSub ( subMode ) ) {
319343 notifyIgnoreFailedRemoteSubFallback ( {
@@ -333,10 +357,12 @@ async function compareCollection(req, res) {
333357 } `,
334358 ) ;
335359 results [ name ] = [ ] ;
360+ rawResults [ name ] = [ ] ;
336361 return ;
337362 }
338363
339364 errors [ name ] = err ;
365+ rawResults [ name ] = undefined ;
340366
341367 $ . error (
342368 `❌ 处理组合订阅 ${ collection . name } 中的子订阅: ${ sub . name } 时出现错误:${ err } !` ,
@@ -349,17 +375,31 @@ async function compareCollection(req, res) {
349375 const message = `组合订阅 ${ collection . name } 的子订阅 ${ Object . keys (
350376 errors ,
351377 ) . join ( ', ' ) } 发生错误, 请查看日志`;
352- handleIgnoreFailedRemoteSubError ( {
353- mode : collectionMode ,
354- message,
355- notify : ( ) => {
356- $ . notify (
357- `🌍 Sub-Store 预览组合订阅失败` ,
358- `❌ ${ collection . name } ` ,
359- message ,
360- ) ;
361- } ,
362- } ) ;
378+ const notify = ( ) => {
379+ $ . notify (
380+ `🌍 Sub-Store 预览组合订阅失败` ,
381+ `❌ ${ collection . name } ` ,
382+ message ,
383+ ) ;
384+ } ;
385+ const hasProcessedSubscriptions = Object . keys ( results ) . length > 0 ;
386+ if (
387+ hasProcessedSubscriptions &&
388+ shouldFallbackIgnoreFailedRemoteSub ( collectionMode )
389+ ) {
390+ Object . keys ( errors ) . forEach ( ( name ) => {
391+ rawResults [ name ] = [ ] ;
392+ } ) ;
393+ if ( shouldNotifyIgnoreFailedRemoteSub ( collectionMode ) ) {
394+ notify ( ) ;
395+ }
396+ } else {
397+ handleIgnoreFailedRemoteSubError ( {
398+ mode : collectionMode ,
399+ message,
400+ notify,
401+ } ) ;
402+ }
363403 }
364404 // merge proxies with the original order
365405 const original = Array . prototype . concat . apply (
@@ -378,6 +418,8 @@ async function compareCollection(req, res) {
378418 collection . process || [ ] ,
379419 'JSON' ,
380420 { _collection : collection } ,
421+ undefined ,
422+ rawResults ,
381423 ) ;
382424
383425 success ( res , { original, processed } ) ;
0 commit comments