diff options
Diffstat (limited to 'server/controllers/api/accounts.ts')
-rw-r--r-- | server/controllers/api/accounts.ts | 57 |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { getFormattedObjects } from '../../helpers/utils' | 2 | import { getFormattedObjects, getServerActor } from '../../helpers/utils' |
3 | import { | 3 | import { |
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' |
12 | import { accountsNameWithHostGetValidator, accountsSortValidator, videosSortValidator } from '../../middlewares/validators' | 12 | import { accountNameWithHostGetValidator, accountsSortValidator, videosSortValidator } from '../../middlewares/validators' |
13 | import { AccountModel } from '../../models/account/account' | 13 | import { AccountModel } from '../../models/account/account' |
14 | import { VideoModel } from '../../models/video/video' | 14 | import { VideoModel } from '../../models/video/video' |
15 | import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' | 15 | import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' |
16 | import { VideoChannelModel } from '../../models/video/video-channel' | 16 | import { VideoChannelModel } from '../../models/video/video-channel' |
17 | import { JobQueue } from '../../lib/job-queue' | 17 | import { JobQueue } from '../../lib/job-queue' |
18 | import { logger } from '../../helpers/logger' | 18 | import { logger } from '../../helpers/logger' |
19 | import { VideoPlaylistModel } from '../../models/video/video-playlist' | ||
20 | import { UserModel } from '../../models/account/user' | ||
19 | 21 | ||
20 | const accountsRouter = express.Router() | 22 | const accountsRouter = express.Router() |
21 | 23 | ||
@@ -28,12 +30,12 @@ accountsRouter.get('/', | |||
28 | ) | 30 | ) |
29 | 31 | ||
30 | accountsRouter.get('/:accountName', | 32 | accountsRouter.get('/:accountName', |
31 | asyncMiddleware(accountsNameWithHostGetValidator), | 33 | asyncMiddleware(accountNameWithHostGetValidator), |
32 | getAccount | 34 | getAccount |
33 | ) | 35 | ) |
34 | 36 | ||
35 | accountsRouter.get('/:accountName/videos', | 37 | accountsRouter.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 | ||
46 | accountsRouter.get('/:accountName/video-channels', | 48 | accountsRouter.get('/:accountName/video-channels', |
47 | asyncMiddleware(listVideoAccountChannelsValidator), | 49 | asyncMiddleware(accountNameWithHostGetValidator), |
48 | asyncMiddleware(listVideoAccountChannels) | 50 | asyncMiddleware(listAccountChannels) |
51 | ) | ||
52 | |||
53 | accountsRouter.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 | ||
59 | function getAccount (req: express.Request, res: express.Response, next: express.NextFunction) { | 71 | function 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 | ||
70 | async function listAccounts (req: express.Request, res: express.Response, next: express.NextFunction) { | 82 | async 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 | ||
76 | async function listVideoAccountChannels (req: express.Request, res: express.Response, next: express.NextFunction) { | 88 | async 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 | ||
82 | async function listAccountVideos (req: express.Request, res: express.Response, next: express.NextFunction) { | 94 | async 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 | |||
115 | async 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 | ||