X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Faccounts.ts;h=0a73dfcbf258eafa5c7a1d9d9793ecc442266657;hb=8054669f1181e815c435e76e81247eff32d41dc5;hp=00148ff555a7dd0282ff30fb7fcbf14c77edc8ef;hpb=fe98765624cdd6695739bda719fcb726b71c2b2a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts index 00148ff55..0a73dfcbf 100644 --- a/server/controllers/api/accounts.ts +++ b/server/controllers/api/accounts.ts @@ -1,5 +1,8 @@ import * as express from 'express' -import { getFormattedObjects, getServerActor } from '../../helpers/utils' +import { getServerActor } from '@server/models/application/application' +import { buildNSFWFilter, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' +import { getFormattedObjects } from '../../helpers/utils' +import { JobQueue } from '../../lib/job-queue' import { asyncMiddleware, authenticate, @@ -8,6 +11,7 @@ import { paginationValidator, setDefaultPagination, setDefaultSort, + setDefaultVideosSort, videoPlaylistsSortValidator, videoRatesSortValidator, videoRatingValidator @@ -16,21 +20,16 @@ import { accountNameWithHostGetValidator, accountsSortValidator, ensureAuthUserOwnsAccountValidator, - videosSortValidator, - videoChannelsSortValidator + videoChannelsSortValidator, + videoChannelStatsValidator, + videosSortValidator } from '../../middlewares/validators' +import { commonVideoPlaylistFiltersValidator, videoPlaylistsSearchValidator } from '../../middlewares/validators/videos/video-playlists' import { AccountModel } from '../../models/account/account' import { AccountVideoRateModel } from '../../models/account/account-video-rate' import { VideoModel } from '../../models/video/video' -import { buildNSFWFilter, isUserAbleToSearchRemoteURI, getCountVideos } from '../../helpers/express-utils' import { VideoChannelModel } from '../../models/video/video-channel' -import { JobQueue } from '../../lib/job-queue' -import { logger } from '../../helpers/logger' import { VideoPlaylistModel } from '../../models/video/video-playlist' -import { - commonVideoPlaylistFiltersValidator, - videoPlaylistsSearchValidator -} from '../../middlewares/validators/videos/video-playlists' const accountsRouter = express.Router() @@ -51,7 +50,7 @@ accountsRouter.get('/:accountName/videos', asyncMiddleware(accountNameWithHostGetValidator), paginationValidator, videosSortValidator, - setDefaultSort, + setDefaultVideosSort, setDefaultPagination, optionalAuthenticate, commonVideosFiltersValidator, @@ -60,6 +59,7 @@ accountsRouter.get('/:accountName/videos', accountsRouter.get('/:accountName/video-channels', asyncMiddleware(accountNameWithHostGetValidator), + videoChannelStatsValidator, paginationValidator, videoChannelsSortValidator, setDefaultSort, @@ -104,7 +104,6 @@ function getAccount (req: express.Request, res: express.Response) { if (account.isOutdated()) { JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'actor', url: account.Actor.url } }) - .catch(err => logger.error('Cannot create AP refresher job for actor %s.', account.Actor.url, { err })) } return res.json(account.toFormattedJSON()) @@ -121,7 +120,9 @@ async function listAccountChannels (req: express.Request, res: express.Response) accountId: res.locals.account.id, start: req.query.start, count: req.query.count, - sort: req.query.sort + sort: req.query.sort, + withStats: req.query.withStats, + search: req.query.search } const resultList = await VideoChannelModel.listByAccount(options) @@ -133,9 +134,9 @@ async function listAccountPlaylists (req: express.Request, res: express.Response const serverActor = await getServerActor() // Allow users to see their private/unlisted video playlists - let privateAndUnlisted = false + let listMyPlaylists = false if (res.locals.oauth && res.locals.oauth.token.User.Account.id === res.locals.account.id) { - privateAndUnlisted = true + listMyPlaylists = true } const resultList = await VideoPlaylistModel.listForApi({ @@ -145,7 +146,7 @@ async function listAccountPlaylists (req: express.Request, res: express.Response count: req.query.count, sort: req.query.sort, accountId: res.locals.account.id, - privateAndUnlisted, + listMyPlaylists, type: req.query.playlistType })