X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-playlist-element.ts;h=b832f9768c04a66c0160ac03c47cafc3f8a59e37;hb=0c9668f77901e7540e2c7045eb0f2974a4842a69;hp=e6906cb19202c6b70b59c8386a86ae8d8e39adc5;hpb=1c5e49e75284100b7b1fc8b4e73c8ba53fe22e89;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-playlist-element.ts b/server/models/video/video-playlist-element.ts index e6906cb19..b832f9768 100644 --- a/server/models/video/video-playlist-element.ts +++ b/server/models/video/video-playlist-element.ts @@ -23,16 +23,17 @@ import { MVideoPlaylistElementVideoUrlPlaylistPrivacy, MVideoPlaylistVideoThumbnail } from '@server/types/models/video/video-playlist-element' +import { forceNumber } from '@shared/core-utils' +import { AttributesOnly } from '@shared/typescript-utils' import { PlaylistElementObject } from '../../../shared/models/activitypub/objects/playlist-element-object' import { VideoPrivacy } from '../../../shared/models/videos' import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../shared/models/videos/playlist/video-playlist-element.model' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' import { CONSTRAINTS_FIELDS } from '../../initializers/constants' import { AccountModel } from '../account/account' -import { getSort, throwIfNotValid } from '../utils' +import { getSort, throwIfNotValid } from '../shared' import { ForAPIOptions, ScopeNames as VideoScopeNames, VideoModel } from './video' import { VideoPlaylistModel } from './video-playlist' -import { AttributesOnly } from '@shared/core-utils' @Table({ tableName: 'videoPlaylistElement', @@ -185,7 +186,9 @@ export class VideoPlaylistElementModel extends Model { - const playlistWhere = validator.isUUID('' + playlistId) ? { uuid: playlistId } : { id: playlistId } + const playlistWhere = validator.isUUID('' + playlistId) + ? { uuid: playlistId } + : { id: playlistId } const query = { include: [ @@ -208,22 +211,28 @@ export class VideoPlaylistElementModel extends Model { + return { + attributes: forCount + ? [] + : [ 'url' ], + offset: start, + limit: count, + order: getSort('position'), + where: { + videoPlaylistId + }, + transaction: t + } } - return VideoPlaylistElementModel - .findAndCountAll(query) - .then(({ rows, count }) => { - return { total: count, data: rows.map(e => e.url) } - }) + return Promise.all([ + VideoPlaylistElementModel.count(getQuery(true)), + VideoPlaylistElementModel.findAll(getQuery(false)) + ]).then(([ total, rows ]) => ({ + total, + data: rows.map(e => e.url) + })) } static loadFirstElementWithVideoThumbnail (videoPlaylistId: number): Promise { @@ -256,13 +265,15 @@ export class VideoPlaylistElementModel extends Model position ? position + 1 : 1) } - static reassignPositionOf ( - videoPlaylistId: number, - firstPosition: number, - endPosition: number, - newPosition: number, + static reassignPositionOf (options: { + videoPlaylistId: number + firstPosition: number + endPosition: number + newPosition: number transaction?: Transaction - ) { + }) { + const { videoPlaylistId, firstPosition, endPosition, newPosition, transaction } = options + const query = { where: { videoPlaylistId, @@ -275,14 +286,13 @@ export class VideoPlaylistElementModel extends Model