FC_DAN\c9837 1 mēnesi atpakaļ
vecāks
revīzija
e58cb2418e

+ 4 - 3
apps/box-app-api/src/feature/auth/auth.service.ts

@@ -21,7 +21,8 @@ type LoginResult = {
   uid: string;
   channelId: string;
   startupAds: any | null; // keep as any until you wire your Ad payload DTO
-  conf: any | null;
+  cdn_img: string;
+  cdn_video: string;
 };
 
 @Injectable()
@@ -109,8 +110,8 @@ export class AuthService {
       uid,
       channelId: finalChannelId,
       startupAds,
-      conf,
-      
+      cdn_img: 'https://vm.rvakc.xyz/res/decode/',
+      cdn_video: 'https://vm.rvakc.xyz/api/web/media/m3u8/',
     };
   }
 

+ 4 - 44
apps/box-app-api/src/feature/video/video.controller.ts

@@ -44,9 +44,7 @@ interface RequestWithUser extends Request {
 @ApiTags('视频')
 @Controller('video')
 export class VideoController {
-  constructor(private readonly videoService: VideoService
-  ) {}
-  
+  constructor(private readonly videoService: VideoService) {}
 
   /**
    * GET /api/v1/video/search
@@ -57,6 +55,8 @@ export class VideoController {
   @ApiOperation({
     summary: '搜索视频',
     description: '',
+    summary: '搜索视频',
+    description: '',
   })
   @ApiResponse({
     status: 200,
@@ -64,52 +64,12 @@ export class VideoController {
     type: VideoItemDto,
     isArray: true,
   })
-  async search(
+  async searchBySecondTags(
     @Body() req: VideoListRequestDto,
   ): Promise<VideoItemDto[]> {
     return await this.videoService.getVideoList(req);
   }
 
-  @Get('homevideo')
-  @ApiOperation({
-    summary: '首页视频',
-  })
-  @ApiQuery({
-    name: 'channelId',
-    required: true,
-    description: '渠道ID',
-  })
-  @ApiResponse({
-    status: 200,
-    description: '标签+视频',
-    isArray: true,
-  })
-  async homeVideo(
-    @Query('channelId') channelId: string,
-  ): Promise<any[]> {
-    return await this.videoService.getHomeSectionVideos(channelId);
-  }  
-
-@Get('guess')
-  @ApiOperation({
-    summary: '猜你喜欢',
-  })
-  @ApiQuery({
-    name: 'tag',
-    required: true,
-    description: '标签',
-  })
-  @ApiResponse({
-    status: 200,
-    description: '视频',
-    isArray: true,
-  })
-  async guess(
-    @Query('tag') tag: string,
-  ): Promise<any[]> {
-    return await this.videoService.getGuessLikeVideos(tag);
-  }    
-
   /**
    * GET /api/v1/video/latest
    *

+ 31 - 27
apps/box-app-api/src/feature/video/video.service.ts

@@ -37,6 +37,7 @@ import {
 } from '../homepage/homepage.constants';
 import { CategoryDto } from '../homepage/dto/homepage.dto';
 import { VideoListItemDto } from './dto/video-list-response.dto';
+import { VideoListItemDto } from './dto/video-list-response.dto';
 
 /**
  * VideoService provides read-only access to video data from Redis cache.
@@ -102,17 +103,18 @@ export class VideoService {
    * Reads video IDs from Redis cache, fetches full details from MongoDB,
    * and returns paginated results.
    */
-  async getVideoList(dto: VideoListRequestDto, ttl?: number): Promise<VideoListItemDto[]> {
+  async getVideoList(dto: VideoListRequestDto): Promise<VideoListItemDto[]> {
     const { page, size, tag, keyword, random } = dto;
     const start = (page - 1) * size;
 
     const cacheKey = `video:list:${Buffer.from(
       JSON.stringify(dto),
     ).toString('base64')}`;
+    const cacheKey = `video:list:${Buffer.from(
+      JSON.stringify(dto),
+    ).toString('base64')}`;
 
-    if(!ttl){
-      ttl = random ? 15 : 300;
-    }
+    const ttl = random ? 15 : 300;
 
     let fallbackRecords: VideoListItemDto[] = [];
     try {
@@ -125,18 +127,19 @@ export class VideoService {
         status: 'Completed'
       };
 
-      if(random){
-        if (tag) {
-          where.secondTags = tag;
-        }
+      if (tag) {
+        where.secondTags = {
+          has: tag,
+        };
+      }
 
-        if (keyword) {
-          where.title = {
-            $regex: keyword,
-            $options: 'i',
-          }
+      if (keyword) {
+        where.title = {
+          contains: keyword, mode: 'insensitive'
         }
+      }
 
+      if(random){
         fallbackRecords = (await this.mongoPrisma.videoMedia.aggregateRaw({
           pipeline: [
             { $match: where },
@@ -154,23 +157,13 @@ export class VideoService {
           ],
         })) as unknown as VideoListItemDto[];
       }else{
-        if (tag) {
-          where.secondTags = {
-            has: tag,
-          };
-        }
-
-        if (keyword) {
-          where.title = {
-            contains: keyword, mode: 'insensitive'
-          }
-        }
-
         fallbackRecords = (await this.mongoPrisma.videoMedia.findMany({
           where,
           orderBy: [{ addedTime: 'desc' }, { createdAt: 'desc' }],
           skip: start,
           take: size,
+          skip: start,
+          take: size,
           select: {
             id: true,
             title: true,
@@ -180,10 +173,13 @@ export class VideoService {
             preFileName: true,
           },
         })) as VideoListItemDto[];
+        })) as VideoListItemDto[];
       }
 
       if (fallbackRecords.length > 0) {
         await this.redis.setJson(cacheKey, fallbackRecords, ttl);
+      if (fallbackRecords.length > 0) {
+        await this.redis.setJson(cacheKey, fallbackRecords, ttl);
       }
 
       return fallbackRecords;
@@ -194,6 +190,14 @@ export class VideoService {
       );
       return [];
     }
+      return fallbackRecords;
+    } catch (err) {
+      this.logger.error(
+        `Error fetching videos from MongoDB`,
+        err instanceof Error ? err.stack : String(err),
+      );
+      return [];
+    }
   }
 
   /**
@@ -469,7 +473,7 @@ export class VideoService {
   async getGuessLikeVideos(tag: string): Promise<VideoItemDto[]> {
     try {
       // Try to fetch from Redis cache first
-      const cached = await this.readCachedVideoList(tsCacheKeys.video.guess() + encodeURIComponent(tag), 'guess like videos');
+      const cached = this.readCachedVideoList(tsCacheKeys.video.guess() + tag, 'guess like videos');
 
       if (cached && Array.isArray(cached) && cached.length > 0) {
         return cached;
@@ -491,7 +495,7 @@ export class VideoService {
         this.mapVideoToDto(v),
       );
 
-      this.redis.setJson(tsCacheKeys.video.guess() + encodeURIComponent(tag), items, 3600).catch(err => {
+      this.redis.setJson(tsCacheKeys.video.guess() + tag, items, 3600).catch(err => {
         this.logger.warn("Redis setJson video.guess failed", err);
       });