]>
Commit | Line | Data |
---|---|---|
265ba139 | 1 | import * as express from 'express' |
cc918ac3 | 2 | import { getFormattedObjects } from '../../helpers/utils' |
48dce1c9 | 3 | import { |
d525fc39 | 4 | asyncMiddleware, commonVideosFiltersValidator, |
48dce1c9 C |
5 | listVideoAccountChannelsValidator, |
6 | optionalAuthenticate, | |
7 | paginationValidator, | |
8 | setDefaultPagination, | |
cc918ac3 | 9 | setDefaultSort |
48dce1c9 | 10 | } from '../../middlewares' |
ad9e39fb | 11 | import { accountsNameWithHostGetValidator, accountsSortValidator, videosSortValidator } from '../../middlewares/validators' |
265ba139 | 12 | import { AccountModel } from '../../models/account/account' |
0626e7af | 13 | import { VideoModel } from '../../models/video/video' |
687d638c | 14 | import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' |
48dce1c9 | 15 | import { VideoChannelModel } from '../../models/video/video-channel' |
265ba139 C |
16 | |
17 | const accountsRouter = express.Router() | |
18 | ||
19 | accountsRouter.get('/', | |
20 | paginationValidator, | |
21 | accountsSortValidator, | |
1174a847 | 22 | setDefaultSort, |
f05a1c30 | 23 | setDefaultPagination, |
265ba139 C |
24 | asyncMiddleware(listAccounts) |
25 | ) | |
26 | ||
ad9e39fb C |
27 | accountsRouter.get('/:accountName', |
28 | asyncMiddleware(accountsNameWithHostGetValidator), | |
265ba139 C |
29 | getAccount |
30 | ) | |
31 | ||
ad9e39fb C |
32 | accountsRouter.get('/:accountName/videos', |
33 | asyncMiddleware(accountsNameWithHostGetValidator), | |
0626e7af C |
34 | paginationValidator, |
35 | videosSortValidator, | |
36 | setDefaultSort, | |
37 | setDefaultPagination, | |
38 | optionalAuthenticate, | |
d525fc39 | 39 | commonVideosFiltersValidator, |
48dce1c9 C |
40 | asyncMiddleware(listAccountVideos) |
41 | ) | |
42 | ||
ad9e39fb | 43 | accountsRouter.get('/:accountName/video-channels', |
48dce1c9 C |
44 | asyncMiddleware(listVideoAccountChannelsValidator), |
45 | asyncMiddleware(listVideoAccountChannels) | |
46 | ) | |
47 | ||
265ba139 C |
48 | // --------------------------------------------------------------------------- |
49 | ||
50 | export { | |
51 | accountsRouter | |
52 | } | |
53 | ||
54 | // --------------------------------------------------------------------------- | |
55 | ||
56 | function getAccount (req: express.Request, res: express.Response, next: express.NextFunction) { | |
0626e7af C |
57 | const account: AccountModel = res.locals.account |
58 | ||
59 | return res.json(account.toFormattedJSON()) | |
265ba139 C |
60 | } |
61 | ||
62 | async function listAccounts (req: express.Request, res: express.Response, next: express.NextFunction) { | |
63 | const resultList = await AccountModel.listForApi(req.query.start, req.query.count, req.query.sort) | |
64 | ||
65 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | |
66 | } | |
0626e7af | 67 | |
48dce1c9 C |
68 | async function listVideoAccountChannels (req: express.Request, res: express.Response, next: express.NextFunction) { |
69 | const resultList = await VideoChannelModel.listByAccount(res.locals.account.id) | |
70 | ||
71 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | |
72 | } | |
73 | ||
48dce1c9 | 74 | async function listAccountVideos (req: express.Request, res: express.Response, next: express.NextFunction) { |
0626e7af | 75 | const account: AccountModel = res.locals.account |
687d638c | 76 | const actorId = isUserAbleToSearchRemoteURI(res) ? null : undefined |
0626e7af | 77 | |
48dce1c9 | 78 | const resultList = await VideoModel.listForApi({ |
687d638c | 79 | actorId, |
48dce1c9 C |
80 | start: req.query.start, |
81 | count: req.query.count, | |
82 | sort: req.query.sort, | |
8a19bee1 | 83 | includeLocalVideos: true, |
d525fc39 C |
84 | categoryOneOf: req.query.categoryOneOf, |
85 | licenceOneOf: req.query.licenceOneOf, | |
86 | languageOneOf: req.query.languageOneOf, | |
87 | tagsOneOf: req.query.tagsOneOf, | |
88 | tagsAllOf: req.query.tagsAllOf, | |
89 | nsfw: buildNSFWFilter(res, req.query.nsfw), | |
48dce1c9 C |
90 | withFiles: false, |
91 | accountId: account.id | |
92 | }) | |
0626e7af C |
93 | |
94 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | |
95 | } |