X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fvideo-channel.ts;h=e65550a221fe03c3dd052c676a4056cf0d27b3bd;hb=d17c7b4e8c52317bdc874917387b7a49f6cf8b01;hp=a0c6601d94f920c5d5f9360fa34eb0819f9edcd1;hpb=98ab5dc81048d47d08a231f17698128f959e59b2;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index a0c6601d9..e65550a22 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts @@ -1,10 +1,11 @@ -import * as express from 'express' +import express from 'express' import { pickCommonVideoQuery } from '@server/helpers/query' import { Hooks } from '@server/lib/plugins/hooks' +import { ActorFollowModel } from '@server/models/actor/actor-follow' import { getServerActor } from '@server/models/application/application' +import { guessAdditionalAttributesFromQuery } from '@server/models/video/formatter/video-format-utils' import { MChannelBannerAccountDefault } from '@server/types/models' -import { ActorImageType, VideoChannelCreate, VideoChannelUpdate } from '../../../shared' -import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' +import { ActorImageType, HttpStatusCode, VideoChannelCreate, VideoChannelUpdate } from '@shared/models' import { auditLoggerFactory, getAuditIdFromRes, VideoChannelAuditView } from '../../helpers/audit-logger' import { resetSequelizeInstance } from '../../helpers/database-utils' import { buildNSFWFilter, createReqFiles, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' @@ -22,6 +23,7 @@ import { asyncRetryTransactionMiddleware, authenticate, commonVideosFiltersValidator, + ensureCanManageChannel, optionalAuthenticate, paginationValidator, setDefaultPagination, @@ -33,7 +35,13 @@ import { videoChannelsUpdateValidator, videoPlaylistsSortValidator } from '../../middlewares' -import { videoChannelsListValidator, videoChannelsNameWithHostValidator, videosSortValidator } from '../../middlewares/validators' +import { + ensureIsLocalChannel, + videoChannelsFollowersSortValidator, + videoChannelsListValidator, + videoChannelsNameWithHostValidator, + videosSortValidator +} from '../../middlewares/validators' import { updateAvatarValidator, updateBannerValidator } from '../../middlewares/validators/actor-image' import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists' import { AccountModel } from '../../models/account/account' @@ -65,8 +73,9 @@ videoChannelRouter.post('/', videoChannelRouter.post('/:nameWithHost/avatar/pick', authenticate, reqAvatarFile, - // Check the rights - asyncMiddleware(videoChannelsUpdateValidator), + asyncMiddleware(videoChannelsNameWithHostValidator), + ensureIsLocalChannel, + ensureCanManageChannel, updateAvatarValidator, asyncMiddleware(updateVideoChannelAvatar) ) @@ -74,34 +83,43 @@ videoChannelRouter.post('/:nameWithHost/avatar/pick', videoChannelRouter.post('/:nameWithHost/banner/pick', authenticate, reqBannerFile, - // Check the rights - asyncMiddleware(videoChannelsUpdateValidator), + asyncMiddleware(videoChannelsNameWithHostValidator), + ensureIsLocalChannel, + ensureCanManageChannel, updateBannerValidator, asyncMiddleware(updateVideoChannelBanner) ) videoChannelRouter.delete('/:nameWithHost/avatar', authenticate, - // Check the rights - asyncMiddleware(videoChannelsUpdateValidator), + asyncMiddleware(videoChannelsNameWithHostValidator), + ensureIsLocalChannel, + ensureCanManageChannel, asyncMiddleware(deleteVideoChannelAvatar) ) videoChannelRouter.delete('/:nameWithHost/banner', authenticate, - // Check the rights - asyncMiddleware(videoChannelsUpdateValidator), + asyncMiddleware(videoChannelsNameWithHostValidator), + ensureIsLocalChannel, + ensureCanManageChannel, asyncMiddleware(deleteVideoChannelBanner) ) videoChannelRouter.put('/:nameWithHost', authenticate, - asyncMiddleware(videoChannelsUpdateValidator), + asyncMiddleware(videoChannelsNameWithHostValidator), + ensureIsLocalChannel, + ensureCanManageChannel, + videoChannelsUpdateValidator, asyncRetryTransactionMiddleware(updateVideoChannel) ) videoChannelRouter.delete('/:nameWithHost', authenticate, + asyncMiddleware(videoChannelsNameWithHostValidator), + ensureIsLocalChannel, + ensureCanManageChannel, asyncMiddleware(videoChannelsRemoveValidator), asyncRetryTransactionMiddleware(removeVideoChannel) ) @@ -132,6 +150,17 @@ videoChannelRouter.get('/:nameWithHost/videos', asyncMiddleware(listVideoChannelVideos) ) +videoChannelRouter.get('/:nameWithHost/followers', + authenticate, + asyncMiddleware(videoChannelsNameWithHostValidator), + ensureCanManageChannel, + paginationValidator, + videoChannelsFollowersSortValidator, + setDefaultSort, + setDefaultPagination, + asyncMiddleware(listVideoChannelFollowers) +) + // --------------------------------------------------------------------------- export { @@ -307,18 +336,25 @@ async function listVideoChannelPlaylists (req: express.Request, res: express.Res } async function listVideoChannelVideos (req: express.Request, res: express.Response) { + const serverActor = await getServerActor() + const videoChannelInstance = res.locals.videoChannel - const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined + + const displayOnlyForFollower = isUserAbleToSearchRemoteURI(res) + ? null + : { + actorId: serverActor.id, + orLocalVideos: true + } + const countVideos = getCountVideos(req) const query = pickCommonVideoQuery(req.query) const apiOptions = await Hooks.wrapObject({ ...query, - followerActorId, - includeLocalVideos: true, + displayOnlyForFollower, nsfw: buildNSFWFilter(res, query.nsfw), - withFiles: false, videoChannelId: videoChannelInstance.id, user: res.locals.oauth ? res.locals.oauth.token.User : undefined, countVideos @@ -330,5 +366,20 @@ async function listVideoChannelVideos (req: express.Request, res: express.Respon 'filter:api.video-channels.videos.list.result' ) + return res.json(getFormattedObjects(resultList.data, resultList.total, guessAdditionalAttributesFromQuery(query))) +} + +async function listVideoChannelFollowers (req: express.Request, res: express.Response) { + const channel = res.locals.videoChannel + + const resultList = await ActorFollowModel.listFollowersForApi({ + actorIds: [ channel.actorId ], + start: req.query.start, + count: req.query.count, + sort: req.query.sort, + search: req.query.search, + state: 'accepted' + }) + return res.json(getFormattedObjects(resultList.data, resultList.total)) }