1
0
Fork 0
peertube/server/lib/transcoding/transcoding-priority.ts
2023-05-09 08:57:34 +02:00

24 lines
703 B
TypeScript

import { JOB_PRIORITY } from '@server/initializers/constants'
import { VideoModel } from '@server/models/video/video'
import { MUserId } from '@server/types/models'
export async function getTranscodingJobPriority (options: {
user: MUserId
fallback: number
type: 'vod' | 'studio'
}) {
const { user, fallback, type } = options
if (!user) return fallback
const now = new Date()
const lastWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7)
const videoUploadedByUser = await VideoModel.countVideosUploadedByUserSince(user.id, lastWeek)
const base = type === 'vod'
? JOB_PRIORITY.TRANSCODING
: JOB_PRIORITY.VIDEO_STUDIO
return base + videoUploadedByUser
}