47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import { prisma } from '@/lib/prisma'
|
|
import { getFileByObjectName, storeFile } from '../fileStorage'
|
|
import { compressImagesToAv1Video } from '../encodeVideo'
|
|
|
|
export async function compressPics(hostname: string, startTime: Date, endTime: Date) {
|
|
// Build query conditions
|
|
const whereClause: any = { hostname }
|
|
|
|
if (startTime || endTime) {
|
|
whereClause.timestamp = {}
|
|
if (startTime) whereClause.timestamp.gte = startTime
|
|
if (endTime) whereClause.timestamp.lte = endTime
|
|
}
|
|
|
|
// Get records
|
|
const records = await prisma.record.findMany({
|
|
where: whereClause,
|
|
include: {
|
|
windows: false,
|
|
screenshots: true
|
|
},
|
|
orderBy: {
|
|
timestamp: 'desc'
|
|
}
|
|
})
|
|
|
|
// 有两种情况不进行处理:
|
|
// 1. 每个记录中有多于一个截图
|
|
// 2. 时间段内截图有多种分辨率
|
|
|
|
const picNames = records.map(record => {
|
|
return record.screenshots.map(screenshot => screenshot.objectName)
|
|
}).flat();
|
|
|
|
const picBuffers = (await Promise.all(picNames.map(name => getFileByObjectName(name)))).filter(buffer => buffer !== null && buffer !== undefined);
|
|
|
|
// 先默认不存在null吧
|
|
|
|
const vBuffer = await compressImagesToAv1Video(picBuffers)
|
|
|
|
storeFile(vBuffer, 'test.mp4', 'video/mp4', 'other', hostname)
|
|
|
|
}
|
|
|
|
//DESKTOP-JHHNH9C startTime=1751104800 1751108400
|
|
|
|
compressPics('DESKTOP-JHHNH9C', new Date(1751104800000), new Date(1751108400000)) |