aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/accounts.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/accounts.ts')
-rw-r--r--server/controllers/api/accounts.ts57
1 files changed, 45 insertions, 12 deletions
diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts
index 8c0237203..03c831092 100644
--- a/server/controllers/api/accounts.ts
+++ b/server/controllers/api/accounts.ts
@@ -1,21 +1,23 @@
1import * as express from 'express' 1import * as express from 'express'
2import { getFormattedObjects } from '../../helpers/utils' 2import { getFormattedObjects, getServerActor } from '../../helpers/utils'
3import { 3import {
4 asyncMiddleware, 4 asyncMiddleware,
5 commonVideosFiltersValidator, 5 commonVideosFiltersValidator,
6 listVideoAccountChannelsValidator,
7 optionalAuthenticate, 6 optionalAuthenticate,
8 paginationValidator, 7 paginationValidator,
9 setDefaultPagination, 8 setDefaultPagination,
10 setDefaultSort 9 setDefaultSort,
10 videoPlaylistsSortValidator
11} from '../../middlewares' 11} from '../../middlewares'
12import { accountsNameWithHostGetValidator, accountsSortValidator, videosSortValidator } from '../../middlewares/validators' 12import { accountNameWithHostGetValidator, accountsSortValidator, videosSortValidator } from '../../middlewares/validators'
13import { AccountModel } from '../../models/account/account' 13import { AccountModel } from '../../models/account/account'
14import { VideoModel } from '../../models/video/video' 14import { VideoModel } from '../../models/video/video'
15import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' 15import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
16import { VideoChannelModel } from '../../models/video/video-channel' 16import { VideoChannelModel } from '../../models/video/video-channel'
17import { JobQueue } from '../../lib/job-queue' 17import { JobQueue } from '../../lib/job-queue'
18import { logger } from '../../helpers/logger' 18import { logger } from '../../helpers/logger'
19import { VideoPlaylistModel } from '../../models/video/video-playlist'
20import { UserModel } from '../../models/account/user'
19 21
20const accountsRouter = express.Router() 22const accountsRouter = express.Router()
21 23
@@ -28,12 +30,12 @@ accountsRouter.get('/',
28) 30)
29 31
30accountsRouter.get('/:accountName', 32accountsRouter.get('/:accountName',
31 asyncMiddleware(accountsNameWithHostGetValidator), 33 asyncMiddleware(accountNameWithHostGetValidator),
32 getAccount 34 getAccount
33) 35)
34 36
35accountsRouter.get('/:accountName/videos', 37accountsRouter.get('/:accountName/videos',
36 asyncMiddleware(accountsNameWithHostGetValidator), 38 asyncMiddleware(accountNameWithHostGetValidator),
37 paginationValidator, 39 paginationValidator,
38 videosSortValidator, 40 videosSortValidator,
39 setDefaultSort, 41 setDefaultSort,
@@ -44,8 +46,18 @@ accountsRouter.get('/:accountName/videos',
44) 46)
45 47
46accountsRouter.get('/:accountName/video-channels', 48accountsRouter.get('/:accountName/video-channels',
47 asyncMiddleware(listVideoAccountChannelsValidator), 49 asyncMiddleware(accountNameWithHostGetValidator),
48 asyncMiddleware(listVideoAccountChannels) 50 asyncMiddleware(listAccountChannels)
51)
52
53accountsRouter.get('/:accountName/video-playlists',
54 optionalAuthenticate,
55 asyncMiddleware(accountNameWithHostGetValidator),
56 paginationValidator,
57 videoPlaylistsSortValidator,
58 setDefaultSort,
59 setDefaultPagination,
60 asyncMiddleware(listAccountPlaylists)
49) 61)
50 62
51// --------------------------------------------------------------------------- 63// ---------------------------------------------------------------------------
@@ -56,7 +68,7 @@ export {
56 68
57// --------------------------------------------------------------------------- 69// ---------------------------------------------------------------------------
58 70
59function getAccount (req: express.Request, res: express.Response, next: express.NextFunction) { 71function getAccount (req: express.Request, res: express.Response) {
60 const account: AccountModel = res.locals.account 72 const account: AccountModel = res.locals.account
61 73
62 if (account.isOutdated()) { 74 if (account.isOutdated()) {
@@ -67,19 +79,40 @@ function getAccount (req: express.Request, res: express.Response, next: express.
67 return res.json(account.toFormattedJSON()) 79 return res.json(account.toFormattedJSON())
68} 80}
69 81
70async function listAccounts (req: express.Request, res: express.Response, next: express.NextFunction) { 82async function listAccounts (req: express.Request, res: express.Response) {
71 const resultList = await AccountModel.listForApi(req.query.start, req.query.count, req.query.sort) 83 const resultList = await AccountModel.listForApi(req.query.start, req.query.count, req.query.sort)
72 84
73 return res.json(getFormattedObjects(resultList.data, resultList.total)) 85 return res.json(getFormattedObjects(resultList.data, resultList.total))
74} 86}
75 87
76async function listVideoAccountChannels (req: express.Request, res: express.Response, next: express.NextFunction) { 88async function listAccountChannels (req: express.Request, res: express.Response) {
77 const resultList = await VideoChannelModel.listByAccount(res.locals.account.id) 89 const resultList = await VideoChannelModel.listByAccount(res.locals.account.id)
78 90
79 return res.json(getFormattedObjects(resultList.data, resultList.total)) 91 return res.json(getFormattedObjects(resultList.data, resultList.total))
80} 92}
81 93
82async function listAccountVideos (req: express.Request, res: express.Response, next: express.NextFunction) { 94async function listAccountPlaylists (req: express.Request, res: express.Response) {
95 const serverActor = await getServerActor()
96
97 // Allow users to see their private/unlisted video playlists
98 let privateAndUnlisted = false
99 if (res.locals.oauth && (res.locals.oauth.token.User as UserModel).Account.id === res.locals.account.id) {
100 privateAndUnlisted = true
101 }
102
103 const resultList = await VideoPlaylistModel.listForApi({
104 followerActorId: serverActor.id,
105 start: req.query.start,
106 count: req.query.count,
107 sort: req.query.sort,
108 accountId: res.locals.account.id,
109 privateAndUnlisted
110 })
111
112 return res.json(getFormattedObjects(resultList.data, resultList.total))
113}
114
115async function listAccountVideos (req: express.Request, res: express.Response) {
83 const account: AccountModel = res.locals.account 116 const account: AccountModel = res.locals.account
84 const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined 117 const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined
85 118