winupdate-neo/lib/schedule/compressPics.ts
2025-07-05 14:26:57 +08:00

42 lines
1.3 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'
}
})
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);
const vBuffer = await compressImagesToAv1Video(picBuffers)
return vBuffer
// storeFile(vBuffer, 'test.mp4', 'video/mp4', 'other', hostname)
}
//DESKTOP-JHHNH9C startTime=1751104800 1751108400
/* compressPics('DESKTOP-JHHNH9C', new Date(1751104800000), new Date(1751108400000)) */