修复继续观看渐进式加载
This commit is contained in:
@@ -716,6 +716,42 @@ export async function getAllPlayRecords(): Promise<Record<string, PlayRecord>> {
|
||||
}
|
||||
}
|
||||
|
||||
export function getCachedPlayRecordsSnapshot(): Record<string, PlayRecord> {
|
||||
if (typeof window === 'undefined') {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (STORAGE_TYPE !== 'localstorage') {
|
||||
const cachedRecords = cacheManager.getCachedPlayRecords();
|
||||
if (cachedRecords) {
|
||||
return cachedRecords;
|
||||
}
|
||||
|
||||
try {
|
||||
const username = getAuthInfoFromBrowserCookie()?.username;
|
||||
if (!username) return {};
|
||||
|
||||
const raw = localStorage.getItem(`${CACHE_PREFIX}${username}`);
|
||||
if (!raw) return {};
|
||||
|
||||
const userCache = JSON.parse(raw) as UserCacheStore;
|
||||
return userCache.playRecords?.data || {};
|
||||
} catch (err) {
|
||||
console.error('读取用户播放记录快照失败:', err);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const raw = localStorage.getItem(PLAY_RECORDS_KEY);
|
||||
if (!raw) return {};
|
||||
return JSON.parse(raw) as Record<string, PlayRecord>;
|
||||
} catch (err) {
|
||||
console.error('读取本地播放记录快照失败:', err);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存播放记录。
|
||||
* 数据库存储模式下使用乐观更新:先更新缓存(立即生效),再异步同步到数据库。
|
||||
|
||||
Reference in New Issue
Block a user