|
@@ -1115,6 +1115,45 @@ export class VideoService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * Read the cached latest video list built by box-mgnt-api.
|
|
|
|
|
+ */
|
|
|
|
|
+ async getLatestVideosFromCache(): Promise<VideoItemDto[]> {
|
|
|
|
|
+ const key = tsCacheKeys.video.latest();
|
|
|
|
|
+ return this.readCachedVideoList(key, 'latest videos');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async getRecommendedVideosFromCache(): Promise<VideoItemDto[]> {
|
|
|
|
|
+ const key = tsCacheKeys.video.recommended();
|
|
|
|
|
+ return this.readCachedVideoList(key, 'recommended videos');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private async readCachedVideoList(
|
|
|
|
|
+ key: string,
|
|
|
|
|
+ label: string,
|
|
|
|
|
+ ): Promise<VideoItemDto[]> {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const raw = await this.redis.get(key);
|
|
|
|
|
+ if (!raw) {
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const parsed = JSON.parse(raw);
|
|
|
|
|
+ if (Array.isArray(parsed)) {
|
|
|
|
|
+ return parsed;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.logger.warn(`${label} cache (${key}) returned non-array payload`);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ this.logger.error(
|
|
|
|
|
+ `Failed to read ${label} cache (${key})`,
|
|
|
|
|
+ err instanceof Error ? err.stack : String(err),
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* Search the cached video list by secondTags, with fallback for videos that have no secondTags.
|
|
* Search the cached video list by secondTags, with fallback for videos that have no secondTags.
|
|
|
*/
|
|
*/
|
|
|
async searchVideosBySecondTags(tags?: string): Promise<VideoItemDto[]> {
|
|
async searchVideosBySecondTags(tags?: string): Promise<VideoItemDto[]> {
|