From df0b219d36bf6852cdf2a7ad09ed4a41c6bccefa Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 5 Mar 2019 10:58:44 +0100 Subject: Add playlist rest tests --- server/controllers/api/accounts.ts | 5 ++++- server/controllers/api/users/index.ts | 6 +++--- server/controllers/api/video-channel.ts | 7 ++++++- server/controllers/api/video-playlist.ts | 25 ++++++++++++++++++++++--- 4 files changed, 35 insertions(+), 8 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts index 03c831092..e24545de8 100644 --- a/server/controllers/api/accounts.ts +++ b/server/controllers/api/accounts.ts @@ -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)) diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index 407f32ac0..5758c8227 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts @@ -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) diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index 534cc8d7b..c13aed4dc 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts @@ -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)) diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts index e026b4d16..8605f3dfc 100644 --- a/server/controllers/api/video-playlist.ts +++ b/server/controllers/api/video-playlist.ts @@ -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 })) } -- cgit v1.2.3