]>
Commit | Line | Data |
---|---|---|
1 | import { HttpStatusCode, VideoEditorTask } from '@shared/models' | |
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | |
3 | ||
4 | export class VideoEditorCommand extends AbstractCommand { | |
5 | ||
6 | static getComplexTask (): VideoEditorTask[] { | |
7 | return [ | |
8 | // Total duration: 2 | |
9 | { | |
10 | name: 'cut', | |
11 | options: { | |
12 | start: 1, | |
13 | end: 3 | |
14 | } | |
15 | }, | |
16 | ||
17 | // Total duration: 7 | |
18 | { | |
19 | name: 'add-outro', | |
20 | options: { | |
21 | file: 'video_short.webm' | |
22 | } | |
23 | }, | |
24 | ||
25 | { | |
26 | name: 'add-watermark', | |
27 | options: { | |
28 | file: 'thumbnail.png' | |
29 | } | |
30 | }, | |
31 | ||
32 | // Total duration: 9 | |
33 | { | |
34 | name: 'add-intro', | |
35 | options: { | |
36 | file: 'video_very_short_240p.mp4' | |
37 | } | |
38 | } | |
39 | ] | |
40 | } | |
41 | ||
42 | createEditionTasks (options: OverrideCommandOptions & { | |
43 | videoId: number | string | |
44 | tasks: VideoEditorTask[] | |
45 | }) { | |
46 | const path = '/api/v1/videos/' + options.videoId + '/editor/edit' | |
47 | const attaches: { [id: string]: any } = {} | |
48 | ||
49 | for (let i = 0; i < options.tasks.length; i++) { | |
50 | const task = options.tasks[i] | |
51 | ||
52 | if (task.name === 'add-intro' || task.name === 'add-outro' || task.name === 'add-watermark') { | |
53 | attaches[`tasks[${i}][options][file]`] = task.options.file | |
54 | } | |
55 | } | |
56 | ||
57 | return this.postUploadRequest({ | |
58 | ...options, | |
59 | ||
60 | path, | |
61 | attaches, | |
62 | fields: { tasks: options.tasks }, | |
63 | implicitToken: true, | |
64 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | |
65 | }) | |
66 | } | |
67 | } |