transcoding-priority.ts 718 B

123456789101112131415161718192021222324
  1. import { JOB_PRIORITY } from '@server/initializers/constants.js'
  2. import { VideoModel } from '@server/models/video/video.js'
  3. import { MUserId } from '@server/types/models/index.js'
  4. export async function getTranscodingJobPriority (options: {
  5. user: MUserId
  6. fallback: number
  7. type: 'vod' | 'studio'
  8. }) {
  9. const { user, fallback, type } = options
  10. if (!user) return fallback
  11. const now = new Date()
  12. const lastWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7)
  13. const videoUploadedByUser = await VideoModel.countVideosUploadedByUserSince(user.id, lastWeek)
  14. const base = type === 'vod'
  15. ? JOB_PRIORITY.TRANSCODING
  16. : JOB_PRIORITY.VIDEO_STUDIO
  17. return base + videoUploadedByUser
  18. }