mirror of
https://github.com/MoonTechLab/LunaTV.git
synced 2026-05-18 03:37:28 +08:00
feat: refine cron job
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
/* eslint-disable no-console, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
import { getRequestContext } from '@cloudflare/next-on-pages';
|
||||
|
||||
import { AdminConfig } from './admin.types';
|
||||
import { Favorite, IStorage, PlayRecord } from './types';
|
||||
|
||||
export const runtime = 'edge';
|
||||
|
||||
// 搜索历史最大条数
|
||||
const SEARCH_HISTORY_LIMIT = 20;
|
||||
|
||||
@@ -120,17 +116,6 @@ const INIT_SQL = `
|
||||
|
||||
// 获取全局D1数据库实例
|
||||
function getD1Database(): D1Database {
|
||||
try {
|
||||
// 在 Cloudflare Pages 环境中,通过 getRequestContext 访问 D1 数据库
|
||||
const { env } = getRequestContext();
|
||||
if (env && (env as any).DB) {
|
||||
return (env as any).DB as D1Database;
|
||||
}
|
||||
} catch (error) {
|
||||
// 如果 getRequestContext 失败,继续尝试其他方式
|
||||
console.warn('Failed to get request context:', error);
|
||||
}
|
||||
|
||||
// 在 next-on-pages 环境中,D1 数据库可能通过 process.env 暴露
|
||||
if (typeof process !== 'undefined' && (process.env as any).DB) {
|
||||
return (process.env as any).DB as D1Database;
|
||||
@@ -145,10 +130,6 @@ export class D1Storage implements IStorage {
|
||||
private db: D1Database | null = null;
|
||||
private initialized = false;
|
||||
|
||||
constructor() {
|
||||
// 不在构造函数中初始化数据库,延迟到实际使用时
|
||||
}
|
||||
|
||||
private async getDatabase(): Promise<D1Database> {
|
||||
if (!this.db) {
|
||||
this.db = getD1Database();
|
||||
|
||||
Reference in New Issue
Block a user