aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/sql/shared/video-model-builder.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/sql/shared/video-model-builder.ts')
-rw-r--r--server/models/video/sql/shared/video-model-builder.ts72
1 files changed, 63 insertions, 9 deletions
diff --git a/server/models/video/sql/shared/video-model-builder.ts b/server/models/video/sql/shared/video-model-builder.ts
index 33a0181e9..0eac95661 100644
--- a/server/models/video/sql/shared/video-model-builder.ts
+++ b/server/models/video/sql/shared/video-model-builder.ts
@@ -1,11 +1,14 @@
1 1
2import { AccountModel } from '@server/models/account/account' 2import { AccountModel } from '@server/models/account/account'
3import { AccountBlocklistModel } from '@server/models/account/account-blocklist'
3import { ActorModel } from '@server/models/actor/actor' 4import { ActorModel } from '@server/models/actor/actor'
4import { ActorImageModel } from '@server/models/actor/actor-image' 5import { ActorImageModel } from '@server/models/actor/actor-image'
5import { VideoRedundancyModel } from '@server/models/redundancy/video-redundancy' 6import { VideoRedundancyModel } from '@server/models/redundancy/video-redundancy'
6import { ServerModel } from '@server/models/server/server' 7import { ServerModel } from '@server/models/server/server'
8import { ServerBlocklistModel } from '@server/models/server/server-blocklist'
7import { TrackerModel } from '@server/models/server/tracker' 9import { TrackerModel } from '@server/models/server/tracker'
8import { UserVideoHistoryModel } from '@server/models/user/user-video-history' 10import { UserVideoHistoryModel } from '@server/models/user/user-video-history'
11import { VideoInclude } from '@shared/models'
9import { ScheduleVideoUpdateModel } from '../../schedule-video-update' 12import { ScheduleVideoUpdateModel } from '../../schedule-video-update'
10import { TagModel } from '../../tag' 13import { TagModel } from '../../tag'
11import { ThumbnailModel } from '../../thumbnail' 14import { ThumbnailModel } from '../../thumbnail'
@@ -33,6 +36,8 @@ export class VideoModelBuilder {
33 private thumbnailsDone: Set<any> 36 private thumbnailsDone: Set<any>
34 private historyDone: Set<any> 37 private historyDone: Set<any>
35 private blacklistDone: Set<any> 38 private blacklistDone: Set<any>
39 private accountBlocklistDone: Set<any>
40 private serverBlocklistDone: Set<any>
36 private liveDone: Set<any> 41 private liveDone: Set<any>
37 private redundancyDone: Set<any> 42 private redundancyDone: Set<any>
38 private scheduleVideoUpdateDone: Set<any> 43 private scheduleVideoUpdateDone: Set<any>
@@ -51,7 +56,14 @@ export class VideoModelBuilder {
51 56
52 } 57 }
53 58
54 buildVideosFromRows (rows: SQLRow[], rowsWebTorrentFiles?: SQLRow[], rowsStreamingPlaylist?: SQLRow[]) { 59 buildVideosFromRows (options: {
60 rows: SQLRow[]
61 include?: VideoInclude
62 rowsWebTorrentFiles?: SQLRow[]
63 rowsStreamingPlaylist?: SQLRow[]
64 }) {
65 const { rows, rowsWebTorrentFiles, rowsStreamingPlaylist, include } = options
66
55 this.reinit() 67 this.reinit()
56 68
57 for (const row of rows) { 69 for (const row of rows) {
@@ -77,6 +89,15 @@ export class VideoModelBuilder {
77 this.setBlacklisted(row, videoModel) 89 this.setBlacklisted(row, videoModel)
78 this.setScheduleVideoUpdate(row, videoModel) 90 this.setScheduleVideoUpdate(row, videoModel)
79 this.setLive(row, videoModel) 91 this.setLive(row, videoModel)
92 } else {
93 if (include & VideoInclude.BLACKLISTED) {
94 this.setBlacklisted(row, videoModel)
95 }
96
97 if (include & VideoInclude.BLOCKED_OWNER) {
98 this.setBlockedOwner(row, videoModel)
99 this.setBlockedServer(row, videoModel)
100 }
80 } 101 }
81 } 102 }
82 103
@@ -91,15 +112,18 @@ export class VideoModelBuilder {
91 this.videoStreamingPlaylistMemo = {} 112 this.videoStreamingPlaylistMemo = {}
92 this.videoFileMemo = {} 113 this.videoFileMemo = {}
93 114
94 this.thumbnailsDone = new Set<number>() 115 this.thumbnailsDone = new Set()
95 this.historyDone = new Set<number>() 116 this.historyDone = new Set()
96 this.blacklistDone = new Set<number>() 117 this.blacklistDone = new Set()
97 this.liveDone = new Set<number>() 118 this.liveDone = new Set()
98 this.redundancyDone = new Set<number>() 119 this.redundancyDone = new Set()
99 this.scheduleVideoUpdateDone = new Set<number>() 120 this.scheduleVideoUpdateDone = new Set()
121
122 this.accountBlocklistDone = new Set()
123 this.serverBlocklistDone = new Set()
100 124
101 this.trackersDone = new Set<string>() 125 this.trackersDone = new Set()
102 this.tagsDone = new Set<string>() 126 this.tagsDone = new Set()
103 127
104 this.videos = [] 128 this.videos = []
105 } 129 }
@@ -162,6 +186,8 @@ export class VideoModelBuilder {
162 const accountModel = new AccountModel(this.grab(row, this.tables.getAccountAttributes(), 'VideoChannel.Account'), this.buildOpts) 186 const accountModel = new AccountModel(this.grab(row, this.tables.getAccountAttributes(), 'VideoChannel.Account'), this.buildOpts)
163 accountModel.Actor = this.buildActor(row, 'VideoChannel.Account') 187 accountModel.Actor = this.buildActor(row, 'VideoChannel.Account')
164 188
189 accountModel.BlockedBy = []
190
165 channelModel.Account = accountModel 191 channelModel.Account = accountModel
166 192
167 videoModel.VideoChannel = channelModel 193 videoModel.VideoChannel = channelModel
@@ -180,6 +206,8 @@ export class VideoModelBuilder {
180 ? new ServerModel(this.grab(row, this.tables.getServerAttributes(), serverPrefix), this.buildOpts) 206 ? new ServerModel(this.grab(row, this.tables.getServerAttributes(), serverPrefix), this.buildOpts)
181 : null 207 : null
182 208
209 if (serverModel) serverModel.BlockedBy = []
210
183 const actorModel = new ActorModel(this.grab(row, this.tables.getActorAttributes(), actorPrefix), this.buildOpts) 211 const actorModel = new ActorModel(this.grab(row, this.tables.getActorAttributes(), actorPrefix), this.buildOpts)
184 actorModel.Avatar = avatarModel 212 actorModel.Avatar = avatarModel
185 actorModel.Server = serverModel 213 actorModel.Server = serverModel
@@ -297,6 +325,32 @@ export class VideoModelBuilder {
297 this.blacklistDone.add(id) 325 this.blacklistDone.add(id)
298 } 326 }
299 327
328 private setBlockedOwner (row: SQLRow, videoModel: VideoModel) {
329 const id = row['VideoChannel.Account.AccountBlocklist.id']
330 if (!id) return
331
332 const key = `${videoModel.id}-${id}`
333 if (this.accountBlocklistDone.has(key)) return
334
335 const attributes = this.grab(row, this.tables.getBlocklistAttributes(), 'VideoChannel.Account.AccountBlocklist')
336 videoModel.VideoChannel.Account.BlockedBy.push(new AccountBlocklistModel(attributes, this.buildOpts))
337
338 this.accountBlocklistDone.add(key)
339 }
340
341 private setBlockedServer (row: SQLRow, videoModel: VideoModel) {
342 const id = row['VideoChannel.Account.Actor.Server.ServerBlocklist.id']
343 if (!id || this.serverBlocklistDone.has(id)) return
344
345 const key = `${videoModel.id}-${id}`
346 if (this.serverBlocklistDone.has(key)) return
347
348 const attributes = this.grab(row, this.tables.getBlocklistAttributes(), 'VideoChannel.Account.Actor.Server.ServerBlocklist')
349 videoModel.VideoChannel.Account.Actor.Server.BlockedBy.push(new ServerBlocklistModel(attributes, this.buildOpts))
350
351 this.serverBlocklistDone.add(key)
352 }
353
300 private setScheduleVideoUpdate (row: SQLRow, videoModel: VideoModel) { 354 private setScheduleVideoUpdate (row: SQLRow, videoModel: VideoModel) {
301 const id = row['ScheduleVideoUpdate.id'] 355 const id = row['ScheduleVideoUpdate.id']
302 if (!id || this.scheduleVideoUpdateDone.has(id)) return 356 if (!id || this.scheduleVideoUpdateDone.has(id)) return