修复cloudflare上环境变量不生效的问题 (#78)

* 修复cloudflare上环境变量不生效的问题

* 将源的初始化提到文件开头,避免重复创建多个对象

* 修改小版本号
This commit is contained in:
huangxd- authored and GitHub committed 2025-10-27 22:42:26 +08:00
1 parent b794f02733
commit 1406bd8148
4 files changed
+20 -33

No files matched your search

+1 -1
View File
@@ -223,7 +223,7 @@ LogVar 弹幕 API 服务器
>
<img src="https://i.mji.rip/2025/09/17/3a675876dabb92e4ce45c10d543ce66b.png" style="width:400px" />
> 如果每次访问都遇到404等问题,可能是edgeone pages修改了访问策略,每次接口请求都转发到了新的环境,没有缓存,导致获取不到对应的弹幕,推荐用vercel部署。
> 如果每次访问都遇到404等问题,可能是edgeone pages修改了访问策略,每次接口请求都转发到了新的环境,没有缓存,导致获取不到对应的弹幕,推荐用vercel/netlify部署。
>
> 解决方法:请配置环境变量`UPSTASH_REDIS_REST_URL`和`UPSTASH_REDIS_REST_TOKEN`,开启upstash redis存储
+12 -28
View File
@@ -24,6 +24,18 @@ import OtherSource from "../sources/other.js";
// 兼容弹弹play接口
// =====================
const kan360Source = new Kan360Source();
const vodSource = new VodSource();
const renrenSource = new RenrenSource();
const hanjutvSource = new HanjutvSource();
const bahamutSource = new BahamutSource();
const tencentSource = new TencentSource();
const youkuSource = new YoukuSource();
const iqiyiSource = new IqiyiSource();
const mangoSource = new MangoSource();
const bilibiliSource = new BilibiliSource();
const otherSource = new OtherSource();
function matchSeason(anime, queryTitle, season) {
if (anime.animeTitle.includes(queryTitle)) {
const title = anime.animeTitle.split("(")[0].trim();
@@ -51,17 +63,6 @@ function matchSeason(anime, queryTitle, season) {
// Extracted function for GET /api/v2/search/anime
export async function searchAnime(url) {
const kan360Source = new Kan360Source();
const vodSource = new VodSource();
const renrenSource = new RenrenSource();
const hanjutvSource = new HanjutvSource();
const bahamutSource = new BahamutSource();
const tencentSource = new TencentSource();
const youkuSource = new YoukuSource();
const iqiyiSource = new IqiyiSource();
const mangoSource = new MangoSource();
const bilibiliSource = new BilibiliSource();
const queryTitle = url.searchParams.get("keyword");
log("info", `Search anime with keyword: ${queryTitle}`);
@@ -687,16 +688,6 @@ export async function getBangumi(path) {
// Extracted function for GET /api/v2/comment/:commentId
export async function getComment(path, queryFormat) {
const renrenSource = new RenrenSource();
const hanjutvSource = new HanjutvSource();
const bahamutSource = new BahamutSource();
const tencentSource = new TencentSource();
const iqiyiSource = new IqiyiSource();
const mangoSource = new MangoSource();
const bilibiliSource = new BilibiliSource();
const youkuSource = new YoukuSource();
const otherSource = new OtherSource();
const commentId = parseInt(path.split("/").pop());
let url = findUrlById(commentId);
let title = findTitleById(commentId);
@@ -769,13 +760,6 @@ export async function getComment(path, queryFormat) {
// Extracted function for GET /api/v2/comment?url=xxx
export async function getCommentByUrl(videoUrl, queryFormat) {
const tencentSource = new TencentSource();
const iqiyiSource = new IqiyiSource();
const mangoSource = new MangoSource();
const bilibiliSource = new BilibiliSource();
const youkuSource = new YoukuSource();
const otherSource = new OtherSource();
try {
// 验证URL参数
if (!videoUrl || typeof videoUrl !== 'string') {
+6 -3
View File
@@ -3,6 +3,8 @@
* 提供获取和设置环境变量的函数,支持 Cloudflare Workers 和 Node.js
*/
export class Envs {
static env;
// 记录获取过的环境变量
static accessedEnvVars = new Map();
@@ -19,10 +21,10 @@ export class Envs {
*/
static get(key, defaultValue, type = 'string', encrypt = false) {
let value;
if (typeof env !== 'undefined' && env[key]) {
value = env[key]; // Cloudflare Workers
if (typeof this.env !== 'undefined' && this.env[key]) {
value = this.env[key];
} else if (typeof process !== 'undefined' && process.env?.[key]) {
value = process.env[key]; // Node.js
value = process.env[key];
} else {
value = defaultValue;
}
@@ -176,6 +178,7 @@ export class Envs {
* @returns {Object} 配置对象
*/
static load(env = {}, deployPlatform = 'node') {
this.env = env;
return {
vodAllowedPlatforms: this.VOD_ALLOWED_PLATFORMS,
allowedPlatforms: this.ALLOWED_PLATFORMS,
+1 -1
View File
@@ -11,7 +11,7 @@ export const Globals = {
accessedEnvVars: {},
// 静态常量
VERSION: '1.6.1',
VERSION: '1.6.2',
MAX_LOGS: 500, // 日志存储,最多保存 500 行
MAX_ANIMES: 100,
MAX_LAST_SELECT_MAP: 100,