|
|
@@ -14,7 +14,7 @@ import type { StorageStrategy } from '@box/core/media-manager/types';
|
|
|
import { randomUUID } from 'crypto';
|
|
|
import {
|
|
|
VideoMediaListQueryDto,
|
|
|
- UpdateVideoMediaManageDto,
|
|
|
+ UpdateVideoMediaTagsDto,
|
|
|
UpdateVideoMediaStatusDto,
|
|
|
BatchUpdateVideoMediaStatusDto,
|
|
|
} from './video-media.dto';
|
|
|
@@ -327,77 +327,36 @@ export class VideoMediaService {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- async updateManage(id: string, dto: UpdateVideoMediaManageDto) {
|
|
|
+ async updateVideoTags(dto: UpdateVideoMediaTagsDto) {
|
|
|
const video = await this.prisma.videoMedia.findUnique({
|
|
|
- where: { id },
|
|
|
+ where: { id: dto.id },
|
|
|
+ select: {
|
|
|
+ id: true,
|
|
|
+ oSecondTags: true,
|
|
|
+ },
|
|
|
});
|
|
|
|
|
|
if (!video) {
|
|
|
throw new NotFoundException('Video not found');
|
|
|
}
|
|
|
|
|
|
- const updateData: any = {};
|
|
|
-
|
|
|
- if (typeof dto.title === 'string') {
|
|
|
- updateData.title = dto.title.trim();
|
|
|
- }
|
|
|
-
|
|
|
- let categoryId: string | null | undefined = dto.categoryId;
|
|
|
- const tagIds: string[] | undefined = dto.tagIds;
|
|
|
-
|
|
|
- if (dto.categoryId === null) {
|
|
|
- categoryId = null;
|
|
|
- }
|
|
|
-
|
|
|
- if (typeof categoryId !== 'undefined' || typeof tagIds !== 'undefined') {
|
|
|
- const { finalCategoryIds, finalTagIds, tags, tagsFlat } =
|
|
|
- await this.validateCategoryAndTags(categoryId, tagIds);
|
|
|
+ const mgntTags = dto.tags; // DTO enforces non-empty string[]
|
|
|
+ const original = video.oSecondTags ?? [];
|
|
|
|
|
|
- updateData.categoryIds = finalCategoryIds;
|
|
|
- updateData.tagIds = finalTagIds;
|
|
|
- updateData.tags = tags; // NEW: store denormalised tag names (lowercased)
|
|
|
- updateData.tagsFlat = tagsFlat; // existing: text for search
|
|
|
- }
|
|
|
-
|
|
|
- if (typeof dto.listStatus === 'number') {
|
|
|
- if (dto.listStatus !== 0 && dto.listStatus !== 1) {
|
|
|
- throw new BadRequestException('Invalid listStatus value');
|
|
|
- }
|
|
|
- updateData.listStatus = dto.listStatus;
|
|
|
- }
|
|
|
-
|
|
|
- updateData.editedAt = BigInt(Date.now());
|
|
|
- updateData.updatedAt = new Date();
|
|
|
+ // combine original + mgnt tags, keep order, remove duplicates
|
|
|
+ const mergedSecondTags = Array.from(new Set([...original, ...mgntTags]));
|
|
|
|
|
|
await this.prisma.videoMedia.update({
|
|
|
- where: { id },
|
|
|
- data: updateData,
|
|
|
+ where: { id: dto.id },
|
|
|
+ data: {
|
|
|
+ tags: mgntTags,
|
|
|
+ secondTags: mergedSecondTags,
|
|
|
+ editedAt: BigInt(Math.floor(Date.now() / 1000)), // epoch seconds (BigInt)
|
|
|
+ updatedAt: new Date(),
|
|
|
+ },
|
|
|
});
|
|
|
|
|
|
- // Refresh category video lists cache if category changed or affected
|
|
|
- if (video.categoryIds && video.categoryIds.length > 0) {
|
|
|
- for (const cid of video.categoryIds) {
|
|
|
- await this.cacheSyncService.scheduleAction({
|
|
|
- entityType: CacheEntityType.VIDEO_LIST,
|
|
|
- operation: 'REFRESH',
|
|
|
- payload: { categoryId: cid },
|
|
|
- } as any);
|
|
|
- }
|
|
|
- }
|
|
|
- if (updateData.categoryIds && updateData.categoryIds.length > 0) {
|
|
|
- const oldCategoryIds = new Set(video.categoryIds || []);
|
|
|
- for (const cid of updateData.categoryIds) {
|
|
|
- if (!oldCategoryIds.has(cid)) {
|
|
|
- await this.cacheSyncService.scheduleAction({
|
|
|
- entityType: CacheEntityType.VIDEO_LIST,
|
|
|
- operation: 'REFRESH',
|
|
|
- payload: { categoryId: cid },
|
|
|
- } as any);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return this.findOne(id);
|
|
|
+ return this.findOne(dto.id);
|
|
|
}
|
|
|
|
|
|
async updateStatus(id: string, dto: UpdateVideoMediaStatusDto) {
|