aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-08-17 16:39:32 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-08-19 11:30:21 +0200
commit371906639ee9b6ea4daae504bc7c2b15856c3f38 (patch)
treea1807d7e5648a8b99565cc22daa22a1afbb34db4 /server/models/video
parentb75410b87d889ae5b1704cc7f9d32a3792db9075 (diff)
downloadPeerTube-371906639ee9b6ea4daae504bc7c2b15856c3f38.tar.gz
PeerTube-371906639ee9b6ea4daae504bc7c2b15856c3f38.tar.zst
PeerTube-371906639ee9b6ea4daae504bc7c2b15856c3f38.zip
Add ability to a video multiple times in a playlist
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video-playlist-element.ts21
1 files changed, 9 insertions, 12 deletions
diff --git a/server/models/video/video-playlist-element.ts b/server/models/video/video-playlist-element.ts
index ba92e129a..d357766e9 100644
--- a/server/models/video/video-playlist-element.ts
+++ b/server/models/video/video-playlist-element.ts
@@ -44,10 +44,6 @@ import { MUserAccountId } from '@server/types/models'
44 fields: [ 'videoId' ] 44 fields: [ 'videoId' ]
45 }, 45 },
46 { 46 {
47 fields: [ 'videoPlaylistId', 'videoId' ],
48 unique: true
49 },
50 {
51 fields: [ 'url' ], 47 fields: [ 'url' ],
52 unique: true 48 unique: true
53 } 49 }
@@ -60,8 +56,8 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel>
60 @UpdatedAt 56 @UpdatedAt
61 updatedAt: Date 57 updatedAt: Date
62 58
63 @AllowNull(false) 59 @AllowNull(true)
64 @Is('VideoPlaylistUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url')) 60 @Is('VideoPlaylistUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url', true))
65 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_PLAYLISTS.URL.max)) 61 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_PLAYLISTS.URL.max))
66 url: string 62 url: string
67 63
@@ -185,12 +181,11 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel>
185 return VideoPlaylistElementModel.findByPk(playlistElementId) 181 return VideoPlaylistElementModel.findByPk(playlistElementId)
186 } 182 }
187 183
188 static loadByPlaylistAndVideoForAP ( 184 static loadByPlaylistAndElementIdForAP (
189 playlistId: number | string, 185 playlistId: number | string,
190 videoId: number | string 186 playlistElementId: number
191 ): Bluebird<MVideoPlaylistElementVideoUrlPlaylistPrivacy> { 187 ): Bluebird<MVideoPlaylistElementVideoUrlPlaylistPrivacy> {
192 const playlistWhere = validator.isUUID('' + playlistId) ? { uuid: playlistId } : { id: playlistId } 188 const playlistWhere = validator.isUUID('' + playlistId) ? { uuid: playlistId } : { id: playlistId }
193 const videoWhere = validator.isUUID('' + videoId) ? { uuid: videoId } : { id: videoId }
194 189
195 const query = { 190 const query = {
196 include: [ 191 include: [
@@ -201,10 +196,12 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel>
201 }, 196 },
202 { 197 {
203 attributes: [ 'url' ], 198 attributes: [ 'url' ],
204 model: VideoModel.unscoped(), 199 model: VideoModel.unscoped()
205 where: videoWhere
206 } 200 }
207 ] 201 ],
202 where: {
203 id: playlistElementId
204 }
208 } 205 }
209 206
210 return VideoPlaylistElementModel.findOne(query) 207 return VideoPlaylistElementModel.findOne(query)