diff options
author | Chocobozzz <me@florianbigard.com> | 2021-06-11 14:45:58 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-06-11 14:45:58 +0200 |
commit | 69322042c4da7dddfdccf55efa3cfbf408660d06 (patch) | |
tree | 5680108bf3a0dca58cbe418578fc96937dd1851d /server | |
parent | 7c3a6636fdd9b905345996d825c249a18add8a2c (diff) | |
download | PeerTube-69322042c4da7dddfdccf55efa3cfbf408660d06.tar.gz PeerTube-69322042c4da7dddfdccf55efa3cfbf408660d06.tar.zst PeerTube-69322042c4da7dddfdccf55efa3cfbf408660d06.zip |
Cleanup video model scopes
Diffstat (limited to 'server')
-rw-r--r-- | server/models/video/video.ts | 62 |
1 files changed, 7 insertions, 55 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index f3782fb43..fabfce588 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -56,19 +56,7 @@ import { | |||
56 | import { getVideoFileResolution } from '../../helpers/ffprobe-utils' | 56 | import { getVideoFileResolution } from '../../helpers/ffprobe-utils' |
57 | import { logger } from '../../helpers/logger' | 57 | import { logger } from '../../helpers/logger' |
58 | import { CONFIG } from '../../initializers/config' | 58 | import { CONFIG } from '../../initializers/config' |
59 | import { | 59 | import { ACTIVITY_PUB, API_VERSION, CONSTRAINTS_FIELDS, LAZY_STATIC_PATHS, STATIC_PATHS, WEBSERVER } from '../../initializers/constants' |
60 | ACTIVITY_PUB, | ||
61 | API_VERSION, | ||
62 | CONSTRAINTS_FIELDS, | ||
63 | LAZY_STATIC_PATHS, | ||
64 | STATIC_PATHS, | ||
65 | VIDEO_CATEGORIES, | ||
66 | VIDEO_LANGUAGES, | ||
67 | VIDEO_LICENCES, | ||
68 | VIDEO_PRIVACIES, | ||
69 | VIDEO_STATES, | ||
70 | WEBSERVER | ||
71 | } from '../../initializers/constants' | ||
72 | import { sendDeleteVideo } from '../../lib/activitypub/send' | 60 | import { sendDeleteVideo } from '../../lib/activitypub/send' |
73 | import { | 61 | import { |
74 | MChannel, | 62 | MChannel, |
@@ -136,20 +124,16 @@ import { VideoTagModel } from './video-tag' | |||
136 | import { VideoViewModel } from './video-view' | 124 | import { VideoViewModel } from './video-view' |
137 | 125 | ||
138 | export enum ScopeNames { | 126 | export enum ScopeNames { |
139 | AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS', | ||
140 | FOR_API = 'FOR_API', | 127 | FOR_API = 'FOR_API', |
141 | WITH_ACCOUNT_DETAILS = 'WITH_ACCOUNT_DETAILS', | 128 | WITH_ACCOUNT_DETAILS = 'WITH_ACCOUNT_DETAILS', |
142 | WITH_TAGS = 'WITH_TAGS', | 129 | WITH_TAGS = 'WITH_TAGS', |
143 | WITH_TRACKERS = 'WITH_TRACKERS', | ||
144 | WITH_WEBTORRENT_FILES = 'WITH_WEBTORRENT_FILES', | 130 | WITH_WEBTORRENT_FILES = 'WITH_WEBTORRENT_FILES', |
145 | WITH_SCHEDULED_UPDATE = 'WITH_SCHEDULED_UPDATE', | 131 | WITH_SCHEDULED_UPDATE = 'WITH_SCHEDULED_UPDATE', |
146 | WITH_BLACKLISTED = 'WITH_BLACKLISTED', | 132 | WITH_BLACKLISTED = 'WITH_BLACKLISTED', |
147 | WITH_USER_HISTORY = 'WITH_USER_HISTORY', | ||
148 | WITH_STREAMING_PLAYLISTS = 'WITH_STREAMING_PLAYLISTS', | 133 | WITH_STREAMING_PLAYLISTS = 'WITH_STREAMING_PLAYLISTS', |
149 | WITH_USER_ID = 'WITH_USER_ID', | ||
150 | WITH_IMMUTABLE_ATTRIBUTES = 'WITH_IMMUTABLE_ATTRIBUTES', | 134 | WITH_IMMUTABLE_ATTRIBUTES = 'WITH_IMMUTABLE_ATTRIBUTES', |
151 | WITH_THUMBNAILS = 'WITH_THUMBNAILS', | 135 | WITH_USER_HISTORY = 'WITH_USER_HISTORY', |
152 | WITH_LIVE = 'WITH_LIVE' | 136 | WITH_THUMBNAILS = 'WITH_THUMBNAILS' |
153 | } | 137 | } |
154 | 138 | ||
155 | export type ForAPIOptions = { | 139 | export type ForAPIOptions = { |
@@ -245,30 +229,6 @@ export type AvailableForListIDsOptions = { | |||
245 | } | 229 | } |
246 | ] | 230 | ] |
247 | }, | 231 | }, |
248 | [ScopeNames.WITH_LIVE]: { | ||
249 | include: [ | ||
250 | { | ||
251 | model: VideoLiveModel.unscoped(), | ||
252 | required: false | ||
253 | } | ||
254 | ] | ||
255 | }, | ||
256 | [ScopeNames.WITH_USER_ID]: { | ||
257 | include: [ | ||
258 | { | ||
259 | attributes: [ 'accountId' ], | ||
260 | model: VideoChannelModel.unscoped(), | ||
261 | required: true, | ||
262 | include: [ | ||
263 | { | ||
264 | attributes: [ 'userId' ], | ||
265 | model: AccountModel.unscoped(), | ||
266 | required: true | ||
267 | } | ||
268 | ] | ||
269 | } | ||
270 | ] | ||
271 | }, | ||
272 | [ScopeNames.WITH_ACCOUNT_DETAILS]: { | 232 | [ScopeNames.WITH_ACCOUNT_DETAILS]: { |
273 | include: [ | 233 | include: [ |
274 | { | 234 | { |
@@ -326,14 +286,6 @@ export type AvailableForListIDsOptions = { | |||
326 | [ScopeNames.WITH_TAGS]: { | 286 | [ScopeNames.WITH_TAGS]: { |
327 | include: [ TagModel ] | 287 | include: [ TagModel ] |
328 | }, | 288 | }, |
329 | [ScopeNames.WITH_TRACKERS]: { | ||
330 | include: [ | ||
331 | { | ||
332 | attributes: [ 'id', 'url' ], | ||
333 | model: TrackerModel | ||
334 | } | ||
335 | ] | ||
336 | }, | ||
337 | [ScopeNames.WITH_BLACKLISTED]: { | 289 | [ScopeNames.WITH_BLACKLISTED]: { |
338 | include: [ | 290 | include: [ |
339 | { | 291 | { |
@@ -1439,7 +1391,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1439 | 1391 | ||
1440 | const rawQuery = `UPDATE "video" SET "${field}" = ` + | 1392 | const rawQuery = `UPDATE "video" SET "${field}" = ` + |
1441 | '(' + | 1393 | '(' + |
1442 | 'SELECT COUNT(id) FROM "accountVideoRate" WHERE "accountVideoRate"."videoId" = "video"."id" AND type = :rateType' + | 1394 | 'SELECT COUNT(id) FROM "accountVideoRate" WHERE "accountVideoRate"."videoId" = "video"."id" AND type = :rateType' + |
1443 | ') ' + | 1395 | ') ' + |
1444 | 'WHERE "video"."id" = :videoId' | 1396 | 'WHERE "video"."id" = :videoId' |
1445 | 1397 | ||
@@ -1467,15 +1419,15 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1467 | .then(results => results.length === 1) | 1419 | .then(results => results.length === 1) |
1468 | } | 1420 | } |
1469 | 1421 | ||
1470 | static bulkUpdateSupportField (videoChannel: MChannel, t: Transaction) { | 1422 | static bulkUpdateSupportField (ofChannel: MChannel, t: Transaction) { |
1471 | const options = { | 1423 | const options = { |
1472 | where: { | 1424 | where: { |
1473 | channelId: videoChannel.id | 1425 | channelId: ofChannel.id |
1474 | }, | 1426 | }, |
1475 | transaction: t | 1427 | transaction: t |
1476 | } | 1428 | } |
1477 | 1429 | ||
1478 | return VideoModel.update({ support: videoChannel.support }, options) | 1430 | return VideoModel.update({ support: ofChannel.support }, options) |
1479 | } | 1431 | } |
1480 | 1432 | ||
1481 | static getAllIdsFromChannel (videoChannel: MChannelId): Promise<number[]> { | 1433 | static getAllIdsFromChannel (videoChannel: MChannelId): Promise<number[]> { |