diff options
Diffstat (limited to 'server/models')
11 files changed, 75 insertions, 66 deletions
diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts index c2a72b71f..cebf47dfd 100644 --- a/server/models/redundancy/video-redundancy.ts +++ b/server/models/redundancy/video-redundancy.ts | |||
@@ -162,7 +162,7 @@ export class VideoRedundancyModel extends Model<Partial<AttributesOnly<VideoRedu | |||
162 | const logIdentifier = `${videoFile.Video.uuid}-${videoFile.resolution}` | 162 | const logIdentifier = `${videoFile.Video.uuid}-${videoFile.resolution}` |
163 | logger.info('Removing duplicated video file %s.', logIdentifier) | 163 | logger.info('Removing duplicated video file %s.', logIdentifier) |
164 | 164 | ||
165 | videoFile.Video.removeWebTorrentFile(videoFile, true) | 165 | videoFile.Video.removeWebVideoFile(videoFile, true) |
166 | .catch(err => logger.error('Cannot delete %s files.', logIdentifier, { err })) | 166 | .catch(err => logger.error('Cannot delete %s files.', logIdentifier, { err })) |
167 | } | 167 | } |
168 | 168 | ||
diff --git a/server/models/user/user.ts b/server/models/user/user.ts index 4f6a8fce4..ff6328d48 100644 --- a/server/models/user/user.ts +++ b/server/models/user/user.ts | |||
@@ -786,7 +786,7 @@ export class UserModel extends Model<Partial<AttributesOnly<UserModel>>> { | |||
786 | 'INNER JOIN "account" ON "videoChannel"."accountId" = "account"."id" ' + | 786 | 'INNER JOIN "account" ON "videoChannel"."accountId" = "account"."id" ' + |
787 | `WHERE "account"."userId" = ${options.whereUserId} ${andWhere}` | 787 | `WHERE "account"."userId" = ${options.whereUserId} ${andWhere}` |
788 | 788 | ||
789 | const webtorrentFiles = 'SELECT "videoFile"."size" AS "size", "video"."id" AS "videoId" FROM "videoFile" ' + | 789 | const webVideoFiles = 'SELECT "videoFile"."size" AS "size", "video"."id" AS "videoId" FROM "videoFile" ' + |
790 | 'INNER JOIN "video" ON "videoFile"."videoId" = "video"."id" AND "video"."isLive" IS FALSE ' + | 790 | 'INNER JOIN "video" ON "videoFile"."videoId" = "video"."id" AND "video"."isLive" IS FALSE ' + |
791 | videoChannelJoin | 791 | videoChannelJoin |
792 | 792 | ||
@@ -797,7 +797,7 @@ export class UserModel extends Model<Partial<AttributesOnly<UserModel>>> { | |||
797 | 797 | ||
798 | return 'SELECT COALESCE(SUM("size"), 0) AS "total" ' + | 798 | return 'SELECT COALESCE(SUM("size"), 0) AS "total" ' + |
799 | 'FROM (' + | 799 | 'FROM (' + |
800 | `SELECT MAX("t1"."size") AS "size" FROM (${webtorrentFiles} UNION ${hlsFiles}) t1 ` + | 800 | `SELECT MAX("t1"."size") AS "size" FROM (${webVideoFiles} UNION ${hlsFiles}) t1 ` + |
801 | 'GROUP BY "t1"."videoId"' + | 801 | 'GROUP BY "t1"."videoId"' + |
802 | ') t2' | 802 | ') t2' |
803 | } | 803 | } |
@@ -890,8 +890,6 @@ export class UserModel extends Model<Partial<AttributesOnly<UserModel>>> { | |||
890 | 890 | ||
891 | nsfwPolicy: this.nsfwPolicy, | 891 | nsfwPolicy: this.nsfwPolicy, |
892 | 892 | ||
893 | // FIXME: deprecated in 4.1 | ||
894 | webTorrentEnabled: this.p2pEnabled, | ||
895 | p2pEnabled: this.p2pEnabled, | 893 | p2pEnabled: this.p2pEnabled, |
896 | 894 | ||
897 | videosHistoryEnabled: this.videosHistoryEnabled, | 895 | videosHistoryEnabled: this.videosHistoryEnabled, |
diff --git a/server/models/video/sql/video/shared/abstract-video-query-builder.ts b/server/models/video/sql/video/shared/abstract-video-query-builder.ts index cbd57ad8c..56a00aa0c 100644 --- a/server/models/video/sql/video/shared/abstract-video-query-builder.ts +++ b/server/models/video/sql/video/shared/abstract-video-query-builder.ts | |||
@@ -111,7 +111,7 @@ export class AbstractVideoQueryBuilder extends AbstractRunQuery { | |||
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | protected includeWebtorrentFiles () { | 114 | protected includeWebVideoFiles () { |
115 | this.addJoin('LEFT JOIN "videoFile" AS "VideoFiles" ON "VideoFiles"."videoId" = "video"."id"') | 115 | this.addJoin('LEFT JOIN "videoFile" AS "VideoFiles" ON "VideoFiles"."videoId" = "video"."id"') |
116 | 116 | ||
117 | this.attributes = { | 117 | this.attributes = { |
@@ -263,7 +263,7 @@ export class AbstractVideoQueryBuilder extends AbstractRunQuery { | |||
263 | } | 263 | } |
264 | } | 264 | } |
265 | 265 | ||
266 | protected includeWebTorrentRedundancies () { | 266 | protected includeWebVideoRedundancies () { |
267 | this.addJoin( | 267 | this.addJoin( |
268 | 'LEFT OUTER JOIN "videoRedundancy" AS "VideoFiles->RedundancyVideos" ON ' + | 268 | 'LEFT OUTER JOIN "videoRedundancy" AS "VideoFiles->RedundancyVideos" ON ' + |
269 | '"VideoFiles"."id" = "VideoFiles->RedundancyVideos"."videoFileId"' | 269 | '"VideoFiles"."id" = "VideoFiles->RedundancyVideos"."videoFileId"' |
diff --git a/server/models/video/sql/video/shared/video-file-query-builder.ts b/server/models/video/sql/video/shared/video-file-query-builder.ts index cc53a4860..196b72b43 100644 --- a/server/models/video/sql/video/shared/video-file-query-builder.ts +++ b/server/models/video/sql/video/shared/video-file-query-builder.ts | |||
@@ -14,7 +14,7 @@ export type FileQueryOptions = { | |||
14 | 14 | ||
15 | /** | 15 | /** |
16 | * | 16 | * |
17 | * Fetch files (webtorrent and streaming playlist) according to a video | 17 | * Fetch files (web videos and streaming playlist) according to a video |
18 | * | 18 | * |
19 | */ | 19 | */ |
20 | 20 | ||
@@ -25,8 +25,8 @@ export class VideoFileQueryBuilder extends AbstractVideoQueryBuilder { | |||
25 | super(sequelize, 'get') | 25 | super(sequelize, 'get') |
26 | } | 26 | } |
27 | 27 | ||
28 | queryWebTorrentVideos (options: FileQueryOptions) { | 28 | queryWebVideos (options: FileQueryOptions) { |
29 | this.buildWebtorrentFilesQuery(options) | 29 | this.buildWebVideoFilesQuery(options) |
30 | 30 | ||
31 | return this.runQuery(options) | 31 | return this.runQuery(options) |
32 | } | 32 | } |
@@ -37,15 +37,15 @@ export class VideoFileQueryBuilder extends AbstractVideoQueryBuilder { | |||
37 | return this.runQuery(options) | 37 | return this.runQuery(options) |
38 | } | 38 | } |
39 | 39 | ||
40 | private buildWebtorrentFilesQuery (options: FileQueryOptions) { | 40 | private buildWebVideoFilesQuery (options: FileQueryOptions) { |
41 | this.attributes = { | 41 | this.attributes = { |
42 | '"video"."id"': '' | 42 | '"video"."id"': '' |
43 | } | 43 | } |
44 | 44 | ||
45 | this.includeWebtorrentFiles() | 45 | this.includeWebVideoFiles() |
46 | 46 | ||
47 | if (options.includeRedundancy) { | 47 | if (options.includeRedundancy) { |
48 | this.includeWebTorrentRedundancies() | 48 | this.includeWebVideoRedundancies() |
49 | } | 49 | } |
50 | 50 | ||
51 | this.whereId(options) | 51 | this.whereId(options) |
diff --git a/server/models/video/sql/video/shared/video-model-builder.ts b/server/models/video/sql/video/shared/video-model-builder.ts index 0a2beb7db..740aa842f 100644 --- a/server/models/video/sql/video/shared/video-model-builder.ts +++ b/server/models/video/sql/video/shared/video-model-builder.ts | |||
@@ -60,10 +60,10 @@ export class VideoModelBuilder { | |||
60 | buildVideosFromRows (options: { | 60 | buildVideosFromRows (options: { |
61 | rows: SQLRow[] | 61 | rows: SQLRow[] |
62 | include?: VideoInclude | 62 | include?: VideoInclude |
63 | rowsWebTorrentFiles?: SQLRow[] | 63 | rowsWebVideoFiles?: SQLRow[] |
64 | rowsStreamingPlaylist?: SQLRow[] | 64 | rowsStreamingPlaylist?: SQLRow[] |
65 | }) { | 65 | }) { |
66 | const { rows, rowsWebTorrentFiles, rowsStreamingPlaylist, include } = options | 66 | const { rows, rowsWebVideoFiles, rowsStreamingPlaylist, include } = options |
67 | 67 | ||
68 | this.reinit() | 68 | this.reinit() |
69 | 69 | ||
@@ -85,8 +85,8 @@ export class VideoModelBuilder { | |||
85 | this.addActorAvatar(row, 'VideoChannel.Account.Actor', accountActor) | 85 | this.addActorAvatar(row, 'VideoChannel.Account.Actor', accountActor) |
86 | } | 86 | } |
87 | 87 | ||
88 | if (!rowsWebTorrentFiles) { | 88 | if (!rowsWebVideoFiles) { |
89 | this.addWebTorrentFile(row, videoModel) | 89 | this.addWebVideoFile(row, videoModel) |
90 | } | 90 | } |
91 | 91 | ||
92 | if (!rowsStreamingPlaylist) { | 92 | if (!rowsStreamingPlaylist) { |
@@ -112,7 +112,7 @@ export class VideoModelBuilder { | |||
112 | } | 112 | } |
113 | } | 113 | } |
114 | 114 | ||
115 | this.grabSeparateWebTorrentFiles(rowsWebTorrentFiles) | 115 | this.grabSeparateWebVideoFiles(rowsWebVideoFiles) |
116 | this.grabSeparateStreamingPlaylistFiles(rowsStreamingPlaylist) | 116 | this.grabSeparateStreamingPlaylistFiles(rowsStreamingPlaylist) |
117 | 117 | ||
118 | return this.videos | 118 | return this.videos |
@@ -140,15 +140,15 @@ export class VideoModelBuilder { | |||
140 | this.videos = [] | 140 | this.videos = [] |
141 | } | 141 | } |
142 | 142 | ||
143 | private grabSeparateWebTorrentFiles (rowsWebTorrentFiles?: SQLRow[]) { | 143 | private grabSeparateWebVideoFiles (rowsWebVideoFiles?: SQLRow[]) { |
144 | if (!rowsWebTorrentFiles) return | 144 | if (!rowsWebVideoFiles) return |
145 | 145 | ||
146 | for (const row of rowsWebTorrentFiles) { | 146 | for (const row of rowsWebVideoFiles) { |
147 | const id = row['VideoFiles.id'] | 147 | const id = row['VideoFiles.id'] |
148 | if (!id) continue | 148 | if (!id) continue |
149 | 149 | ||
150 | const videoModel = this.videosMemo[row.id] | 150 | const videoModel = this.videosMemo[row.id] |
151 | this.addWebTorrentFile(row, videoModel) | 151 | this.addWebVideoFile(row, videoModel) |
152 | this.addRedundancy(row, 'VideoFiles', this.videoFileMemo[id]) | 152 | this.addRedundancy(row, 'VideoFiles', this.videoFileMemo[id]) |
153 | } | 153 | } |
154 | } | 154 | } |
@@ -258,7 +258,7 @@ export class VideoModelBuilder { | |||
258 | this.thumbnailsDone.add(id) | 258 | this.thumbnailsDone.add(id) |
259 | } | 259 | } |
260 | 260 | ||
261 | private addWebTorrentFile (row: SQLRow, videoModel: VideoModel) { | 261 | private addWebVideoFile (row: SQLRow, videoModel: VideoModel) { |
262 | const id = row['VideoFiles.id'] | 262 | const id = row['VideoFiles.id'] |
263 | if (!id || this.videoFileMemo[id]) return | 263 | if (!id || this.videoFileMemo[id]) return |
264 | 264 | ||
diff --git a/server/models/video/sql/video/video-model-get-query-builder.ts b/server/models/video/sql/video/video-model-get-query-builder.ts index 8e90ff641..3f43d4d92 100644 --- a/server/models/video/sql/video/video-model-get-query-builder.ts +++ b/server/models/video/sql/video/video-model-get-query-builder.ts | |||
@@ -35,7 +35,7 @@ export type BuildVideoGetQueryOptions = { | |||
35 | 35 | ||
36 | export class VideoModelGetQueryBuilder { | 36 | export class VideoModelGetQueryBuilder { |
37 | videoQueryBuilder: VideosModelGetQuerySubBuilder | 37 | videoQueryBuilder: VideosModelGetQuerySubBuilder |
38 | webtorrentFilesQueryBuilder: VideoFileQueryBuilder | 38 | webVideoFilesQueryBuilder: VideoFileQueryBuilder |
39 | streamingPlaylistFilesQueryBuilder: VideoFileQueryBuilder | 39 | streamingPlaylistFilesQueryBuilder: VideoFileQueryBuilder |
40 | 40 | ||
41 | private readonly videoModelBuilder: VideoModelBuilder | 41 | private readonly videoModelBuilder: VideoModelBuilder |
@@ -44,7 +44,7 @@ export class VideoModelGetQueryBuilder { | |||
44 | 44 | ||
45 | constructor (protected readonly sequelize: Sequelize) { | 45 | constructor (protected readonly sequelize: Sequelize) { |
46 | this.videoQueryBuilder = new VideosModelGetQuerySubBuilder(sequelize) | 46 | this.videoQueryBuilder = new VideosModelGetQuerySubBuilder(sequelize) |
47 | this.webtorrentFilesQueryBuilder = new VideoFileQueryBuilder(sequelize) | 47 | this.webVideoFilesQueryBuilder = new VideoFileQueryBuilder(sequelize) |
48 | this.streamingPlaylistFilesQueryBuilder = new VideoFileQueryBuilder(sequelize) | 48 | this.streamingPlaylistFilesQueryBuilder = new VideoFileQueryBuilder(sequelize) |
49 | 49 | ||
50 | this.videoModelBuilder = new VideoModelBuilder('get', new VideoTableAttributes('get')) | 50 | this.videoModelBuilder = new VideoModelBuilder('get', new VideoTableAttributes('get')) |
@@ -57,11 +57,11 @@ export class VideoModelGetQueryBuilder { | |||
57 | includeRedundancy: this.shouldIncludeRedundancies(options) | 57 | includeRedundancy: this.shouldIncludeRedundancies(options) |
58 | } | 58 | } |
59 | 59 | ||
60 | const [ videoRows, webtorrentFilesRows, streamingPlaylistFilesRows ] = await Promise.all([ | 60 | const [ videoRows, webVideoFilesRows, streamingPlaylistFilesRows ] = await Promise.all([ |
61 | this.videoQueryBuilder.queryVideos(options), | 61 | this.videoQueryBuilder.queryVideos(options), |
62 | 62 | ||
63 | VideoModelGetQueryBuilder.videoFilesInclude.has(options.type) | 63 | VideoModelGetQueryBuilder.videoFilesInclude.has(options.type) |
64 | ? this.webtorrentFilesQueryBuilder.queryWebTorrentVideos(fileQueryOptions) | 64 | ? this.webVideoFilesQueryBuilder.queryWebVideos(fileQueryOptions) |
65 | : Promise.resolve(undefined), | 65 | : Promise.resolve(undefined), |
66 | 66 | ||
67 | VideoModelGetQueryBuilder.videoFilesInclude.has(options.type) | 67 | VideoModelGetQueryBuilder.videoFilesInclude.has(options.type) |
@@ -71,7 +71,7 @@ export class VideoModelGetQueryBuilder { | |||
71 | 71 | ||
72 | const videos = this.videoModelBuilder.buildVideosFromRows({ | 72 | const videos = this.videoModelBuilder.buildVideosFromRows({ |
73 | rows: videoRows, | 73 | rows: videoRows, |
74 | rowsWebTorrentFiles: webtorrentFilesRows, | 74 | rowsWebVideoFiles: webVideoFilesRows, |
75 | rowsStreamingPlaylist: streamingPlaylistFilesRows | 75 | rowsStreamingPlaylist: streamingPlaylistFilesRows |
76 | }) | 76 | }) |
77 | 77 | ||
@@ -92,7 +92,7 @@ export class VideoModelGetQueryBuilder { | |||
92 | export class VideosModelGetQuerySubBuilder extends AbstractVideoQueryBuilder { | 92 | export class VideosModelGetQuerySubBuilder extends AbstractVideoQueryBuilder { |
93 | protected attributes: { [key: string]: string } | 93 | protected attributes: { [key: string]: string } |
94 | 94 | ||
95 | protected webtorrentFilesQuery: string | 95 | protected webVideoFilesQuery: string |
96 | protected streamingPlaylistFilesQuery: string | 96 | protected streamingPlaylistFilesQuery: string |
97 | 97 | ||
98 | private static readonly trackersInclude = new Set<GetType>([ 'api' ]) | 98 | private static readonly trackersInclude = new Set<GetType>([ 'api' ]) |
diff --git a/server/models/video/sql/video/videos-id-list-query-builder.ts b/server/models/video/sql/video/videos-id-list-query-builder.ts index cba77c1d1..7f2376102 100644 --- a/server/models/video/sql/video/videos-id-list-query-builder.ts +++ b/server/models/video/sql/video/videos-id-list-query-builder.ts | |||
@@ -48,7 +48,9 @@ export type BuildVideosListQueryOptions = { | |||
48 | 48 | ||
49 | hasFiles?: boolean | 49 | hasFiles?: boolean |
50 | hasHLSFiles?: boolean | 50 | hasHLSFiles?: boolean |
51 | hasWebtorrentFiles?: boolean | 51 | |
52 | hasWebVideoFiles?: boolean | ||
53 | hasWebtorrentFiles?: boolean // TODO: Remove in v7 | ||
52 | 54 | ||
53 | accountId?: number | 55 | accountId?: number |
54 | videoChannelId?: number | 56 | videoChannelId?: number |
@@ -175,7 +177,9 @@ export class VideosIdListQueryBuilder extends AbstractRunQuery { | |||
175 | } | 177 | } |
176 | 178 | ||
177 | if (exists(options.hasWebtorrentFiles)) { | 179 | if (exists(options.hasWebtorrentFiles)) { |
178 | this.whereWebTorrentFileExists(options.hasWebtorrentFiles) | 180 | this.whereWebVideoFileExists(options.hasWebtorrentFiles) |
181 | } else if (exists(options.hasWebVideoFiles)) { | ||
182 | this.whereWebVideoFileExists(options.hasWebVideoFiles) | ||
179 | } | 183 | } |
180 | 184 | ||
181 | if (exists(options.hasHLSFiles)) { | 185 | if (exists(options.hasHLSFiles)) { |
@@ -400,18 +404,18 @@ export class VideosIdListQueryBuilder extends AbstractRunQuery { | |||
400 | } | 404 | } |
401 | 405 | ||
402 | private whereFileExists () { | 406 | private whereFileExists () { |
403 | this.and.push(`(${this.buildWebTorrentFileExistsQuery(true)} OR ${this.buildHLSFileExistsQuery(true)})`) | 407 | this.and.push(`(${this.buildWebVideoFileExistsQuery(true)} OR ${this.buildHLSFileExistsQuery(true)})`) |
404 | } | 408 | } |
405 | 409 | ||
406 | private whereWebTorrentFileExists (exists: boolean) { | 410 | private whereWebVideoFileExists (exists: boolean) { |
407 | this.and.push(this.buildWebTorrentFileExistsQuery(exists)) | 411 | this.and.push(this.buildWebVideoFileExistsQuery(exists)) |
408 | } | 412 | } |
409 | 413 | ||
410 | private whereHLSFileExists (exists: boolean) { | 414 | private whereHLSFileExists (exists: boolean) { |
411 | this.and.push(this.buildHLSFileExistsQuery(exists)) | 415 | this.and.push(this.buildHLSFileExistsQuery(exists)) |
412 | } | 416 | } |
413 | 417 | ||
414 | private buildWebTorrentFileExistsQuery (exists: boolean) { | 418 | private buildWebVideoFileExistsQuery (exists: boolean) { |
415 | const prefix = exists ? '' : 'NOT ' | 419 | const prefix = exists ? '' : 'NOT ' |
416 | 420 | ||
417 | return prefix + 'EXISTS (SELECT 1 FROM "videoFile" WHERE "videoFile"."videoId" = "video"."id")' | 421 | return prefix + 'EXISTS (SELECT 1 FROM "videoFile" WHERE "videoFile"."videoId" = "video"."id")' |
diff --git a/server/models/video/sql/video/videos-model-list-query-builder.ts b/server/models/video/sql/video/videos-model-list-query-builder.ts index 3fdac4ed3..b73dc28cd 100644 --- a/server/models/video/sql/video/videos-model-list-query-builder.ts +++ b/server/models/video/sql/video/videos-model-list-query-builder.ts | |||
@@ -18,7 +18,7 @@ export class VideosModelListQueryBuilder extends AbstractVideoQueryBuilder { | |||
18 | private innerQuery: string | 18 | private innerQuery: string |
19 | private innerSort: string | 19 | private innerSort: string |
20 | 20 | ||
21 | webtorrentFilesQueryBuilder: VideoFileQueryBuilder | 21 | webVideoFilesQueryBuilder: VideoFileQueryBuilder |
22 | streamingPlaylistFilesQueryBuilder: VideoFileQueryBuilder | 22 | streamingPlaylistFilesQueryBuilder: VideoFileQueryBuilder |
23 | 23 | ||
24 | private readonly videoModelBuilder: VideoModelBuilder | 24 | private readonly videoModelBuilder: VideoModelBuilder |
@@ -27,7 +27,7 @@ export class VideosModelListQueryBuilder extends AbstractVideoQueryBuilder { | |||
27 | super(sequelize, 'list') | 27 | super(sequelize, 'list') |
28 | 28 | ||
29 | this.videoModelBuilder = new VideoModelBuilder(this.mode, this.tables) | 29 | this.videoModelBuilder = new VideoModelBuilder(this.mode, this.tables) |
30 | this.webtorrentFilesQueryBuilder = new VideoFileQueryBuilder(sequelize) | 30 | this.webVideoFilesQueryBuilder = new VideoFileQueryBuilder(sequelize) |
31 | this.streamingPlaylistFilesQueryBuilder = new VideoFileQueryBuilder(sequelize) | 31 | this.streamingPlaylistFilesQueryBuilder = new VideoFileQueryBuilder(sequelize) |
32 | } | 32 | } |
33 | 33 | ||
@@ -48,12 +48,12 @@ export class VideosModelListQueryBuilder extends AbstractVideoQueryBuilder { | |||
48 | includeRedundancy: false | 48 | includeRedundancy: false |
49 | } | 49 | } |
50 | 50 | ||
51 | const [ rowsWebTorrentFiles, rowsStreamingPlaylist ] = await Promise.all([ | 51 | const [ rowsWebVideoFiles, rowsStreamingPlaylist ] = await Promise.all([ |
52 | this.webtorrentFilesQueryBuilder.queryWebTorrentVideos(fileQueryOptions), | 52 | this.webVideoFilesQueryBuilder.queryWebVideos(fileQueryOptions), |
53 | this.streamingPlaylistFilesQueryBuilder.queryStreamingPlaylistVideos(fileQueryOptions) | 53 | this.streamingPlaylistFilesQueryBuilder.queryStreamingPlaylistVideos(fileQueryOptions) |
54 | ]) | 54 | ]) |
55 | 55 | ||
56 | return this.videoModelBuilder.buildVideosFromRows({ rows, include: options.include, rowsStreamingPlaylist, rowsWebTorrentFiles }) | 56 | return this.videoModelBuilder.buildVideosFromRows({ rows, include: options.include, rowsStreamingPlaylist, rowsWebVideoFiles }) |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
diff --git a/server/models/video/video-change-ownership.ts b/server/models/video/video-change-ownership.ts index 2db4b523a..26f072f4f 100644 --- a/server/models/video/video-change-ownership.ts +++ b/server/models/video/video-change-ownership.ts | |||
@@ -45,7 +45,7 @@ enum ScopeNames { | |||
45 | { | 45 | { |
46 | model: VideoModel.scope([ | 46 | model: VideoModel.scope([ |
47 | VideoScopeNames.WITH_THUMBNAILS, | 47 | VideoScopeNames.WITH_THUMBNAILS, |
48 | VideoScopeNames.WITH_WEBTORRENT_FILES, | 48 | VideoScopeNames.WITH_WEB_VIDEO_FILES, |
49 | VideoScopeNames.WITH_STREAMING_PLAYLISTS, | 49 | VideoScopeNames.WITH_STREAMING_PLAYLISTS, |
50 | VideoScopeNames.WITH_ACCOUNT_DETAILS | 50 | VideoScopeNames.WITH_ACCOUNT_DETAILS |
51 | ]), | 51 | ]), |
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts index 07bc13de1..5e476f3c7 100644 --- a/server/models/video/video-file.ts +++ b/server/models/video/video-file.ts | |||
@@ -26,8 +26,8 @@ import { buildRemoteVideoBaseUrl } from '@server/lib/activitypub/url' | |||
26 | import { | 26 | import { |
27 | getHLSPrivateFileUrl, | 27 | getHLSPrivateFileUrl, |
28 | getHLSPublicFileUrl, | 28 | getHLSPublicFileUrl, |
29 | getWebTorrentPrivateFileUrl, | 29 | getWebVideoPrivateFileUrl, |
30 | getWebTorrentPublicFileUrl | 30 | getWebVideoPublicFileUrl |
31 | } from '@server/lib/object-storage' | 31 | } from '@server/lib/object-storage' |
32 | import { getFSTorrentFilePath } from '@server/lib/paths' | 32 | import { getFSTorrentFilePath } from '@server/lib/paths' |
33 | import { isVideoInPrivateDirectory } from '@server/lib/video-privacy' | 33 | import { isVideoInPrivateDirectory } from '@server/lib/video-privacy' |
@@ -276,15 +276,15 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel> | |||
276 | 276 | ||
277 | static async doesOwnedTorrentFileExist (filename: string) { | 277 | static async doesOwnedTorrentFileExist (filename: string) { |
278 | const query = 'SELECT 1 FROM "videoFile" ' + | 278 | const query = 'SELECT 1 FROM "videoFile" ' + |
279 | 'LEFT JOIN "video" "webtorrent" ON "webtorrent"."id" = "videoFile"."videoId" AND "webtorrent"."remote" IS FALSE ' + | 279 | 'LEFT JOIN "video" "webvideo" ON "webvideo"."id" = "videoFile"."videoId" AND "webvideo"."remote" IS FALSE ' + |
280 | 'LEFT JOIN "videoStreamingPlaylist" ON "videoStreamingPlaylist"."id" = "videoFile"."videoStreamingPlaylistId" ' + | 280 | 'LEFT JOIN "videoStreamingPlaylist" ON "videoStreamingPlaylist"."id" = "videoFile"."videoStreamingPlaylistId" ' + |
281 | 'LEFT JOIN "video" "hlsVideo" ON "hlsVideo"."id" = "videoStreamingPlaylist"."videoId" AND "hlsVideo"."remote" IS FALSE ' + | 281 | 'LEFT JOIN "video" "hlsVideo" ON "hlsVideo"."id" = "videoStreamingPlaylist"."videoId" AND "hlsVideo"."remote" IS FALSE ' + |
282 | 'WHERE "torrentFilename" = $filename AND ("hlsVideo"."id" IS NOT NULL OR "webtorrent"."id" IS NOT NULL) LIMIT 1' | 282 | 'WHERE "torrentFilename" = $filename AND ("hlsVideo"."id" IS NOT NULL OR "webvideo"."id" IS NOT NULL) LIMIT 1' |
283 | 283 | ||
284 | return doesExist(this.sequelize, query, { filename }) | 284 | return doesExist(this.sequelize, query, { filename }) |
285 | } | 285 | } |
286 | 286 | ||
287 | static async doesOwnedWebTorrentVideoFileExist (filename: string) { | 287 | static async doesOwnedWebVideoFileExist (filename: string) { |
288 | const query = 'SELECT 1 FROM "videoFile" INNER JOIN "video" ON "video"."id" = "videoFile"."videoId" AND "video"."remote" IS FALSE ' + | 288 | const query = 'SELECT 1 FROM "videoFile" INNER JOIN "video" ON "video"."id" = "videoFile"."videoId" AND "video"."remote" IS FALSE ' + |
289 | `WHERE "filename" = $filename AND "storage" = ${VideoStorage.FILE_SYSTEM} LIMIT 1` | 289 | `WHERE "filename" = $filename AND "storage" = ${VideoStorage.FILE_SYSTEM} LIMIT 1` |
290 | 290 | ||
@@ -378,7 +378,7 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel> | |||
378 | } | 378 | } |
379 | 379 | ||
380 | static getStats () { | 380 | static getStats () { |
381 | const webtorrentFilesQuery: FindOptions = { | 381 | const webVideoFilesQuery: FindOptions = { |
382 | include: [ | 382 | include: [ |
383 | { | 383 | { |
384 | attributes: [], | 384 | attributes: [], |
@@ -412,10 +412,10 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel> | |||
412 | } | 412 | } |
413 | 413 | ||
414 | return Promise.all([ | 414 | return Promise.all([ |
415 | VideoFileModel.aggregate('size', 'SUM', webtorrentFilesQuery), | 415 | VideoFileModel.aggregate('size', 'SUM', webVideoFilesQuery), |
416 | VideoFileModel.aggregate('size', 'SUM', hlsFilesQuery) | 416 | VideoFileModel.aggregate('size', 'SUM', hlsFilesQuery) |
417 | ]).then(([ webtorrentResult, hlsResult ]) => ({ | 417 | ]).then(([ webVideoResult, hlsResult ]) => ({ |
418 | totalLocalVideoFilesSize: parseAggregateResult(webtorrentResult) + parseAggregateResult(hlsResult) | 418 | totalLocalVideoFilesSize: parseAggregateResult(webVideoResult) + parseAggregateResult(hlsResult) |
419 | })) | 419 | })) |
420 | } | 420 | } |
421 | 421 | ||
@@ -433,7 +433,7 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel> | |||
433 | 433 | ||
434 | const element = mode === 'streaming-playlist' | 434 | const element = mode === 'streaming-playlist' |
435 | ? await VideoFileModel.loadHLSFile({ ...baseFind, playlistId: videoFile.videoStreamingPlaylistId }) | 435 | ? await VideoFileModel.loadHLSFile({ ...baseFind, playlistId: videoFile.videoStreamingPlaylistId }) |
436 | : await VideoFileModel.loadWebTorrentFile({ ...baseFind, videoId: videoFile.videoId }) | 436 | : await VideoFileModel.loadWebVideoFile({ ...baseFind, videoId: videoFile.videoId }) |
437 | 437 | ||
438 | if (!element) return videoFile.save({ transaction }) | 438 | if (!element) return videoFile.save({ transaction }) |
439 | 439 | ||
@@ -444,7 +444,7 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel> | |||
444 | return element.save({ transaction }) | 444 | return element.save({ transaction }) |
445 | } | 445 | } |
446 | 446 | ||
447 | static async loadWebTorrentFile (options: { | 447 | static async loadWebVideoFile (options: { |
448 | videoId: number | 448 | videoId: number |
449 | fps: number | 449 | fps: number |
450 | resolution: number | 450 | resolution: number |
@@ -523,7 +523,7 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel> | |||
523 | return getHLSPrivateFileUrl(video, this.filename) | 523 | return getHLSPrivateFileUrl(video, this.filename) |
524 | } | 524 | } |
525 | 525 | ||
526 | return getWebTorrentPrivateFileUrl(this.filename) | 526 | return getWebVideoPrivateFileUrl(this.filename) |
527 | } | 527 | } |
528 | 528 | ||
529 | private getPublicObjectStorageUrl () { | 529 | private getPublicObjectStorageUrl () { |
@@ -531,7 +531,7 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel> | |||
531 | return getHLSPublicFileUrl(this.fileUrl) | 531 | return getHLSPublicFileUrl(this.fileUrl) |
532 | } | 532 | } |
533 | 533 | ||
534 | return getWebTorrentPublicFileUrl(this.fileUrl) | 534 | return getWebVideoPublicFileUrl(this.fileUrl) |
535 | } | 535 | } |
536 | 536 | ||
537 | // --------------------------------------------------------------------------- | 537 | // --------------------------------------------------------------------------- |
@@ -553,10 +553,10 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel> | |||
553 | getFileStaticPath (video: MVideo) { | 553 | getFileStaticPath (video: MVideo) { |
554 | if (this.isHLS()) return this.getHLSFileStaticPath(video) | 554 | if (this.isHLS()) return this.getHLSFileStaticPath(video) |
555 | 555 | ||
556 | return this.getWebTorrentFileStaticPath(video) | 556 | return this.getWebVideoFileStaticPath(video) |
557 | } | 557 | } |
558 | 558 | ||
559 | private getWebTorrentFileStaticPath (video: MVideo) { | 559 | private getWebVideoFileStaticPath (video: MVideo) { |
560 | if (isVideoInPrivateDirectory(video.privacy)) { | 560 | if (isVideoInPrivateDirectory(video.privacy)) { |
561 | return join(STATIC_PATHS.PRIVATE_WEBSEED, this.filename) | 561 | return join(STATIC_PATHS.PRIVATE_WEBSEED, this.filename) |
562 | } | 562 | } |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 3a0d95b62..4c6297243 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -29,7 +29,7 @@ import { | |||
29 | import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video' | 29 | import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video' |
30 | import { InternalEventEmitter } from '@server/lib/internal-event-emitter' | 30 | import { InternalEventEmitter } from '@server/lib/internal-event-emitter' |
31 | import { LiveManager } from '@server/lib/live/live-manager' | 31 | import { LiveManager } from '@server/lib/live/live-manager' |
32 | import { removeHLSFileObjectStorageByFilename, removeHLSObjectStorage, removeWebTorrentObjectStorage } from '@server/lib/object-storage' | 32 | import { removeHLSFileObjectStorageByFilename, removeHLSObjectStorage, removeWebVideoObjectStorage } from '@server/lib/object-storage' |
33 | import { tracer } from '@server/lib/opentelemetry/tracing' | 33 | import { tracer } from '@server/lib/opentelemetry/tracing' |
34 | import { getHLSDirectory, getHLSRedundancyDirectory, getHlsResolutionPlaylistFilename } from '@server/lib/paths' | 34 | import { getHLSDirectory, getHLSRedundancyDirectory, getHlsResolutionPlaylistFilename } from '@server/lib/paths' |
35 | import { Hooks } from '@server/lib/plugins/hooks' | 35 | import { Hooks } from '@server/lib/plugins/hooks' |
@@ -151,7 +151,7 @@ export enum ScopeNames { | |||
151 | FOR_API = 'FOR_API', | 151 | FOR_API = 'FOR_API', |
152 | WITH_ACCOUNT_DETAILS = 'WITH_ACCOUNT_DETAILS', | 152 | WITH_ACCOUNT_DETAILS = 'WITH_ACCOUNT_DETAILS', |
153 | WITH_TAGS = 'WITH_TAGS', | 153 | WITH_TAGS = 'WITH_TAGS', |
154 | WITH_WEBTORRENT_FILES = 'WITH_WEBTORRENT_FILES', | 154 | WITH_WEB_VIDEO_FILES = 'WITH_WEB_VIDEO_FILES', |
155 | WITH_SCHEDULED_UPDATE = 'WITH_SCHEDULED_UPDATE', | 155 | WITH_SCHEDULED_UPDATE = 'WITH_SCHEDULED_UPDATE', |
156 | WITH_BLACKLISTED = 'WITH_BLACKLISTED', | 156 | WITH_BLACKLISTED = 'WITH_BLACKLISTED', |
157 | WITH_STREAMING_PLAYLISTS = 'WITH_STREAMING_PLAYLISTS', | 157 | WITH_STREAMING_PLAYLISTS = 'WITH_STREAMING_PLAYLISTS', |
@@ -290,7 +290,7 @@ export type ForAPIOptions = { | |||
290 | } | 290 | } |
291 | ] | 291 | ] |
292 | }, | 292 | }, |
293 | [ScopeNames.WITH_WEBTORRENT_FILES]: (withRedundancies = false) => { | 293 | [ScopeNames.WITH_WEB_VIDEO_FILES]: (withRedundancies = false) => { |
294 | let subInclude: any[] = [] | 294 | let subInclude: any[] = [] |
295 | 295 | ||
296 | if (withRedundancies === true) { | 296 | if (withRedundancies === true) { |
@@ -813,7 +813,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
813 | 813 | ||
814 | // Remove physical files and torrents | 814 | // Remove physical files and torrents |
815 | instance.VideoFiles.forEach(file => { | 815 | instance.VideoFiles.forEach(file => { |
816 | tasks.push(instance.removeWebTorrentFile(file)) | 816 | tasks.push(instance.removeWebVideoFile(file)) |
817 | }) | 817 | }) |
818 | 818 | ||
819 | // Remove playlists file | 819 | // Remove playlists file |
@@ -1107,7 +1107,10 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1107 | include?: VideoInclude | 1107 | include?: VideoInclude |
1108 | 1108 | ||
1109 | hasFiles?: boolean // default false | 1109 | hasFiles?: boolean // default false |
1110 | hasWebtorrentFiles?: boolean | 1110 | |
1111 | hasWebtorrentFiles?: boolean // TODO: remove in v7 | ||
1112 | hasWebVideoFiles?: boolean | ||
1113 | |||
1111 | hasHLSFiles?: boolean | 1114 | hasHLSFiles?: boolean |
1112 | 1115 | ||
1113 | categoryOneOf?: number[] | 1116 | categoryOneOf?: number[] |
@@ -1172,6 +1175,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1172 | 'historyOfUser', | 1175 | 'historyOfUser', |
1173 | 'hasHLSFiles', | 1176 | 'hasHLSFiles', |
1174 | 'hasWebtorrentFiles', | 1177 | 'hasWebtorrentFiles', |
1178 | 'hasWebVideoFiles', | ||
1175 | 'search', | 1179 | 'search', |
1176 | 'excludeAlreadyWatched' | 1180 | 'excludeAlreadyWatched' |
1177 | ]), | 1181 | ]), |
@@ -1205,7 +1209,9 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1205 | 1209 | ||
1206 | user?: MUserAccountId | 1210 | user?: MUserAccountId |
1207 | 1211 | ||
1208 | hasWebtorrentFiles?: boolean | 1212 | hasWebtorrentFiles?: boolean // TODO: remove in v7 |
1213 | hasWebVideoFiles?: boolean | ||
1214 | |||
1209 | hasHLSFiles?: boolean | 1215 | hasHLSFiles?: boolean |
1210 | 1216 | ||
1211 | search?: string | 1217 | search?: string |
@@ -1252,6 +1258,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1252 | 'durationMax', | 1258 | 'durationMax', |
1253 | 'hasHLSFiles', | 1259 | 'hasHLSFiles', |
1254 | 'hasWebtorrentFiles', | 1260 | 'hasWebtorrentFiles', |
1261 | 'hasWebVideoFiles', | ||
1255 | 'uuids', | 1262 | 'uuids', |
1256 | 'search', | 1263 | 'search', |
1257 | 'displayOnlyForFollower', | 1264 | 'displayOnlyForFollower', |
@@ -1676,7 +1683,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1676 | return this.getQualityFileBy(minBy) | 1683 | return this.getQualityFileBy(minBy) |
1677 | } | 1684 | } |
1678 | 1685 | ||
1679 | getWebTorrentFile<T extends MVideoWithFile> (this: T, resolution: number): MVideoFileVideo { | 1686 | getWebVideoFile<T extends MVideoWithFile> (this: T, resolution: number): MVideoFileVideo { |
1680 | if (Array.isArray(this.VideoFiles) === false) return undefined | 1687 | if (Array.isArray(this.VideoFiles) === false) return undefined |
1681 | 1688 | ||
1682 | const file = this.VideoFiles.find(f => f.resolution === resolution) | 1689 | const file = this.VideoFiles.find(f => f.resolution === resolution) |
@@ -1685,7 +1692,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1685 | return Object.assign(file, { Video: this }) | 1692 | return Object.assign(file, { Video: this }) |
1686 | } | 1693 | } |
1687 | 1694 | ||
1688 | hasWebTorrentFiles () { | 1695 | hasWebVideoFiles () { |
1689 | return Array.isArray(this.VideoFiles) === true && this.VideoFiles.length !== 0 | 1696 | return Array.isArray(this.VideoFiles) === true && this.VideoFiles.length !== 0 |
1690 | } | 1697 | } |
1691 | 1698 | ||
@@ -1884,7 +1891,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1884 | .concat(toAdd) | 1891 | .concat(toAdd) |
1885 | } | 1892 | } |
1886 | 1893 | ||
1887 | removeWebTorrentFile (videoFile: MVideoFile, isRedundancy = false) { | 1894 | removeWebVideoFile (videoFile: MVideoFile, isRedundancy = false) { |
1888 | const filePath = isRedundancy | 1895 | const filePath = isRedundancy |
1889 | ? VideoPathManager.Instance.getFSRedundancyVideoFilePath(this, videoFile) | 1896 | ? VideoPathManager.Instance.getFSRedundancyVideoFilePath(this, videoFile) |
1890 | : VideoPathManager.Instance.getFSVideoFileOutputPath(this, videoFile) | 1897 | : VideoPathManager.Instance.getFSVideoFileOutputPath(this, videoFile) |
@@ -1893,7 +1900,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1893 | if (!isRedundancy) promises.push(videoFile.removeTorrent()) | 1900 | if (!isRedundancy) promises.push(videoFile.removeTorrent()) |
1894 | 1901 | ||
1895 | if (videoFile.storage === VideoStorage.OBJECT_STORAGE) { | 1902 | if (videoFile.storage === VideoStorage.OBJECT_STORAGE) { |
1896 | promises.push(removeWebTorrentObjectStorage(videoFile)) | 1903 | promises.push(removeWebVideoObjectStorage(videoFile)) |
1897 | } | 1904 | } |
1898 | 1905 | ||
1899 | return Promise.all(promises) | 1906 | return Promise.all(promises) |