fix typeeror

This commit is contained in:
mtvpls
2025-12-24 23:19:06 +08:00
parent bc8ac693b4
commit c7b9097447
2 changed files with 19 additions and 16 deletions
+6 -5
View File
@@ -85,11 +85,12 @@ class LockManager {
// 全局单例 // 全局单例
const globalKey = Symbol.for('__MOONTV_LOCK_MANAGER__'); const globalKey = Symbol.for('__MOONTV_LOCK_MANAGER__');
let lockManager: LockManager | undefined = (global as any)[globalKey]; let _lockManager: LockManager | undefined = (global as any)[globalKey];
if (!lockManager) { if (!_lockManager) {
lockManager = new LockManager(); _lockManager = new LockManager();
(global as any)[globalKey] = lockManager; (global as any)[globalKey] = _lockManager;
} }
export { lockManager }; // TypeScript doesn't recognize that lockManager is always defined after the if block
export const lockManager = _lockManager as LockManager;
+13 -11
View File
@@ -102,29 +102,31 @@ class OwnerExistenceCache {
// 全局单例 // 全局单例
const globalKey = Symbol.for('__MOONTV_USER_INFO_CACHE__'); const globalKey = Symbol.for('__MOONTV_USER_INFO_CACHE__');
let userInfoCache: UserInfoCache | undefined = (global as any)[globalKey]; let _userInfoCache: UserInfoCache | undefined = (global as any)[globalKey];
if (!userInfoCache) { if (!_userInfoCache) {
userInfoCache = new UserInfoCache(); _userInfoCache = new UserInfoCache();
(global as any)[globalKey] = userInfoCache; (global as any)[globalKey] = _userInfoCache;
// 每分钟清理一次过期缓存 // 每分钟清理一次过期缓存
setInterval(() => { setInterval(() => {
userInfoCache?.cleanup(); _userInfoCache?.cleanup();
}, 60 * 1000); }, 60 * 1000);
} }
export const userInfoCache = _userInfoCache as UserInfoCache;
const ownerExistenceGlobalKey = Symbol.for('__MOONTV_OWNER_EXISTENCE_CACHE__'); const ownerExistenceGlobalKey = Symbol.for('__MOONTV_OWNER_EXISTENCE_CACHE__');
let ownerExistenceCache: OwnerExistenceCache | undefined = (global as any)[ownerExistenceGlobalKey]; let _ownerExistenceCache: OwnerExistenceCache | undefined = (global as any)[ownerExistenceGlobalKey];
if (!ownerExistenceCache) { if (!_ownerExistenceCache) {
ownerExistenceCache = new OwnerExistenceCache(); _ownerExistenceCache = new OwnerExistenceCache();
(global as any)[ownerExistenceGlobalKey] = ownerExistenceCache; (global as any)[ownerExistenceGlobalKey] = _ownerExistenceCache;
// 每分钟清理一次过期缓存 // 每分钟清理一次过期缓存
setInterval(() => { setInterval(() => {
ownerExistenceCache?.cleanup(); _ownerExistenceCache?.cleanup();
}, 60 * 1000); }, 60 * 1000);
} }
export { userInfoCache, ownerExistenceCache }; export const ownerExistenceCache = _ownerExistenceCache as OwnerExistenceCache;