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