X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fvideo-channel.ts;h=b2916278752aee9095a78514f180011aadab33de;hb=43df00a30dc07ec6fc1b30d41eac011e4ea8641b;hp=f370c700475105799eace0f65ac7595868453fb2;hpb=4beda9e12adc7b1f3b178cecd6863ebf3cf431f1;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index f370c7004..b29162787 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts @@ -3,6 +3,7 @@ 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' @@ -23,6 +24,7 @@ import { asyncRetryTransactionMiddleware, authenticate, commonVideosFiltersValidator, + ensureUserCanManageChannel, optionalAuthenticate, paginationValidator, setDefaultPagination, @@ -73,7 +75,7 @@ videoChannelRouter.post('/:nameWithHost/avatar/pick', authenticate, reqAvatarFile, asyncMiddleware(videoChannelsNameWithHostValidator), - ensureAuthUserOwnsChannelValidator, + ensureUserCanManageChannel, updateAvatarValidator, asyncMiddleware(updateVideoChannelAvatar) ) @@ -82,7 +84,7 @@ videoChannelRouter.post('/:nameWithHost/banner/pick', authenticate, reqBannerFile, asyncMiddleware(videoChannelsNameWithHostValidator), - ensureAuthUserOwnsChannelValidator, + ensureUserCanManageChannel, updateBannerValidator, asyncMiddleware(updateVideoChannelBanner) ) @@ -90,21 +92,21 @@ videoChannelRouter.post('/:nameWithHost/banner/pick', videoChannelRouter.delete('/:nameWithHost/avatar', authenticate, asyncMiddleware(videoChannelsNameWithHostValidator), - ensureAuthUserOwnsChannelValidator, + ensureUserCanManageChannel, asyncMiddleware(deleteVideoChannelAvatar) ) videoChannelRouter.delete('/:nameWithHost/banner', authenticate, asyncMiddleware(videoChannelsNameWithHostValidator), - ensureAuthUserOwnsChannelValidator, + ensureUserCanManageChannel, asyncMiddleware(deleteVideoChannelBanner) ) videoChannelRouter.put('/:nameWithHost', authenticate, asyncMiddleware(videoChannelsNameWithHostValidator), - ensureAuthUserOwnsChannelValidator, + ensureUserCanManageChannel, videoChannelsUpdateValidator, asyncRetryTransactionMiddleware(updateVideoChannel) ) @@ -327,18 +329,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 @@ -350,7 +359,7 @@ async function listVideoChannelVideos (req: express.Request, res: express.Respon 'filter:api.video-channels.videos.list.result' ) - return res.json(getFormattedObjects(resultList.data, resultList.total)) + return res.json(getFormattedObjects(resultList.data, resultList.total, guessAdditionalAttributesFromQuery(query))) } async function listVideoChannelFollowers (req: express.Request, res: express.Response) { @@ -362,7 +371,7 @@ async function listVideoChannelFollowers (req: express.Request, res: express.Res count: req.query.count, sort: req.query.sort, search: req.query.search, - state: 'accepted', + state: 'accepted' }) return res.json(getFormattedObjects(resultList.data, resultList.total))