aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-playlist.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-23 09:50:57 +0200
committerChocobozzz <me@florianbigard.com>2019-04-24 16:26:21 +0200
commit3acc50844047a37698f0618fa235c138e386a053 (patch)
treee33243bf7fadbcf2df616fc41814245094fd881a /server/models/video/video-playlist.ts
parent1735c825726edaa0af5035cb6cbb0cc0db502c6d (diff)
downloadPeerTube-3acc50844047a37698f0618fa235c138e386a053.tar.gz
PeerTube-3acc50844047a37698f0618fa235c138e386a053.tar.zst
PeerTube-3acc50844047a37698f0618fa235c138e386a053.zip
Upgrade sequelize
Diffstat (limited to 'server/models/video/video-playlist.ts')
-rw-r--r--server/models/video/video-playlist.ts47
1 files changed, 21 insertions, 26 deletions
diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts
index 3e436acfc..63b4a0715 100644
--- a/server/models/video/video-playlist.ts
+++ b/server/models/video/video-playlist.ts
@@ -42,7 +42,7 @@ import { activityPubCollectionPagination } from '../../helpers/activitypub'
42import { VideoPlaylistType } from '../../../shared/models/videos/playlist/video-playlist-type.model' 42import { VideoPlaylistType } from '../../../shared/models/videos/playlist/video-playlist-type.model'
43import { ThumbnailModel } from './thumbnail' 43import { ThumbnailModel } from './thumbnail'
44import { ActivityIconObject } from '../../../shared/models/activitypub/objects' 44import { ActivityIconObject } from '../../../shared/models/activitypub/objects'
45import { fn, literal, Op, Transaction } from 'sequelize' 45import { FindOptions, literal, Op, ScopeOptions, Transaction, WhereOptions } from 'sequelize'
46 46
47enum ScopeNames { 47enum ScopeNames {
48 AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST', 48 AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST',
@@ -61,11 +61,11 @@ type AvailableForListOptions = {
61 privateAndUnlisted?: boolean 61 privateAndUnlisted?: boolean
62} 62}
63 63
64@Scopes({ 64@Scopes(() => ({
65 [ ScopeNames.WITH_THUMBNAIL ]: { 65 [ ScopeNames.WITH_THUMBNAIL ]: {
66 include: [ 66 include: [
67 { 67 {
68 model: () => ThumbnailModel, 68 model: ThumbnailModel,
69 required: false 69 required: false
70 } 70 }
71 ] 71 ]
@@ -74,20 +74,16 @@ type AvailableForListOptions = {
74 attributes: { 74 attributes: {
75 include: [ 75 include: [
76 [ 76 [
77 fn('COUNT', 'toto'),
78 'coucou'
79 ],
80 [
81 literal('(SELECT COUNT("id") FROM "videoPlaylistElement" WHERE "videoPlaylistId" = "VideoPlaylistModel"."id")'), 77 literal('(SELECT COUNT("id") FROM "videoPlaylistElement" WHERE "videoPlaylistId" = "VideoPlaylistModel"."id")'),
82 'videosLength' 78 'videosLength'
83 ] 79 ]
84 ] 80 ]
85 } 81 }
86 }, 82 } as FindOptions,
87 [ ScopeNames.WITH_ACCOUNT ]: { 83 [ ScopeNames.WITH_ACCOUNT ]: {
88 include: [ 84 include: [
89 { 85 {
90 model: () => AccountModel, 86 model: AccountModel,
91 required: true 87 required: true
92 } 88 }
93 ] 89 ]
@@ -95,11 +91,11 @@ type AvailableForListOptions = {
95 [ ScopeNames.WITH_ACCOUNT_AND_CHANNEL_SUMMARY ]: { 91 [ ScopeNames.WITH_ACCOUNT_AND_CHANNEL_SUMMARY ]: {
96 include: [ 92 include: [
97 { 93 {
98 model: () => AccountModel.scope(AccountScopeNames.SUMMARY), 94 model: AccountModel.scope(AccountScopeNames.SUMMARY),
99 required: true 95 required: true
100 }, 96 },
101 { 97 {
102 model: () => VideoChannelModel.scope(VideoChannelScopeNames.SUMMARY), 98 model: VideoChannelModel.scope(VideoChannelScopeNames.SUMMARY),
103 required: false 99 required: false
104 } 100 }
105 ] 101 ]
@@ -107,11 +103,11 @@ type AvailableForListOptions = {
107 [ ScopeNames.WITH_ACCOUNT_AND_CHANNEL ]: { 103 [ ScopeNames.WITH_ACCOUNT_AND_CHANNEL ]: {
108 include: [ 104 include: [
109 { 105 {
110 model: () => AccountModel, 106 model: AccountModel,
111 required: true 107 required: true
112 }, 108 },
113 { 109 {
114 model: () => VideoChannelModel, 110 model: VideoChannelModel,
115 required: false 111 required: false
116 } 112 }
117 ] 113 ]
@@ -132,7 +128,7 @@ type AvailableForListOptions = {
132 ] 128 ]
133 } 129 }
134 130
135 const whereAnd: any[] = [] 131 const whereAnd: WhereOptions[] = []
136 132
137 if (options.privateAndUnlisted !== true) { 133 if (options.privateAndUnlisted !== true) {
138 whereAnd.push({ 134 whereAnd.push({
@@ -178,9 +174,9 @@ type AvailableForListOptions = {
178 required: false 174 required: false
179 } 175 }
180 ] 176 ]
181 } 177 } as FindOptions
182 } 178 }
183}) 179}))
184 180
185@Table({ 181@Table({
186 tableName: 'videoPlaylist', 182 tableName: 'videoPlaylist',
@@ -269,6 +265,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
269 VideoPlaylistElements: VideoPlaylistElementModel[] 265 VideoPlaylistElements: VideoPlaylistElementModel[]
270 266
271 @HasOne(() => ThumbnailModel, { 267 @HasOne(() => ThumbnailModel, {
268
272 foreignKey: { 269 foreignKey: {
273 name: 'videoPlaylistId', 270 name: 'videoPlaylistId',
274 allowNull: true 271 allowNull: true
@@ -294,7 +291,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
294 order: getSort(options.sort) 291 order: getSort(options.sort)
295 } 292 }
296 293
297 const scopes = [ 294 const scopes: (string | ScopeOptions)[] = [
298 { 295 {
299 method: [ 296 method: [
300 ScopeNames.AVAILABLE_FOR_LIST, 297 ScopeNames.AVAILABLE_FOR_LIST,
@@ -306,7 +303,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
306 privateAndUnlisted: options.privateAndUnlisted 303 privateAndUnlisted: options.privateAndUnlisted
307 } as AvailableForListOptions 304 } as AvailableForListOptions
308 ] 305 ]
309 } as any, // FIXME: typings 306 },
310 ScopeNames.WITH_VIDEOS_LENGTH, 307 ScopeNames.WITH_VIDEOS_LENGTH,
311 ScopeNames.WITH_THUMBNAIL 308 ScopeNames.WITH_THUMBNAIL
312 ] 309 ]
@@ -348,7 +345,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
348 model: VideoPlaylistElementModel.unscoped(), 345 model: VideoPlaylistElementModel.unscoped(),
349 where: { 346 where: {
350 videoId: { 347 videoId: {
351 [Op.any]: videoIds 348 [Op.in]: videoIds // FIXME: sequelize ANY seems broken
352 } 349 }
353 }, 350 },
354 required: true 351 required: true
@@ -427,12 +424,10 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
427 return VideoPlaylistModel.update({ privacy: VideoPlaylistPrivacy.PRIVATE, videoChannelId: null }, query) 424 return VideoPlaylistModel.update({ privacy: VideoPlaylistPrivacy.PRIVATE, videoChannelId: null }, query)
428 } 425 }
429 426
430 setThumbnail (thumbnail: ThumbnailModel) { 427 async setAndSaveThumbnail (thumbnail: ThumbnailModel, t: Transaction) {
431 this.Thumbnail = thumbnail 428 thumbnail.videoPlaylistId = this.id
432 }
433 429
434 getThumbnail () { 430 this.Thumbnail = await thumbnail.save({ transaction: t })
435 return this.Thumbnail
436 } 431 }
437 432
438 hasThumbnail () { 433 hasThumbnail () {
@@ -448,13 +443,13 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
448 getThumbnailUrl () { 443 getThumbnailUrl () {
449 if (!this.hasThumbnail()) return null 444 if (!this.hasThumbnail()) return null
450 445
451 return WEBSERVER.URL + STATIC_PATHS.THUMBNAILS + this.getThumbnail().filename 446 return WEBSERVER.URL + STATIC_PATHS.THUMBNAILS + this.Thumbnail.filename
452 } 447 }
453 448
454 getThumbnailStaticPath () { 449 getThumbnailStaticPath () {
455 if (!this.hasThumbnail()) return null 450 if (!this.hasThumbnail()) return null
456 451
457 return join(STATIC_PATHS.THUMBNAILS, this.getThumbnail().filename) 452 return join(STATIC_PATHS.THUMBNAILS, this.Thumbnail.filename)
458 } 453 }
459 454
460 setAsRefreshed () { 455 setAsRefreshed () {