diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/account/account.ts | 2 | ||||
-rw-r--r-- | server/models/user/user-video-history.ts | 1 | ||||
-rw-r--r-- | server/models/video/formatter/video-format-utils.ts | 32 | ||||
-rw-r--r-- | server/models/video/sql/video-model-get-query-builder.ts | 6 | ||||
-rw-r--r-- | server/models/video/sql/videos-id-list-query-builder.ts | 4 | ||||
-rw-r--r-- | server/models/video/sql/videos-model-list-query-builder.ts | 2 | ||||
-rw-r--r-- | server/models/video/video.ts | 34 |
7 files changed, 43 insertions, 38 deletions
diff --git a/server/models/account/account.ts b/server/models/account/account.ts index 056ec6857..71a9b8ccb 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts | |||
@@ -99,7 +99,7 @@ export type SummaryOptions = { | |||
99 | queryInclude.push({ | 99 | queryInclude.push({ |
100 | attributes: [ 'id' ], | 100 | attributes: [ 'id' ], |
101 | model: AccountBlocklistModel.unscoped(), | 101 | model: AccountBlocklistModel.unscoped(), |
102 | as: 'BlockedAccounts', | 102 | as: 'BlockedBy', |
103 | required: false, | 103 | required: false, |
104 | where: { | 104 | where: { |
105 | accountId: { | 105 | accountId: { |
diff --git a/server/models/user/user-video-history.ts b/server/models/user/user-video-history.ts index d633cc9d5..1aefdf02b 100644 --- a/server/models/user/user-video-history.ts +++ b/server/models/user/user-video-history.ts | |||
@@ -70,7 +70,6 @@ export class UserVideoHistoryModel extends Model<Partial<AttributesOnly<UserVide | |||
70 | actorId: serverActor.id, | 70 | actorId: serverActor.id, |
71 | orLocalVideos: true | 71 | orLocalVideos: true |
72 | }, | 72 | }, |
73 | withFiles: false, | ||
74 | user, | 73 | user, |
75 | historyOfUser: user | 74 | historyOfUser: user |
76 | }) | 75 | }) |
diff --git a/server/models/video/formatter/video-format-utils.ts b/server/models/video/formatter/video-format-utils.ts index 5dc2c2f1b..ba49e41ae 100644 --- a/server/models/video/formatter/video-format-utils.ts +++ b/server/models/video/formatter/video-format-utils.ts | |||
@@ -42,6 +42,7 @@ export type VideoFormattingJSONOptions = { | |||
42 | waitTranscoding?: boolean | 42 | waitTranscoding?: boolean |
43 | scheduledUpdate?: boolean | 43 | scheduledUpdate?: boolean |
44 | blacklistInfo?: boolean | 44 | blacklistInfo?: boolean |
45 | files?: boolean | ||
45 | blockedOwner?: boolean | 46 | blockedOwner?: boolean |
46 | } | 47 | } |
47 | } | 48 | } |
@@ -55,6 +56,7 @@ function guessAdditionalAttributesFromQuery (query: VideosCommonQueryAfterSaniti | |||
55 | waitTranscoding: !!(query.include & VideoInclude.NOT_PUBLISHED_STATE), | 56 | waitTranscoding: !!(query.include & VideoInclude.NOT_PUBLISHED_STATE), |
56 | scheduledUpdate: !!(query.include & VideoInclude.NOT_PUBLISHED_STATE), | 57 | scheduledUpdate: !!(query.include & VideoInclude.NOT_PUBLISHED_STATE), |
57 | blacklistInfo: !!(query.include & VideoInclude.BLACKLISTED), | 58 | blacklistInfo: !!(query.include & VideoInclude.BLACKLISTED), |
59 | files: !!(query.include & VideoInclude.FILES), | ||
58 | blockedOwner: !!(query.include & VideoInclude.BLOCKED_OWNER) | 60 | blockedOwner: !!(query.include & VideoInclude.BLOCKED_OWNER) |
59 | } | 61 | } |
60 | } | 62 | } |
@@ -150,22 +152,26 @@ function videoModelToFormattedJSON (video: MVideoFormattable, options: VideoForm | |||
150 | videoObject.blockedServer = !!(server?.isBlocked()) | 152 | videoObject.blockedServer = !!(server?.isBlocked()) |
151 | } | 153 | } |
152 | 154 | ||
155 | if (add?.files === true) { | ||
156 | videoObject.streamingPlaylists = streamingPlaylistsModelToFormattedJSON(video, video.VideoStreamingPlaylists) | ||
157 | videoObject.files = videoFilesModelToFormattedJSON(video, video.VideoFiles) | ||
158 | } | ||
159 | |||
153 | return videoObject | 160 | return videoObject |
154 | } | 161 | } |
155 | 162 | ||
156 | function videoModelToFormattedDetailsJSON (video: MVideoFormattableDetails): VideoDetails { | 163 | function videoModelToFormattedDetailsJSON (video: MVideoFormattableDetails): VideoDetails { |
157 | const formattedJson = video.toFormattedJSON({ | 164 | const videoJSON = video.toFormattedJSON({ |
158 | additionalAttributes: { | 165 | additionalAttributes: { |
159 | scheduledUpdate: true, | 166 | scheduledUpdate: true, |
160 | blacklistInfo: true | 167 | blacklistInfo: true, |
168 | files: true | ||
161 | } | 169 | } |
162 | }) | 170 | }) as Video & Required<Pick<Video, 'files' | 'streamingPlaylists'>> |
163 | 171 | ||
164 | const tags = video.Tags ? video.Tags.map(t => t.name) : [] | 172 | const tags = video.Tags ? video.Tags.map(t => t.name) : [] |
165 | 173 | ||
166 | const streamingPlaylists = streamingPlaylistsModelToFormattedJSON(video, video.VideoStreamingPlaylists) | 174 | const detailsJSON = { |
167 | |||
168 | const detailsJson = { | ||
169 | support: video.support, | 175 | support: video.support, |
170 | descriptionPath: video.getDescriptionAPIPath(), | 176 | descriptionPath: video.getDescriptionAPIPath(), |
171 | channel: video.VideoChannel.toFormattedJSON(), | 177 | channel: video.VideoChannel.toFormattedJSON(), |
@@ -179,20 +185,14 @@ function videoModelToFormattedDetailsJSON (video: MVideoFormattableDetails): Vid | |||
179 | label: getStateLabel(video.state) | 185 | label: getStateLabel(video.state) |
180 | }, | 186 | }, |
181 | 187 | ||
182 | trackerUrls: video.getTrackerUrls(), | 188 | trackerUrls: video.getTrackerUrls() |
183 | |||
184 | files: [], | ||
185 | streamingPlaylists | ||
186 | } | 189 | } |
187 | 190 | ||
188 | // Format and sort video files | 191 | return Object.assign(videoJSON, detailsJSON) |
189 | detailsJson.files = videoFilesModelToFormattedJSON(video, video.VideoFiles) | ||
190 | |||
191 | return Object.assign(formattedJson, detailsJson) | ||
192 | } | 192 | } |
193 | 193 | ||
194 | function streamingPlaylistsModelToFormattedJSON ( | 194 | function streamingPlaylistsModelToFormattedJSON ( |
195 | video: MVideoFormattableDetails, | 195 | video: MVideoFormattable, |
196 | playlists: MStreamingPlaylistRedundanciesOpt[] | 196 | playlists: MStreamingPlaylistRedundanciesOpt[] |
197 | ): VideoStreamingPlaylist[] { | 197 | ): VideoStreamingPlaylist[] { |
198 | if (isArray(playlists) === false) return [] | 198 | if (isArray(playlists) === false) return [] |
@@ -223,7 +223,7 @@ function sortByResolutionDesc (fileA: MVideoFile, fileB: MVideoFile) { | |||
223 | } | 223 | } |
224 | 224 | ||
225 | function videoFilesModelToFormattedJSON ( | 225 | function videoFilesModelToFormattedJSON ( |
226 | video: MVideoFormattableDetails, | 226 | video: MVideoFormattable, |
227 | videoFiles: MVideoFileRedundanciesOpt[], | 227 | videoFiles: MVideoFileRedundanciesOpt[], |
228 | includeMagnet = true | 228 | includeMagnet = true |
229 | ): VideoFile[] { | 229 | ): VideoFile[] { |
diff --git a/server/models/video/sql/video-model-get-query-builder.ts b/server/models/video/sql/video-model-get-query-builder.ts index d18ddae67..2f34d5602 100644 --- a/server/models/video/sql/video-model-get-query-builder.ts +++ b/server/models/video/sql/video-model-get-query-builder.ts | |||
@@ -32,7 +32,7 @@ export type BuildVideoGetQueryOptions = { | |||
32 | logging?: boolean | 32 | logging?: boolean |
33 | } | 33 | } |
34 | 34 | ||
35 | export class VideosModelGetQueryBuilder { | 35 | export class VideoModelGetQueryBuilder { |
36 | videoQueryBuilder: VideosModelGetQuerySubBuilder | 36 | videoQueryBuilder: VideosModelGetQuerySubBuilder |
37 | webtorrentFilesQueryBuilder: VideoFileQueryBuilder | 37 | webtorrentFilesQueryBuilder: VideoFileQueryBuilder |
38 | streamingPlaylistFilesQueryBuilder: VideoFileQueryBuilder | 38 | streamingPlaylistFilesQueryBuilder: VideoFileQueryBuilder |
@@ -53,11 +53,11 @@ export class VideosModelGetQueryBuilder { | |||
53 | const [ videoRows, webtorrentFilesRows, streamingPlaylistFilesRows ] = await Promise.all([ | 53 | const [ videoRows, webtorrentFilesRows, streamingPlaylistFilesRows ] = await Promise.all([ |
54 | this.videoQueryBuilder.queryVideos(options), | 54 | this.videoQueryBuilder.queryVideos(options), |
55 | 55 | ||
56 | VideosModelGetQueryBuilder.videoFilesInclude.has(options.type) | 56 | VideoModelGetQueryBuilder.videoFilesInclude.has(options.type) |
57 | ? this.webtorrentFilesQueryBuilder.queryWebTorrentVideos(options) | 57 | ? this.webtorrentFilesQueryBuilder.queryWebTorrentVideos(options) |
58 | : Promise.resolve(undefined), | 58 | : Promise.resolve(undefined), |
59 | 59 | ||
60 | VideosModelGetQueryBuilder.videoFilesInclude.has(options.type) | 60 | VideoModelGetQueryBuilder.videoFilesInclude.has(options.type) |
61 | ? this.streamingPlaylistFilesQueryBuilder.queryStreamingPlaylistVideos(options) | 61 | ? this.streamingPlaylistFilesQueryBuilder.queryStreamingPlaylistVideos(options) |
62 | : Promise.resolve(undefined) | 62 | : Promise.resolve(undefined) |
63 | ]) | 63 | ]) |
diff --git a/server/models/video/sql/videos-id-list-query-builder.ts b/server/models/video/sql/videos-id-list-query-builder.ts index 3eb547e75..4d6e0ea4b 100644 --- a/server/models/video/sql/videos-id-list-query-builder.ts +++ b/server/models/video/sql/videos-id-list-query-builder.ts | |||
@@ -43,7 +43,7 @@ export type BuildVideosListQueryOptions = { | |||
43 | 43 | ||
44 | uuids?: string[] | 44 | uuids?: string[] |
45 | 45 | ||
46 | withFiles?: boolean | 46 | hasFiles?: boolean |
47 | 47 | ||
48 | accountId?: number | 48 | accountId?: number |
49 | videoChannelId?: number | 49 | videoChannelId?: number |
@@ -165,7 +165,7 @@ export class VideosIdListQueryBuilder extends AbstractVideosQueryBuilder { | |||
165 | this.whereFollowerActorId(options.displayOnlyForFollower) | 165 | this.whereFollowerActorId(options.displayOnlyForFollower) |
166 | } | 166 | } |
167 | 167 | ||
168 | if (options.withFiles === true) { | 168 | if (options.hasFiles === true) { |
169 | this.whereFileExists() | 169 | this.whereFileExists() |
170 | } | 170 | } |
171 | 171 | ||
diff --git a/server/models/video/sql/videos-model-list-query-builder.ts b/server/models/video/sql/videos-model-list-query-builder.ts index ef92bd2b0..cd721f055 100644 --- a/server/models/video/sql/videos-model-list-query-builder.ts +++ b/server/models/video/sql/videos-model-list-query-builder.ts | |||
@@ -52,7 +52,7 @@ export class VideosModelListQueryBuilder extends AbstractVideosModelQueryBuilder | |||
52 | this.includeAccounts() | 52 | this.includeAccounts() |
53 | this.includeThumbnails() | 53 | this.includeThumbnails() |
54 | 54 | ||
55 | if (options.withFiles) { | 55 | if (options.include & VideoInclude.FILES) { |
56 | this.includeWebtorrentFiles() | 56 | this.includeWebtorrentFiles() |
57 | this.includeStreamingPlaylistFiles() | 57 | this.includeStreamingPlaylistFiles() |
58 | } | 58 | } |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 26be34329..f9618c102 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -105,7 +105,7 @@ import { | |||
105 | videoModelToFormattedJSON | 105 | videoModelToFormattedJSON |
106 | } from './formatter/video-format-utils' | 106 | } from './formatter/video-format-utils' |
107 | import { ScheduleVideoUpdateModel } from './schedule-video-update' | 107 | import { ScheduleVideoUpdateModel } from './schedule-video-update' |
108 | import { VideosModelGetQueryBuilder } from './sql/video-model-get-query-builder' | 108 | import { VideoModelGetQueryBuilder } from './sql/video-model-get-query-builder' |
109 | import { BuildVideosListQueryOptions, DisplayOnlyForFollowerOptions, VideosIdListQueryBuilder } from './sql/videos-id-list-query-builder' | 109 | import { BuildVideosListQueryOptions, DisplayOnlyForFollowerOptions, VideosIdListQueryBuilder } from './sql/videos-id-list-query-builder' |
110 | import { VideosModelListQueryBuilder } from './sql/videos-model-list-query-builder' | 110 | import { VideosModelListQueryBuilder } from './sql/videos-model-list-query-builder' |
111 | import { TagModel } from './tag' | 111 | import { TagModel } from './tag' |
@@ -1029,7 +1029,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1029 | isLocal?: boolean | 1029 | isLocal?: boolean |
1030 | include?: VideoInclude | 1030 | include?: VideoInclude |
1031 | 1031 | ||
1032 | withFiles: boolean | 1032 | hasFiles?: boolean // default false |
1033 | 1033 | ||
1034 | categoryOneOf?: number[] | 1034 | categoryOneOf?: number[] |
1035 | licenceOneOf?: number[] | 1035 | licenceOneOf?: number[] |
@@ -1053,7 +1053,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1053 | 1053 | ||
1054 | search?: string | 1054 | search?: string |
1055 | }) { | 1055 | }) { |
1056 | if (options.include && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) { | 1056 | if (VideoModel.isPrivateInclude(options.include) && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) { |
1057 | throw new Error('Try to filter all-local but no user has not the see all videos right') | 1057 | throw new Error('Try to filter all-local but no user has not the see all videos right') |
1058 | } | 1058 | } |
1059 | 1059 | ||
@@ -1082,7 +1082,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1082 | 'isLocal', | 1082 | 'isLocal', |
1083 | 'include', | 1083 | 'include', |
1084 | 'displayOnlyForFollower', | 1084 | 'displayOnlyForFollower', |
1085 | 'withFiles', | 1085 | 'hasFiles', |
1086 | 'accountId', | 1086 | 'accountId', |
1087 | 'videoChannelId', | 1087 | 'videoChannelId', |
1088 | 'videoPlaylistId', | 1088 | 'videoPlaylistId', |
@@ -1229,13 +1229,13 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1229 | } | 1229 | } |
1230 | 1230 | ||
1231 | static load (id: number | string, transaction?: Transaction): Promise<MVideoThumbnail> { | 1231 | static load (id: number | string, transaction?: Transaction): Promise<MVideoThumbnail> { |
1232 | const queryBuilder = new VideosModelGetQueryBuilder(VideoModel.sequelize) | 1232 | const queryBuilder = new VideoModelGetQueryBuilder(VideoModel.sequelize) |
1233 | 1233 | ||
1234 | return queryBuilder.queryVideo({ id, transaction, type: 'thumbnails' }) | 1234 | return queryBuilder.queryVideo({ id, transaction, type: 'thumbnails' }) |
1235 | } | 1235 | } |
1236 | 1236 | ||
1237 | static loadWithBlacklist (id: number | string, transaction?: Transaction): Promise<MVideoThumbnailBlacklist> { | 1237 | static loadWithBlacklist (id: number | string, transaction?: Transaction): Promise<MVideoThumbnailBlacklist> { |
1238 | const queryBuilder = new VideosModelGetQueryBuilder(VideoModel.sequelize) | 1238 | const queryBuilder = new VideoModelGetQueryBuilder(VideoModel.sequelize) |
1239 | 1239 | ||
1240 | return queryBuilder.queryVideo({ id, transaction, type: 'thumbnails-blacklist' }) | 1240 | return queryBuilder.queryVideo({ id, transaction, type: 'thumbnails-blacklist' }) |
1241 | } | 1241 | } |
@@ -1279,31 +1279,31 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1279 | } | 1279 | } |
1280 | 1280 | ||
1281 | static loadOnlyId (id: number | string, transaction?: Transaction): Promise<MVideoId> { | 1281 | static loadOnlyId (id: number | string, transaction?: Transaction): Promise<MVideoId> { |
1282 | const queryBuilder = new VideosModelGetQueryBuilder(VideoModel.sequelize) | 1282 | const queryBuilder = new VideoModelGetQueryBuilder(VideoModel.sequelize) |
1283 | 1283 | ||
1284 | return queryBuilder.queryVideo({ id, transaction, type: 'id' }) | 1284 | return queryBuilder.queryVideo({ id, transaction, type: 'id' }) |
1285 | } | 1285 | } |
1286 | 1286 | ||
1287 | static loadWithFiles (id: number | string, transaction?: Transaction, logging?: boolean): Promise<MVideoWithAllFiles> { | 1287 | static loadWithFiles (id: number | string, transaction?: Transaction, logging?: boolean): Promise<MVideoWithAllFiles> { |
1288 | const queryBuilder = new VideosModelGetQueryBuilder(VideoModel.sequelize) | 1288 | const queryBuilder = new VideoModelGetQueryBuilder(VideoModel.sequelize) |
1289 | 1289 | ||
1290 | return queryBuilder.queryVideo({ id, transaction, type: 'all-files', logging }) | 1290 | return queryBuilder.queryVideo({ id, transaction, type: 'all-files', logging }) |
1291 | } | 1291 | } |
1292 | 1292 | ||
1293 | static loadByUrl (url: string, transaction?: Transaction): Promise<MVideoThumbnail> { | 1293 | static loadByUrl (url: string, transaction?: Transaction): Promise<MVideoThumbnail> { |
1294 | const queryBuilder = new VideosModelGetQueryBuilder(VideoModel.sequelize) | 1294 | const queryBuilder = new VideoModelGetQueryBuilder(VideoModel.sequelize) |
1295 | 1295 | ||
1296 | return queryBuilder.queryVideo({ url, transaction, type: 'thumbnails' }) | 1296 | return queryBuilder.queryVideo({ url, transaction, type: 'thumbnails' }) |
1297 | } | 1297 | } |
1298 | 1298 | ||
1299 | static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Promise<MVideoAccountLightBlacklistAllFiles> { | 1299 | static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Promise<MVideoAccountLightBlacklistAllFiles> { |
1300 | const queryBuilder = new VideosModelGetQueryBuilder(VideoModel.sequelize) | 1300 | const queryBuilder = new VideoModelGetQueryBuilder(VideoModel.sequelize) |
1301 | 1301 | ||
1302 | return queryBuilder.queryVideo({ url, transaction, type: 'account-blacklist-files' }) | 1302 | return queryBuilder.queryVideo({ url, transaction, type: 'account-blacklist-files' }) |
1303 | } | 1303 | } |
1304 | 1304 | ||
1305 | static loadAndPopulateAccountAndServerAndTags (id: number | string, t?: Transaction, userId?: number): Promise<MVideoFullLight> { | 1305 | static loadAndPopulateAccountAndServerAndTags (id: number | string, t?: Transaction, userId?: number): Promise<MVideoFullLight> { |
1306 | const queryBuilder = new VideosModelGetQueryBuilder(VideoModel.sequelize) | 1306 | const queryBuilder = new VideoModelGetQueryBuilder(VideoModel.sequelize) |
1307 | 1307 | ||
1308 | return queryBuilder.queryVideo({ id, transaction: t, type: 'full-light', userId }) | 1308 | return queryBuilder.queryVideo({ id, transaction: t, type: 'full-light', userId }) |
1309 | } | 1309 | } |
@@ -1314,7 +1314,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1314 | userId?: number | 1314 | userId?: number |
1315 | }): Promise<MVideoDetails> { | 1315 | }): Promise<MVideoDetails> { |
1316 | const { id, transaction, userId } = parameters | 1316 | const { id, transaction, userId } = parameters |
1317 | const queryBuilder = new VideosModelGetQueryBuilder(VideoModel.sequelize) | 1317 | const queryBuilder = new VideoModelGetQueryBuilder(VideoModel.sequelize) |
1318 | 1318 | ||
1319 | return queryBuilder.queryVideo({ id, transaction, type: 'api', userId }) | 1319 | return queryBuilder.queryVideo({ id, transaction, type: 'api', userId }) |
1320 | } | 1320 | } |
@@ -1345,8 +1345,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1345 | displayOnlyForFollower: { | 1345 | displayOnlyForFollower: { |
1346 | actorId: serverActor.id, | 1346 | actorId: serverActor.id, |
1347 | orLocalVideos: true | 1347 | orLocalVideos: true |
1348 | }, | 1348 | } |
1349 | withFiles: false | ||
1350 | }) | 1349 | }) |
1351 | 1350 | ||
1352 | return { | 1351 | return { |
@@ -1490,6 +1489,13 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1490 | } | 1489 | } |
1491 | } | 1490 | } |
1492 | 1491 | ||
1492 | private static isPrivateInclude (include: VideoInclude) { | ||
1493 | return include & VideoInclude.BLACKLISTED || | ||
1494 | include & VideoInclude.BLOCKED_OWNER || | ||
1495 | include & VideoInclude.HIDDEN_PRIVACY || | ||
1496 | include & VideoInclude.NOT_PUBLISHED_STATE | ||
1497 | } | ||
1498 | |||
1493 | isBlacklisted () { | 1499 | isBlacklisted () { |
1494 | return !!this.VideoBlacklist | 1500 | return !!this.VideoBlacklist |
1495 | } | 1501 | } |