asyncMiddleware,
asyncRetryTransactionMiddleware,
authenticate,
- commonVideosFiltersValidator, optionalAuthenticate,
+ commonVideosFiltersValidator,
+ optionalAuthenticate,
paginationValidator,
setDefaultPagination,
setDefaultSort
import { processImage } from '../../helpers/image-utils'
import { join } from 'path'
import { UserModel } from '../../models/account/user'
-import {
- sendCreateVideoPlaylist,
- sendDeleteVideoPlaylist,
- sendUpdateVideoPlaylist
-} from '../../lib/activitypub/send'
-import {
- getVideoPlaylistActivityPubUrl,
- getVideoPlaylistElementActivityPubUrl
-} from '../../lib/activitypub/url'
+import { sendCreateVideoPlaylist, sendDeleteVideoPlaylist, sendUpdateVideoPlaylist } from '../../lib/activitypub/send'
+import { getVideoPlaylistActivityPubUrl, getVideoPlaylistElementActivityPubUrl } from '../../lib/activitypub/url'
import { VideoPlaylistUpdate } from '../../../shared/models/videos/playlist/video-playlist-update.model'
import { VideoModel } from '../../models/video/video'
import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element'
}
const playlistUpdated = await videoPlaylistInstance.save(sequelizeOptions)
- // We need more attributes for the federation
- playlistUpdated.OwnerAccount = await AccountModel.load(playlistUpdated.OwnerAccount.id, t)
const isNewPlaylist = wasPrivatePlaylist && playlistUpdated.privacy !== VideoPlaylistPrivacy.PRIVATE
}
}
- // We need more attributes for the federation
- videoPlaylist.OwnerAccount = await AccountModel.load(videoPlaylist.OwnerAccount.id, t)
await sendUpdateVideoPlaylist(videoPlaylist, t)
return playlistElement
const element = await videoPlaylistElement.save({ transaction: t })
- // We need more attributes for the federation
- videoPlaylist.OwnerAccount = await AccountModel.load(videoPlaylist.OwnerAccount.id, t)
await sendUpdateVideoPlaylist(videoPlaylist, t)
return element
// Decrease position of the next elements
await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, positionToDelete, null, -1, t)
- // We need more attributes for the federation
- videoPlaylist.OwnerAccount = await AccountModel.load(videoPlaylist.OwnerAccount.id, t)
await sendUpdateVideoPlaylist(videoPlaylist, t)
logger.info('Video playlist element %d of playlist %s deleted.', videoPlaylistElement.position, videoPlaylist.uuid)
// Decrease positions of elements after the old position of our ordered elements (decrease)
await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, oldPosition, null, -reorderLength, t)
- // We need more attributes for the federation
- videoPlaylist.OwnerAccount = await AccountModel.load(videoPlaylist.OwnerAccount.id, t)
await sendUpdateVideoPlaylist(videoPlaylist, t)
})
return exists(value) && VIDEO_PLAYLIST_TYPES[ value ] !== undefined
}
-async function isVideoPlaylistExist (id: number | string, res: express.Response) {
- const videoPlaylist = await VideoPlaylistModel.loadWithAccountAndChannel(id, undefined)
+async function isVideoPlaylistExist (id: number | string, res: express.Response, fetchType: 'summary' | 'all' = 'summary') {
+ const videoPlaylist = fetchType === 'summary'
+ ? await VideoPlaylistModel.loadWithAccountAndChannelSummary(id, undefined)
+ : await VideoPlaylistModel.loadWithAccountAndChannel(id, undefined)
if (!videoPlaylist) {
res.status(404)
if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
- if (!await isVideoPlaylistExist(req.params.playlistId, res)) return cleanUpReqFiles(req)
+ if (!await isVideoPlaylistExist(req.params.playlistId, res, 'all')) return cleanUpReqFiles(req)
const videoPlaylist = res.locals.videoPlaylist
if (areValidationErrors(req, res)) return
- if (!await isVideoPlaylistExist(req.params.playlistId, res)) return
+ if (!await isVideoPlaylistExist(req.params.playlistId, res, 'all')) return
if (!await isVideoExist(req.body.videoId, res, 'only-video')) return
const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist
if (areValidationErrors(req, res)) return
- if (!await isVideoPlaylistExist(req.params.playlistId, res)) return
+ if (!await isVideoPlaylistExist(req.params.playlistId, res, 'all')) return
if (!await isVideoExist(req.params.videoId, res, 'id')) return
const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist
if (areValidationErrors(req, res)) return
- if (!await isVideoPlaylistExist(req.params.playlistId, res)) return
+ if (!await isVideoPlaylistExist(req.params.playlistId, res, 'all')) return
const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist
if (!checkUserCanManageVideoPlaylist(res.locals.oauth.token.User, videoPlaylist, UserRight.UPDATE_ANY_VIDEO_PLAYLIST, res)) return
ForeignKey,
HasMany,
Is,
- Model, Scopes,
+ Model,
+ Scopes,
Table,
UpdatedAt
} from 'sequelize-typescript'
import { UserModel } from './user'
import { CONFIG } from '../../initializers'
import { AvatarModel } from '../avatar/avatar'
-import { WhereOptions } from 'sequelize'
import { VideoPlaylistModel } from '../video/video-playlist'
export enum ScopeNames {
]
})
@Scopes({
- [ ScopeNames.SUMMARY ]: (whereActor?: WhereOptions<ActorModel>) => {
+ [ ScopeNames.SUMMARY ]: (whereActor?: Sequelize.WhereOptions<ActorModel>) => {
return {
attributes: [ 'id', 'name' ],
include: [
AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST',
WITH_VIDEOS_LENGTH = 'WITH_VIDEOS_LENGTH',
WITH_ACCOUNT_AND_CHANNEL_SUMMARY = 'WITH_ACCOUNT_AND_CHANNEL_SUMMARY',
- WITH_ACCOUNT = 'WITH_ACCOUNT'
+ WITH_ACCOUNT = 'WITH_ACCOUNT',
+ WITH_ACCOUNT_AND_CHANNEL = 'WITH_ACCOUNT_AND_CHANNEL'
}
type AvailableForListOptions = {
}
]
},
+ [ ScopeNames.WITH_ACCOUNT_AND_CHANNEL ]: {
+ include: [
+ {
+ model: () => AccountModel,
+ required: true
+ },
+ {
+ model: () => VideoChannelModel,
+ required: false
+ }
+ ]
+ },
[ ScopeNames.AVAILABLE_FOR_LIST ]: (options: AvailableForListOptions) => {
// Only list local playlists OR playlists that are on an instance followed by actorId
const inQueryInstanceFollow = buildServerIdsFollowedBy(options.followerActorId)
.then(e => !!e)
}
- static loadWithAccountAndChannel (id: number | string, transaction: Sequelize.Transaction) {
+ static loadWithAccountAndChannelSummary (id: number | string, transaction: Sequelize.Transaction) {
const where = buildWhereIdOrUUID(id)
const query = {
.findOne(query)
}
+ static loadWithAccountAndChannel (id: number | string, transaction: Sequelize.Transaction) {
+ const where = buildWhereIdOrUUID(id)
+
+ const query = {
+ where,
+ transaction
+ }
+
+ return VideoPlaylistModel
+ .scope([ ScopeNames.WITH_ACCOUNT_AND_CHANNEL, ScopeNames.WITH_VIDEOS_LENGTH ])
+ .findOne(query)
+ }
+
static loadByUrlAndPopulateAccount (url: string) {
const query = {
where: {
import './video-hls'
import './video-imports'
import './video-nsfw'
+import './video-playlists'
import './video-privacy'
import './video-schedule-update'
import './video-transcoder'
const videoAttrs: any = { name: options.videoName }
if (options.nsfw) videoAttrs.nsfw = options.nsfw
-
const res = await uploadVideo(options.server.url, options.token || options.server.accessToken, videoAttrs)
return { id: res.body.video.id, uuid: res.body.video.uuid }