Move to eslint
[oweals/peertube.git] / server / typings / models / video / video.ts
1 import { VideoModel } from '../../../models/video/video'
2 import { PickWith, PickWithOpt } from '../../utils'
3 import {
4   MChannelAccountDefault,
5   MChannelAccountLight,
6   MChannelAccountSummaryFormattable,
7   MChannelActor,
8   MChannelFormattable,
9   MChannelUserId
10 } from './video-channels'
11 import { MTag } from './tag'
12 import { MVideoCaptionLanguage, MVideoCaptionLanguageUrl } from './video-caption'
13 import {
14   MStreamingPlaylistFiles,
15   MStreamingPlaylistRedundancies,
16   MStreamingPlaylistRedundanciesAll,
17   MStreamingPlaylistRedundanciesOpt
18 } from './video-streaming-playlist'
19 import { MVideoFile, MVideoFileRedundanciesAll, MVideoFileRedundanciesOpt } from './video-file'
20 import { MThumbnail } from './thumbnail'
21 import { MVideoBlacklist, MVideoBlacklistLight, MVideoBlacklistUnfederated } from './video-blacklist'
22 import { MScheduleVideoUpdate } from './schedule-video-update'
23 import { MUserVideoHistoryTime } from '../user/user-video-history'
24
25 type Use<K extends keyof VideoModel, M> = PickWith<VideoModel, K, M>
26
27 // ############################################################################
28
29 export type MVideo =
30   Omit<VideoModel, 'VideoChannel' | 'Tags' | 'Thumbnails' | 'VideoPlaylistElements' | 'VideoAbuses' |
31   'VideoFiles' | 'VideoStreamingPlaylists' | 'VideoShares' | 'AccountVideoRates' | 'VideoComments' | 'VideoViews' | 'UserVideoHistories' |
32   'ScheduleVideoUpdate' | 'VideoBlacklist' | 'VideoImport' | 'VideoCaptions'>
33
34 // ############################################################################
35
36 export type MVideoId = Pick<MVideo, 'id'>
37 export type MVideoUrl = Pick<MVideo, 'url'>
38 export type MVideoUUID = Pick<MVideo, 'uuid'>
39
40 export type MVideoIdUrl = MVideoId & MVideoUrl
41 export type MVideoFeed = Pick<MVideo, 'name' | 'uuid'>
42
43 // ############################################################################
44
45 // Video raw associations: schedules, video files, tags, thumbnails, captions, streaming playlists
46
47 // "With" to not confuse with the VideoFile model
48 export type MVideoWithFile =
49   MVideo &
50   Use<'VideoFiles', MVideoFile[]> &
51   Use<'VideoStreamingPlaylists', MStreamingPlaylistFiles[]>
52
53 export type MVideoThumbnail =
54   MVideo &
55   Use<'Thumbnails', MThumbnail[]>
56
57 export type MVideoIdThumbnail =
58   MVideoId &
59   Use<'Thumbnails', MThumbnail[]>
60
61 export type MVideoWithFileThumbnail =
62   MVideo &
63   Use<'VideoFiles', MVideoFile[]> &
64   Use<'Thumbnails', MThumbnail[]>
65
66 export type MVideoThumbnailBlacklist =
67   MVideo &
68   Use<'Thumbnails', MThumbnail[]> &
69   Use<'VideoBlacklist', MVideoBlacklistLight>
70
71 export type MVideoTag =
72   MVideo &
73   Use<'Tags', MTag[]>
74
75 export type MVideoWithSchedule =
76   MVideo &
77   PickWithOpt<VideoModel, 'ScheduleVideoUpdate', MScheduleVideoUpdate>
78
79 export type MVideoWithCaptions =
80   MVideo &
81   Use<'VideoCaptions', MVideoCaptionLanguage[]>
82
83 export type MVideoWithStreamingPlaylist =
84   MVideo &
85   Use<'VideoStreamingPlaylists', MStreamingPlaylistFiles[]>
86
87 // ############################################################################
88
89 // Associations with not all their attributes
90
91 export type MVideoUserHistory =
92   MVideo &
93   Use<'UserVideoHistories', MUserVideoHistoryTime[]>
94
95 export type MVideoWithBlacklistLight =
96   MVideo &
97   Use<'VideoBlacklist', MVideoBlacklistLight>
98
99 export type MVideoAccountLight =
100   MVideo &
101   Use<'VideoChannel', MChannelAccountLight>
102
103 export type MVideoWithRights =
104   MVideo &
105   Use<'VideoBlacklist', MVideoBlacklistLight> &
106   Use<'Thumbnails', MThumbnail[]> &
107   Use<'VideoChannel', MChannelUserId>
108
109 // ############################################################################
110
111 // All files with some additional associations
112
113 export type MVideoWithAllFiles =
114   MVideo &
115   Use<'VideoFiles', MVideoFile[]> &
116   Use<'Thumbnails', MThumbnail[]> &
117   Use<'VideoStreamingPlaylists', MStreamingPlaylistFiles[]>
118
119 export type MVideoAccountLightBlacklistAllFiles =
120   MVideo &
121   Use<'VideoFiles', MVideoFile[]> &
122   Use<'Thumbnails', MThumbnail[]> &
123   Use<'VideoStreamingPlaylists', MStreamingPlaylistFiles[]> &
124   Use<'VideoChannel', MChannelAccountLight> &
125   Use<'VideoBlacklist', MVideoBlacklistLight>
126
127 // ############################################################################
128
129 // With account
130
131 export type MVideoAccountDefault =
132   MVideo &
133   Use<'VideoChannel', MChannelAccountDefault>
134
135 export type MVideoThumbnailAccountDefault =
136   MVideo &
137   Use<'Thumbnails', MThumbnail[]> &
138   Use<'VideoChannel', MChannelAccountDefault>
139
140 export type MVideoWithChannelActor =
141   MVideo &
142   Use<'VideoChannel', MChannelActor>
143
144 export type MVideoFullLight =
145   MVideo &
146   Use<'Thumbnails', MThumbnail[]> &
147   Use<'VideoBlacklist', MVideoBlacklistLight> &
148   Use<'Tags', MTag[]> &
149   Use<'VideoChannel', MChannelAccountLight> &
150   Use<'UserVideoHistories', MUserVideoHistoryTime[]> &
151   Use<'VideoFiles', MVideoFile[]> &
152   Use<'ScheduleVideoUpdate', MScheduleVideoUpdate> &
153   Use<'VideoStreamingPlaylists', MStreamingPlaylistFiles[]>
154
155 // ############################################################################
156
157 // API
158
159 export type MVideoAP =
160   MVideo &
161   Use<'Tags', MTag[]> &
162   Use<'VideoChannel', MChannelAccountLight> &
163   Use<'VideoStreamingPlaylists', MStreamingPlaylistFiles[]> &
164   Use<'VideoCaptions', MVideoCaptionLanguageUrl[]> &
165   Use<'VideoBlacklist', MVideoBlacklistUnfederated> &
166   Use<'VideoFiles', MVideoFileRedundanciesOpt[]> &
167   Use<'Thumbnails', MThumbnail[]>
168
169 export type MVideoAPWithoutCaption = Omit<MVideoAP, 'VideoCaptions'>
170
171 export type MVideoDetails =
172   MVideo &
173   Use<'VideoBlacklist', MVideoBlacklistLight> &
174   Use<'Tags', MTag[]> &
175   Use<'VideoChannel', MChannelAccountLight> &
176   Use<'ScheduleVideoUpdate', MScheduleVideoUpdate> &
177   Use<'Thumbnails', MThumbnail[]> &
178   Use<'UserVideoHistories', MUserVideoHistoryTime[]> &
179   Use<'VideoStreamingPlaylists', MStreamingPlaylistRedundancies[]> &
180   Use<'VideoFiles', MVideoFileRedundanciesOpt[]>
181
182 export type MVideoForUser =
183   MVideo &
184   Use<'VideoChannel', MChannelAccountDefault> &
185   Use<'ScheduleVideoUpdate', MScheduleVideoUpdate> &
186   Use<'VideoBlacklist', MVideoBlacklistLight> &
187   Use<'Thumbnails', MThumbnail[]>
188
189 export type MVideoForRedundancyAPI =
190   MVideo &
191   Use<'VideoFiles', MVideoFileRedundanciesAll[]> &
192   Use<'VideoStreamingPlaylists', MStreamingPlaylistRedundanciesAll[]>
193
194 // ############################################################################
195
196 // Format for API or AP object
197
198 export type MVideoFormattable =
199   MVideo &
200   PickWithOpt<VideoModel, 'UserVideoHistories', MUserVideoHistoryTime[]> &
201   Use<'VideoChannel', MChannelAccountSummaryFormattable> &
202   PickWithOpt<VideoModel, 'ScheduleVideoUpdate', Pick<MScheduleVideoUpdate, 'updateAt' | 'privacy'>> &
203   PickWithOpt<VideoModel, 'VideoBlacklist', Pick<MVideoBlacklist, 'reason'>>
204
205 export type MVideoFormattableDetails =
206   MVideoFormattable &
207   Use<'VideoChannel', MChannelFormattable> &
208   Use<'Tags', MTag[]> &
209   Use<'VideoStreamingPlaylists', MStreamingPlaylistRedundanciesOpt[]> &
210   Use<'VideoFiles', MVideoFileRedundanciesOpt[]>