]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/video/sql/shared/video-tables.ts
Use raw SQL for most of video queries
[github/Chocobozzz/PeerTube.git] / server / models / video / sql / shared / video-tables.ts
1
2 /**
3 *
4 * Class to build video attributes/join names we want to fetch from the database
5 *
6 */
7 export class VideoTables {
8
9 constructor (readonly mode: 'get' | 'list') {
10
11 }
12
13 getChannelAttributesForUser () {
14 return [ 'id', 'accountId' ]
15 }
16
17 getChannelAttributes () {
18 let attributeKeys = [
19 'id',
20 'name',
21 'description',
22 'actorId'
23 ]
24
25 if (this.mode === 'get') {
26 attributeKeys = attributeKeys.concat([
27 'support',
28 'createdAt',
29 'updatedAt'
30 ])
31 }
32
33 return attributeKeys
34 }
35
36 getUserAccountAttributes () {
37 return [ 'id', 'userId' ]
38 }
39
40 getAccountAttributes () {
41 let attributeKeys = [ 'id', 'name', 'actorId' ]
42
43 if (this.mode === 'get') {
44 attributeKeys = attributeKeys.concat([
45 'description',
46 'createdAt',
47 'updatedAt'
48 ])
49 }
50
51 return attributeKeys
52 }
53
54 getThumbnailAttributes () {
55 let attributeKeys = [ 'id', 'type', 'filename' ]
56
57 if (this.mode === 'get') {
58 attributeKeys = attributeKeys.concat([
59 'height',
60 'width',
61 'fileUrl',
62 'automaticallyGenerated',
63 'videoId',
64 'videoPlaylistId',
65 'createdAt',
66 'updatedAt'
67 ])
68 }
69
70 return attributeKeys
71 }
72
73 getFileAttributes () {
74 return [
75 'id',
76 'createdAt',
77 'updatedAt',
78 'resolution',
79 'size',
80 'extname',
81 'filename',
82 'fileUrl',
83 'torrentFilename',
84 'torrentUrl',
85 'infoHash',
86 'fps',
87 'metadataUrl',
88 'videoStreamingPlaylistId',
89 'videoId'
90 ]
91 }
92
93 getStreamingPlaylistAttributes () {
94 let playlistKeys = [ 'id', 'playlistUrl', 'type' ]
95
96 if (this.mode === 'get') {
97 playlistKeys = playlistKeys.concat([
98 'p2pMediaLoaderInfohashes',
99 'p2pMediaLoaderPeerVersion',
100 'segmentsSha256Url',
101 'videoId',
102 'createdAt',
103 'updatedAt'
104 ])
105 }
106
107 return playlistKeys
108 }
109
110 getUserHistoryAttributes () {
111 return [ 'id', 'currentTime' ]
112 }
113
114 getPlaylistAttributes () {
115 return [
116 'createdAt',
117 'updatedAt',
118 'url',
119 'position',
120 'startTimestamp',
121 'stopTimestamp',
122 'videoPlaylistId'
123 ]
124 }
125
126 getTagAttributes () {
127 return [ 'id', 'name' ]
128 }
129
130 getVideoTagAttributes () {
131 return [ 'videoId', 'tagId', 'createdAt', 'updatedAt' ]
132 }
133
134 getBlacklistedAttributes () {
135 return [ 'id', 'reason', 'unfederated' ]
136 }
137
138 getScheduleUpdateAttributes () {
139 return [
140 'id',
141 'updateAt',
142 'privacy',
143 'videoId',
144 'createdAt',
145 'updatedAt'
146 ]
147 }
148
149 getLiveAttributes () {
150 return [
151 'id',
152 'streamKey',
153 'saveReplay',
154 'permanentLive',
155 'videoId',
156 'createdAt',
157 'updatedAt'
158 ]
159 }
160
161 getTrackerAttributes () {
162 return [ 'id', 'url' ]
163 }
164
165 getVideoTrackerAttributes () {
166 return [
167 'videoId',
168 'trackerId',
169 'createdAt',
170 'updatedAt'
171 ]
172 }
173
174 getRedundancyAttributes () {
175 return [ 'id', 'fileUrl' ]
176 }
177
178 getActorAttributes () {
179 let attributeKeys = [
180 'id',
181 'preferredUsername',
182 'url',
183 'serverId',
184 'avatarId'
185 ]
186
187 if (this.mode === 'get') {
188 attributeKeys = attributeKeys.concat([
189 'type',
190 'followersCount',
191 'followingCount',
192 'inboxUrl',
193 'outboxUrl',
194 'sharedInboxUrl',
195 'followersUrl',
196 'followingUrl',
197 'remoteCreatedAt',
198 'createdAt',
199 'updatedAt'
200 ])
201 }
202
203 return attributeKeys
204 }
205
206 getAvatarAttributes () {
207 let attributeKeys = [
208 'id',
209 'filename',
210 'type',
211 'fileUrl',
212 'onDisk',
213 'createdAt',
214 'updatedAt'
215 ]
216
217 if (this.mode === 'get') {
218 attributeKeys = attributeKeys.concat([
219 'height',
220 'width',
221 'type'
222 ])
223 }
224
225 return attributeKeys
226 }
227
228 getServerAttributes () {
229 return [ 'id', 'host' ]
230 }
231
232 getVideoAttributes () {
233 return [
234 'id',
235 'uuid',
236 'name',
237 'category',
238 'licence',
239 'language',
240 'privacy',
241 'nsfw',
242 'description',
243 'support',
244 'duration',
245 'views',
246 'likes',
247 'dislikes',
248 'remote',
249 'isLive',
250 'url',
251 'commentsEnabled',
252 'downloadEnabled',
253 'waitTranscoding',
254 'state',
255 'publishedAt',
256 'originallyPublishedAt',
257 'channelId',
258 'createdAt',
259 'updatedAt'
260 ]
261 }
262 }