|
|
@@ -103,7 +103,7 @@ export class VideoService {
|
|
|
* Reads video IDs from Redis cache, fetches full details from MongoDB,
|
|
|
* and returns paginated results.
|
|
|
*/
|
|
|
- async getVideoList(dto: VideoListRequestDto): Promise<VideoListItemDto[]> {
|
|
|
+ async getVideoList(dto: VideoListRequestDto, ttl?: number): Promise<VideoListItemDto[]> {
|
|
|
const { page, size, tag, keyword, random } = dto;
|
|
|
const start = (page - 1) * size;
|
|
|
|
|
|
@@ -114,7 +114,9 @@ export class VideoService {
|
|
|
JSON.stringify(dto),
|
|
|
).toString('base64')}`;
|
|
|
|
|
|
- const ttl = random ? 15 : 300;
|
|
|
+ if(!ttl){
|
|
|
+ ttl = random ? 15 : 300;
|
|
|
+ }
|
|
|
|
|
|
let fallbackRecords: VideoListItemDto[] = [];
|
|
|
try {
|
|
|
@@ -127,19 +129,18 @@ export class VideoService {
|
|
|
status: 'Completed'
|
|
|
};
|
|
|
|
|
|
- if (tag) {
|
|
|
- where.secondTags = {
|
|
|
- has: tag,
|
|
|
- };
|
|
|
- }
|
|
|
+ if(random){
|
|
|
+ if (tag) {
|
|
|
+ where.secondTags = tag;
|
|
|
+ }
|
|
|
|
|
|
- if (keyword) {
|
|
|
- where.title = {
|
|
|
- contains: keyword, mode: 'insensitive'
|
|
|
+ if (keyword) {
|
|
|
+ where.title = {
|
|
|
+ $regex: keyword,
|
|
|
+ $options: 'i',
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if(random){
|
|
|
fallbackRecords = (await this.mongoPrisma.videoMedia.aggregateRaw({
|
|
|
pipeline: [
|
|
|
{ $match: where },
|
|
|
@@ -157,6 +158,18 @@ 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' }],
|
|
|
@@ -473,7 +486,7 @@ export class VideoService {
|
|
|
async getGuessLikeVideos(tag: string): Promise<VideoItemDto[]> {
|
|
|
try {
|
|
|
// Try to fetch from Redis cache first
|
|
|
- const cached = this.readCachedVideoList(tsCacheKeys.video.guess() + tag, 'guess like videos');
|
|
|
+ const cached = await this.readCachedVideoList(tsCacheKeys.video.guess() + encodeURIComponent(tag), 'guess like videos');
|
|
|
|
|
|
if (cached && Array.isArray(cached) && cached.length > 0) {
|
|
|
return cached;
|
|
|
@@ -495,7 +508,7 @@ export class VideoService {
|
|
|
this.mapVideoToDto(v),
|
|
|
);
|
|
|
|
|
|
- this.redis.setJson(tsCacheKeys.video.guess() + tag, items, 3600).catch(err => {
|
|
|
+ this.redis.setJson(tsCacheKeys.video.guess() + encodeURIComponent(tag), items, 3600).catch(err => {
|
|
|
this.logger.warn("Redis setJson video.guess failed", err);
|
|
|
});
|
|
|
|