1 parent
5fa871d169
commit
948384222e
3 files changed
+19
-9
No files matched your search
@@ -2,3 +2,4 @@
|
||||
package-lock.json
|
||||
node_modules
|
||||
.env
|
||||
.cache
|
||||
@@ -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
@@ -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);
|
||||
|
||||
|
||||
Reference in new issue
Block a user