MVideoPlaylistElementVideoUrlPlaylistPrivacy,
MVideoPlaylistVideoThumbnail
} from '@server/types/models/video/video-playlist-element'
+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 { getSort, throwIfNotValid } from '../utils'
import { ForAPIOptions, ScopeNames as VideoScopeNames, VideoModel } from './video'
import { VideoPlaylistModel } from './video-playlist'
-import { AttributesOnly } from '@shared/core-utils'
@Table({
tableName: 'videoPlaylistElement',
}
static listUrlsOfForAP (videoPlaylistId: number, start: number, count: number, t?: Transaction) {
- const query = {
- attributes: [ 'url' ],
- offset: start,
- limit: count,
- order: getSort('position'),
- where: {
- videoPlaylistId
- },
- transaction: t
+ const getQuery = (forCount: boolean) => {
+ 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<MVideoPlaylistVideoThumbnail> {
}
const positionQuery = Sequelize.literal(`${newPosition} + "position" - ${firstPosition}`)
- return VideoPlaylistElementModel.update({ position: positionQuery as any }, query)
+ return VideoPlaylistElementModel.update({ position: positionQuery }, query)
}
static increasePositionOf (
videoPlaylistId: number,
fromPosition: number,
- toPosition?: number,
by = 1,
transaction?: Transaction
) {