|
|
@@ -7,6 +7,7 @@ import {
|
|
|
} from '@nestjs/common';
|
|
|
import type { MultipartFile } from '@fastify/multipart';
|
|
|
import { MongoPrismaService } from '@box/db/prisma/mongo-prisma.service';
|
|
|
+import ExcelJS from 'exceljs';
|
|
|
import { CacheSyncService } from '../../../cache-sync/cache-sync.service';
|
|
|
import { CacheEntityType } from '../../../cache-sync/cache-sync.types';
|
|
|
import { MediaManagerService } from '@box/core/media-manager/media-manager.service';
|
|
|
@@ -219,6 +220,45 @@ export class VideoMediaService {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+ async exportExcel(): Promise<Buffer> {
|
|
|
+ const rows = await this.prisma.videoMedia.findMany({});
|
|
|
+ const workbook = new ExcelJS.Workbook();
|
|
|
+ const sheet = workbook.addWorksheet('video-media');
|
|
|
+
|
|
|
+ sheet.columns = [
|
|
|
+ { header: 'id', key: 'id', width: 28 },
|
|
|
+ { header: 'vid', key: 'vid', width: 10 },
|
|
|
+ { header: 'title', key: 'title', width: 40 },
|
|
|
+ { header: 'filename', key: 'filename', width: 40 },
|
|
|
+ { header: 'videoTime', key: 'videoTime', width: 12 },
|
|
|
+ { header: 'size', key: 'size', width: 16 },
|
|
|
+ { header: 'listStatus', key: 'listStatus', width: 12 },
|
|
|
+ { header: 'tags', key: 'tags', width: 40 },
|
|
|
+ { header: 'secondTags', key: 'secondTags', width: 40 },
|
|
|
+ { header: 'updatedAt', key: 'updatedAt', width: 24 },
|
|
|
+ ];
|
|
|
+
|
|
|
+ sheet.addRows(
|
|
|
+ rows.map((row: any) => ({
|
|
|
+ id: this.normalizeMongoIdToString(row.id),
|
|
|
+ vid: row.vid ?? '',
|
|
|
+ title: row.title ?? '',
|
|
|
+ filename: row.filename ?? '',
|
|
|
+ videoTime: row.videoTime ?? '',
|
|
|
+ size: row.size?.toString?.() ?? '',
|
|
|
+ listStatus: row.listStatus ?? '',
|
|
|
+ tags: Array.isArray(row.tags) ? row.tags.join(',') : '',
|
|
|
+ secondTags: Array.isArray(row.secondTags)
|
|
|
+ ? row.secondTags.join(',')
|
|
|
+ : '',
|
|
|
+ updatedAt: row.updatedAt ? new Date(row.updatedAt).toISOString() : '',
|
|
|
+ })),
|
|
|
+ );
|
|
|
+
|
|
|
+ const buffer = await workbook.xlsx.writeBuffer();
|
|
|
+ return Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer);
|
|
|
+ }
|
|
|
+
|
|
|
private buildVideoListBaseFilter(
|
|
|
query: VideoMediaListQueryDto,
|
|
|
): Record<string, any> {
|