@@ -2,8 +2,7 @@ import { globals } from '../configs/globals.js';
22import { log } from './log-util.js'
33import { Anime } from "../models/dandan-model.js" ;
44import { simpleHash } from "./codec-util.js" ;
5- import fs from 'fs' ;
6- import path from 'path' ;
5+ let fs , path ;
76
87// =====================
98// cache数据结构处理函数
@@ -409,13 +408,23 @@ export async function updateLocalCaches() {
409408}
410409
411410// 判断是否有效的本地缓存目录
412- export function judgeLocalCacheValid ( urlPath ) {
413- if ( ! globals . localCacheValid && urlPath !== "/favicon.ico" && urlPath !== "/robots.txt" ) {
414- const cacheDirPath = path . join ( getDirname ( ) , '..' , '..' , '.cache' ) ;
411+ export async function judgeLocalCacheValid ( urlPath , deployPlatform ) {
412+ if ( deployPlatform === 'node' ) {
413+ try {
414+ fs = await import ( 'fs' ) ;
415+ path = await import ( 'path' ) ;
415416
416- if ( fs . existsSync ( cacheDirPath ) ) {
417- globals . localCacheValid = true ;
418- } else {
417+ if ( ! globals . localCacheValid && urlPath !== "/favicon.ico" && urlPath !== "/robots.txt" ) {
418+ const cacheDirPath = path . join ( getDirname ( ) , '..' , '..' , '.cache' ) ;
419+
420+ if ( fs . existsSync ( cacheDirPath ) ) {
421+ globals . localCacheValid = true ;
422+ } else {
423+ globals . localCacheValid = false ;
424+ }
425+ }
426+ } catch ( error ) {
427+ console . warn ( 'Node.js modules not available:' , error . message ) ;
419428 globals . localCacheValid = false ;
420429 }
421430 }
0 commit comments