aboutsummaryrefslogtreecommitdiffhomepage
path: root/apps/peertube-runner/src/server/shared/supported-job.ts
blob: d905b5de27518b376557c21e00ac00dead829e7a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import {
  RunnerJobLiveRTMPHLSTranscodingPayload,
  RunnerJobPayload,
  RunnerJobType,
  RunnerJobStudioTranscodingPayload,
  RunnerJobVODAudioMergeTranscodingPayload,
  RunnerJobVODHLSTranscodingPayload,
  RunnerJobVODWebVideoTranscodingPayload,
  VideoStudioTaskPayload
} from '@peertube/peertube-models'

const supportedMatrix = {
  'vod-web-video-transcoding': (_payload: RunnerJobVODWebVideoTranscodingPayload) => {
    return true
  },
  'vod-hls-transcoding': (_payload: RunnerJobVODHLSTranscodingPayload) => {
    return true
  },
  'vod-audio-merge-transcoding': (_payload: RunnerJobVODAudioMergeTranscodingPayload) => {
    return true
  },
  'live-rtmp-hls-transcoding': (_payload: RunnerJobLiveRTMPHLSTranscodingPayload) => {
    return true
  },
  'video-studio-transcoding': (payload: RunnerJobStudioTranscodingPayload) => {
    const tasks = payload?.tasks
    const supported = new Set<VideoStudioTaskPayload['name']>([ 'add-intro', 'add-outro', 'add-watermark', 'cut' ])

    if (!Array.isArray(tasks)) return false

    return tasks.every(t => t && supported.has(t.name))
  }
}

export function isJobSupported (job: {
  type: RunnerJobType
  payload: RunnerJobPayload
}) {
  const fn = supportedMatrix[job.type]
  if (!fn) return false

  return fn(job.payload as any)
}