mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Add playlist rest tests
This commit is contained in:
@@ -18,6 +18,7 @@ import { JobQueue } from '../../lib/job-queue'
|
||||
import { logger } from '../../helpers/logger'
|
||||
import { VideoPlaylistModel } from '../../models/video/video-playlist'
|
||||
import { UserModel } from '../../models/account/user'
|
||||
import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists'
|
||||
|
||||
const accountsRouter = express.Router()
|
||||
|
||||
@@ -57,6 +58,7 @@ accountsRouter.get('/:accountName/video-playlists',
|
||||
videoPlaylistsSortValidator,
|
||||
setDefaultSort,
|
||||
setDefaultPagination,
|
||||
commonVideoPlaylistFiltersValidator,
|
||||
asyncMiddleware(listAccountPlaylists)
|
||||
)
|
||||
|
||||
@@ -106,7 +108,8 @@ async function listAccountPlaylists (req: express.Request, res: express.Response
|
||||
count: req.query.count,
|
||||
sort: req.query.sort,
|
||||
accountId: res.locals.account.id,
|
||||
privateAndUnlisted
|
||||
privateAndUnlisted,
|
||||
type: req.query.playlistType
|
||||
})
|
||||
|
||||
return res.json(getFormattedObjects(resultList.data, resultList.total))
|
||||
|
||||
@@ -6,7 +6,7 @@ import { getFormattedObjects } from '../../../helpers/utils'
|
||||
import { CONFIG, RATES_LIMIT, sequelizeTypescript } from '../../../initializers'
|
||||
import { Emailer } from '../../../lib/emailer'
|
||||
import { Redis } from '../../../lib/redis'
|
||||
import { createUserAccountAndChannel } from '../../../lib/user'
|
||||
import { createUserAccountAndChannelAndPlaylist } from '../../../lib/user'
|
||||
import {
|
||||
asyncMiddleware,
|
||||
asyncRetryTransactionMiddleware,
|
||||
@@ -174,7 +174,7 @@ async function createUser (req: express.Request, res: express.Response) {
|
||||
videoQuotaDaily: body.videoQuotaDaily
|
||||
})
|
||||
|
||||
const { user, account } = await createUserAccountAndChannel(userToCreate)
|
||||
const { user, account } = await createUserAccountAndChannelAndPlaylist(userToCreate)
|
||||
|
||||
auditLogger.create(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()))
|
||||
logger.info('User %s with its channel and account created.', body.username)
|
||||
@@ -205,7 +205,7 @@ async function registerUser (req: express.Request, res: express.Response) {
|
||||
emailVerified: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION ? false : null
|
||||
})
|
||||
|
||||
const { user } = await createUserAccountAndChannel(userToCreate)
|
||||
const { user } = await createUserAccountAndChannelAndPlaylist(userToCreate)
|
||||
|
||||
auditLogger.create(body.username, new UserAuditView(user.toFormattedJSON()))
|
||||
logger.info('User %s with its channel and account registered.', body.username)
|
||||
|
||||
@@ -33,6 +33,7 @@ import { resetSequelizeInstance } from '../../helpers/database-utils'
|
||||
import { UserModel } from '../../models/account/user'
|
||||
import { JobQueue } from '../../lib/job-queue'
|
||||
import { VideoPlaylistModel } from '../../models/video/video-playlist'
|
||||
import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists'
|
||||
|
||||
const auditLogger = auditLoggerFactory('channels')
|
||||
const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR })
|
||||
@@ -85,6 +86,7 @@ videoChannelRouter.get('/:nameWithHost/video-playlists',
|
||||
videoPlaylistsSortValidator,
|
||||
setDefaultSort,
|
||||
setDefaultPagination,
|
||||
commonVideoPlaylistFiltersValidator,
|
||||
asyncMiddleware(listVideoChannelPlaylists)
|
||||
)
|
||||
|
||||
@@ -197,6 +199,8 @@ async function removeVideoChannel (req: express.Request, res: express.Response)
|
||||
const videoChannelInstance: VideoChannelModel = res.locals.videoChannel
|
||||
|
||||
await sequelizeTypescript.transaction(async t => {
|
||||
await VideoPlaylistModel.resetPlaylistsOfChannel(videoChannelInstance.id, t)
|
||||
|
||||
await videoChannelInstance.destroy({ transaction: t })
|
||||
|
||||
auditLogger.delete(getAuditIdFromRes(res), new VideoChannelAuditView(videoChannelInstance.toFormattedJSON()))
|
||||
@@ -225,7 +229,8 @@ async function listVideoChannelPlaylists (req: express.Request, res: express.Res
|
||||
start: req.query.start,
|
||||
count: req.query.count,
|
||||
sort: req.query.sort,
|
||||
videoChannelId: res.locals.videoChannel.id
|
||||
videoChannelId: res.locals.videoChannel.id,
|
||||
type: req.query.playlistType
|
||||
})
|
||||
|
||||
return res.json(getFormattedObjects(resultList.data, resultList.total))
|
||||
|
||||
@@ -17,6 +17,7 @@ import { logger } from '../../helpers/logger'
|
||||
import { resetSequelizeInstance } from '../../helpers/database-utils'
|
||||
import { VideoPlaylistModel } from '../../models/video/video-playlist'
|
||||
import {
|
||||
commonVideoPlaylistFiltersValidator,
|
||||
videoPlaylistsAddValidator,
|
||||
videoPlaylistsAddVideoValidator,
|
||||
videoPlaylistsDeleteValidator,
|
||||
@@ -45,6 +46,7 @@ import { VideoPlaylistElementModel } from '../../models/video/video-playlist-ele
|
||||
import { VideoPlaylistElementCreate } from '../../../shared/models/videos/playlist/video-playlist-element-create.model'
|
||||
import { VideoPlaylistElementUpdate } from '../../../shared/models/videos/playlist/video-playlist-element-update.model'
|
||||
import { copy, pathExists } from 'fs-extra'
|
||||
import { AccountModel } from '../../models/account/account'
|
||||
|
||||
const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { thumbnailfile: CONFIG.STORAGE.TMP_DIR })
|
||||
|
||||
@@ -55,6 +57,7 @@ videoPlaylistRouter.get('/',
|
||||
videoPlaylistsSortValidator,
|
||||
setDefaultSort,
|
||||
setDefaultPagination,
|
||||
commonVideoPlaylistFiltersValidator,
|
||||
asyncMiddleware(listVideoPlaylists)
|
||||
)
|
||||
|
||||
@@ -130,7 +133,8 @@ async function listVideoPlaylists (req: express.Request, res: express.Response)
|
||||
followerActorId: serverActor.id,
|
||||
start: req.query.start,
|
||||
count: req.query.count,
|
||||
sort: req.query.sort
|
||||
sort: req.query.sort,
|
||||
type: req.query.type
|
||||
})
|
||||
|
||||
return res.json(getFormattedObjects(resultList.data, resultList.total))
|
||||
@@ -171,7 +175,8 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) {
|
||||
const videoPlaylistCreated: VideoPlaylistModel = await sequelizeTypescript.transaction(async t => {
|
||||
const videoPlaylistCreated = await videoPlaylist.save({ transaction: t })
|
||||
|
||||
videoPlaylistCreated.OwnerAccount = user.Account
|
||||
// We need more attributes for the federation
|
||||
videoPlaylistCreated.OwnerAccount = await AccountModel.load(user.Account.id, t)
|
||||
await sendCreateVideoPlaylist(videoPlaylistCreated, t)
|
||||
|
||||
return videoPlaylistCreated
|
||||
@@ -216,6 +221,7 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response)
|
||||
const videoChannel = res.locals.videoChannel as VideoChannelModel
|
||||
|
||||
videoPlaylistInstance.videoChannelId = videoChannel.id
|
||||
videoPlaylistInstance.VideoChannel = videoChannel
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,6 +233,8 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response)
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -290,11 +298,15 @@ async function addVideoInPlaylist (req: express.Request, res: express.Response)
|
||||
const playlistThumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, videoPlaylist.getThumbnailName())
|
||||
|
||||
if (await pathExists(playlistThumbnailPath) === false) {
|
||||
logger.info('Generating default thumbnail to playlist %s.', videoPlaylist.url)
|
||||
|
||||
const videoThumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName())
|
||||
await copy(videoThumbnailPath, playlistThumbnailPath)
|
||||
}
|
||||
}
|
||||
|
||||
// We need more attributes for the federation
|
||||
videoPlaylist.OwnerAccount = await AccountModel.load(videoPlaylist.OwnerAccount.id, t)
|
||||
await sendUpdateVideoPlaylist(videoPlaylist, t)
|
||||
|
||||
return playlistElement
|
||||
@@ -320,6 +332,8 @@ async function updateVideoPlaylistElement (req: express.Request, res: express.Re
|
||||
|
||||
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
|
||||
@@ -341,6 +355,8 @@ async function removeVideoFromPlaylist (req: express.Request, res: express.Respo
|
||||
// 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)
|
||||
@@ -382,6 +398,8 @@ async function reorderVideosPlaylist (req: express.Request, res: express.Respons
|
||||
// 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)
|
||||
})
|
||||
|
||||
@@ -415,5 +433,6 @@ async function getVideoPlaylistVideos (req: express.Request, res: express.Respon
|
||||
user: res.locals.oauth ? res.locals.oauth.token.User : undefined
|
||||
})
|
||||
|
||||
return res.json(getFormattedObjects(resultList.data, resultList.total))
|
||||
const additionalAttributes = { playlistInfo: true }
|
||||
return res.json(getFormattedObjects(resultList.data, resultList.total, { additionalAttributes }))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user