弹幕缓存显示元信息
This commit is contained in:
+20
-6
@@ -143,15 +143,22 @@ export async function getEpisodes(
|
||||
export async function getDanmakuById(
|
||||
episodeId: number,
|
||||
title?: string,
|
||||
episodeIndex?: number
|
||||
episodeIndex?: number,
|
||||
metadata?: {
|
||||
animeId?: number;
|
||||
animeTitle?: string;
|
||||
episodeTitle?: string;
|
||||
searchKeyword?: string;
|
||||
danmakuCount?: number;
|
||||
}
|
||||
): Promise<DanmakuComment[]> {
|
||||
try {
|
||||
// 1. 如果提供了 title 和 episodeIndex,先尝试从缓存读取
|
||||
if (title && episodeIndex !== undefined) {
|
||||
const cachedComments = await getDanmakuFromCache(title, episodeIndex);
|
||||
if (cachedComments) {
|
||||
console.log(`[弹幕缓存] 使用缓存: title=${title}, episodeIndex=${episodeIndex}, 数量=${cachedComments.length}`);
|
||||
return cachedComments;
|
||||
const cachedData = await getDanmakuFromCache(title, episodeIndex);
|
||||
if (cachedData) {
|
||||
console.log(`[弹幕缓存] 使用缓存: title=${title}, episodeIndex=${episodeIndex}, 数量=${cachedData.comments.length}`);
|
||||
return cachedData.comments;
|
||||
}
|
||||
console.log(`[弹幕缓存] 缓存未命中,从 API 获取: title=${title}, episodeIndex=${episodeIndex}`);
|
||||
} else {
|
||||
@@ -173,7 +180,14 @@ export async function getDanmakuById(
|
||||
if (comments.length > 0 && title && title.trim() !== '' && episodeIndex !== undefined && episodeIndex >= 0) {
|
||||
try {
|
||||
console.log(`[弹幕缓存] 尝试保存缓存: title="${title}", episodeIndex=${episodeIndex}, 数量=${comments.length}`);
|
||||
await saveDanmakuToCache(title, episodeIndex, comments);
|
||||
await saveDanmakuToCache(title, episodeIndex, comments, {
|
||||
animeId: metadata?.animeId,
|
||||
episodeId: episodeId,
|
||||
animeTitle: metadata?.animeTitle,
|
||||
episodeTitle: metadata?.episodeTitle,
|
||||
searchKeyword: metadata?.searchKeyword,
|
||||
danmakuCount: metadata?.danmakuCount ?? comments.length,
|
||||
});
|
||||
console.log(`[弹幕缓存] 已缓存: title=${title}, episodeIndex=${episodeIndex}, 数量=${comments.length}`);
|
||||
} catch (cacheError) {
|
||||
console.error('[弹幕缓存] 保存缓存失败:', cacheError);
|
||||
|
||||
Reference in New Issue
Block a user