fix: 修复cloudflare部署失败的问题 (#92)

* 修复cf部署报错的问题

* 增加.cache ignore
This commit is contained in:
huangxd- authored and GitHub committed 2025-11-15 11:14:55 +08:00
1 parent 5fa871d169
commit 948384222e
3 files changed
+19 -9

No files matched your search

+1
View File
@@ -2,3 +2,4 @@
package-lock.json
node_modules
.env
.cache
+17 -8
View File
@@ -2,8 +2,7 @@ import { globals } from '../configs/globals.js';
import { log } from './log-util.js'
import { Anime } from "../models/dandan-model.js";
import { simpleHash } from "./codec-util.js";
import fs from 'fs';
import path from 'path';
let fs, path;
// =====================
// cache数据结构处理函数
@@ -409,13 +408,23 @@ export async function updateLocalCaches() {
}
// 判断是否有效的本地缓存目录
export function judgeLocalCacheValid(urlPath) {
if (!globals.localCacheValid && urlPath !== "/favicon.ico" && urlPath !== "/robots.txt") {
const cacheDirPath = path.join(getDirname(), '..', '..', '.cache');
export async function judgeLocalCacheValid(urlPath, deployPlatform) {
if (deployPlatform === 'node') {
try {
fs = await import('fs');
path = await import('path');
if (fs.existsSync(cacheDirPath)) {
globals.localCacheValid = true;
} else {
if (!globals.localCacheValid && urlPath !== "/favicon.ico" && urlPath !== "/robots.txt") {
const cacheDirPath = path.join(getDirname(), '..', '..', '.cache');
if (fs.existsSync(cacheDirPath)) {
globals.localCacheValid = true;
} else {
globals.localCacheValid = false;
}
}
} catch (error) {
console.warn('Node.js modules not available:', error.message);
globals.localCacheValid = false;
}
}
+1 -1
View File
@@ -17,7 +17,7 @@ async function handleRequest(req, env, deployPlatform, clientIp) {
const method = req.method;
if (deployPlatform === "node") {
judgeLocalCacheValid(path);
await judgeLocalCacheValid(path, deployPlatform);
}
await judgeRedisValid(path);