@@ -14,6 +14,8 @@ import $ from '@/core/app';
1414import { findByName } from '@/utils/database' ;
1515import { produceArtifact } from '@/restful/sync' ;
1616import PROXY_PREPROCESSORS from '@/core/proxy-utils/preprocessors' ;
17+ import { ProxyUtils } from '@/core/proxy-utils' ;
18+
1719const clashPreprocessor = PROXY_PREPROCESSORS . find (
1820 ( processor ) => processor . name === 'Clash Pre-processor' ,
1921) ;
@@ -261,10 +263,34 @@ export default async function download(
261263 if ( shouldCache ) {
262264 resourceCache . set ( id , body ) ;
263265 if ( customCacheKey ) {
264- $ . info (
265- `URL ${ url } \n写入自定义缓存 ${ $arguments ?. cacheKey } ` ,
266- ) ;
267- $ . write ( body , customCacheKey ) ;
266+ let shouldWriteCustomCacheKey = true ;
267+ if ( preprocess ) {
268+ try {
269+ const proxies = ProxyUtils . parse ( body ) ;
270+ if (
271+ ! Array . isArray ( proxies ) ||
272+ proxies . length === 0
273+ ) {
274+ $ . error (
275+ `URL ${ url } 不包含有效节点\n不写入自定义缓存 ${ $arguments ?. cacheKey } ` ,
276+ ) ;
277+ shouldWriteCustomCacheKey = false ;
278+ }
279+ } catch ( e ) {
280+ $ . error (
281+ `URL ${ url } 尝试解析节点失败 ${
282+ e . message ?? e
283+ } \n不写入自定义缓存 ${ $arguments ?. cacheKey } `,
284+ ) ;
285+ shouldWriteCustomCacheKey = false ;
286+ }
287+ }
288+ if ( shouldWriteCustomCacheKey ) {
289+ $ . info (
290+ `URL ${ url } \n写入自定义缓存 ${ $arguments ?. cacheKey } ` ,
291+ ) ;
292+ $ . write ( body , customCacheKey ) ;
293+ }
268294 }
269295 }
270296
0 commit comments