From 371906639ee9b6ea4daae504bc7c2b15856c3f38 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 17 Aug 2020 16:39:32 +0200 Subject: Add ability to a video multiple times in a playlist --- server/models/video/video-playlist-element.ts | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'server/models/video') 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 @@ -43,10 +43,6 @@ import { MUserAccountId } from '@server/types/models' { fields: [ 'videoId' ] }, - { - fields: [ 'videoPlaylistId', 'videoId' ], - unique: true - }, { fields: [ 'url' ], unique: true @@ -60,8 +56,8 @@ export class VideoPlaylistElementModel extends Model @UpdatedAt updatedAt: Date - @AllowNull(false) - @Is('VideoPlaylistUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url')) + @AllowNull(true) + @Is('VideoPlaylistUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url', true)) @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_PLAYLISTS.URL.max)) url: string @@ -185,12 +181,11 @@ export class VideoPlaylistElementModel extends Model return VideoPlaylistElementModel.findByPk(playlistElementId) } - static loadByPlaylistAndVideoForAP ( + static loadByPlaylistAndElementIdForAP ( playlistId: number | string, - videoId: number | string + playlistElementId: number ): Bluebird { const playlistWhere = validator.isUUID('' + playlistId) ? { uuid: playlistId } : { id: playlistId } - const videoWhere = validator.isUUID('' + videoId) ? { uuid: videoId } : { id: videoId } const query = { include: [ @@ -201,10 +196,12 @@ export class VideoPlaylistElementModel extends Model }, { attributes: [ 'url' ], - model: VideoModel.unscoped(), - where: videoWhere + model: VideoModel.unscoped() } - ] + ], + where: { + id: playlistElementId + } } return VideoPlaylistElementModel.findOne(query) -- cgit v1.2.3