aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-04-24 15:10:54 +0200
committerChocobozzz <me@florianbigard.com>2018-04-24 15:13:19 +0200
commit0626e7af82e02f8a5bd1e74a7d4d8c916d073ceb (patch)
tree79b5befbc6a04c007e5919805f1514d065b30e11 /server/controllers/api
parentb4d1af3dd8cdab2d58927e671d62194ca383cd75 (diff)
downloadPeerTube-0626e7af82e02f8a5bd1e74a7d4d8c916d073ceb.tar.gz
PeerTube-0626e7af82e02f8a5bd1e74a7d4d8c916d073ceb.tar.zst
PeerTube-0626e7af82e02f8a5bd1e74a7d4d8c916d073ceb.zip
Add account view
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/accounts.ts37
-rw-r--r--server/controllers/api/index.ts2
-rw-r--r--server/controllers/api/users.ts3
-rw-r--r--server/controllers/api/videos/index.ts19
4 files changed, 40 insertions, 21 deletions
diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts
index 4dc0cc16d..06ab04033 100644
--- a/server/controllers/api/accounts.ts
+++ b/server/controllers/api/accounts.ts
@@ -1,8 +1,11 @@
1import * as express from 'express' 1import * as express from 'express'
2import { getFormattedObjects } from '../../helpers/utils' 2import { getFormattedObjects } from '../../helpers/utils'
3import { asyncMiddleware, paginationValidator, setDefaultSort, setDefaultPagination } from '../../middlewares' 3import { asyncMiddleware, optionalAuthenticate, paginationValidator, setDefaultPagination, setDefaultSort } from '../../middlewares'
4import { accountsGetValidator, accountsSortValidator } from '../../middlewares/validators' 4import { accountsGetValidator, accountsSortValidator, videosSortValidator } from '../../middlewares/validators'
5import { AccountModel } from '../../models/account/account' 5import { AccountModel } from '../../models/account/account'
6import { VideoModel } from '../../models/video/video'
7import { VideoSortField } from '../../../client/src/app/shared/video/sort-field.type'
8import { isNSFWHidden } from '../../helpers/express-utils'
6 9
7const accountsRouter = express.Router() 10const accountsRouter = express.Router()
8 11
@@ -19,6 +22,16 @@ accountsRouter.get('/:id',
19 getAccount 22 getAccount
20) 23)
21 24
25accountsRouter.get('/:id/videos',
26 asyncMiddleware(accountsGetValidator),
27 paginationValidator,
28 videosSortValidator,
29 setDefaultSort,
30 setDefaultPagination,
31 optionalAuthenticate,
32 asyncMiddleware(getAccountVideos)
33)
34
22// --------------------------------------------------------------------------- 35// ---------------------------------------------------------------------------
23 36
24export { 37export {
@@ -28,7 +41,9 @@ export {
28// --------------------------------------------------------------------------- 41// ---------------------------------------------------------------------------
29 42
30function getAccount (req: express.Request, res: express.Response, next: express.NextFunction) { 43function getAccount (req: express.Request, res: express.Response, next: express.NextFunction) {
31 return res.json(res.locals.account.toFormattedJSON()) 44 const account: AccountModel = res.locals.account
45
46 return res.json(account.toFormattedJSON())
32} 47}
33 48
34async function listAccounts (req: express.Request, res: express.Response, next: express.NextFunction) { 49async function listAccounts (req: express.Request, res: express.Response, next: express.NextFunction) {
@@ -36,3 +51,19 @@ async function listAccounts (req: express.Request, res: express.Response, next:
36 51
37 return res.json(getFormattedObjects(resultList.data, resultList.total)) 52 return res.json(getFormattedObjects(resultList.data, resultList.total))
38} 53}
54
55async function getAccountVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
56 const account: AccountModel = res.locals.account
57
58 const resultList = await VideoModel.listForApi(
59 req.query.start as number,
60 req.query.count as number,
61 req.query.sort as VideoSortField,
62 isNSFWHidden(res),
63 null,
64 false,
65 account.id
66 )
67
68 return res.json(getFormattedObjects(resultList.data, resultList.total))
69}
diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts
index 3b499f3b7..964d5d04c 100644
--- a/server/controllers/api/index.ts
+++ b/server/controllers/api/index.ts
@@ -1,5 +1,4 @@
1import * as express from 'express' 1import * as express from 'express'
2import { badRequest } from '../../helpers/utils'
3import { configRouter } from './config' 2import { configRouter } from './config'
4import { jobsRouter } from './jobs' 3import { jobsRouter } from './jobs'
5import { oauthClientsRouter } from './oauth-clients' 4import { oauthClientsRouter } from './oauth-clients'
@@ -7,6 +6,7 @@ import { serverRouter } from './server'
7import { usersRouter } from './users' 6import { usersRouter } from './users'
8import { accountsRouter } from './accounts' 7import { accountsRouter } from './accounts'
9import { videosRouter } from './videos' 8import { videosRouter } from './videos'
9import { badRequest } from '../../helpers/express-utils'
10 10
11const apiRouter = express.Router() 11const apiRouter = express.Router()
12 12
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts
index 6540adb1c..474329b58 100644
--- a/server/controllers/api/users.ts
+++ b/server/controllers/api/users.ts
@@ -7,7 +7,7 @@ import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRat
7import { retryTransactionWrapper } from '../../helpers/database-utils' 7import { retryTransactionWrapper } from '../../helpers/database-utils'
8import { processImage } from '../../helpers/image-utils' 8import { processImage } from '../../helpers/image-utils'
9import { logger } from '../../helpers/logger' 9import { logger } from '../../helpers/logger'
10import { createReqFiles, getFormattedObjects } from '../../helpers/utils' 10import { getFormattedObjects } from '../../helpers/utils'
11import { AVATARS_SIZE, CONFIG, IMAGE_MIMETYPE_EXT, RATES_LIMIT, sequelizeTypescript } from '../../initializers' 11import { AVATARS_SIZE, CONFIG, IMAGE_MIMETYPE_EXT, RATES_LIMIT, sequelizeTypescript } from '../../initializers'
12import { updateActorAvatarInstance } from '../../lib/activitypub' 12import { updateActorAvatarInstance } from '../../lib/activitypub'
13import { sendUpdateActor } from '../../lib/activitypub/send' 13import { sendUpdateActor } from '../../lib/activitypub/send'
@@ -43,6 +43,7 @@ import { UserModel } from '../../models/account/user'
43import { OAuthTokenModel } from '../../models/oauth/oauth-token' 43import { OAuthTokenModel } from '../../models/oauth/oauth-token'
44import { VideoModel } from '../../models/video/video' 44import { VideoModel } from '../../models/video/video'
45import { VideoSortField } from '../../../client/src/app/shared/video/sort-field.type' 45import { VideoSortField } from '../../../client/src/app/shared/video/sort-field.type'
46import { createReqFiles } from '../../helpers/express-utils'
46 47
47const reqAvatarFile = createReqFiles([ 'avatarfile' ], IMAGE_MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.AVATARS_DIR }) 48const reqAvatarFile = createReqFiles([ 'avatarfile' ], IMAGE_MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.AVATARS_DIR })
48const loginRateLimiter = new RateLimit({ 49const loginRateLimiter = new RateLimit({
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 6e8601fa1..61b6c5826 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -6,7 +6,7 @@ import { retryTransactionWrapper } from '../../../helpers/database-utils'
6import { getVideoFileResolution } from '../../../helpers/ffmpeg-utils' 6import { getVideoFileResolution } from '../../../helpers/ffmpeg-utils'
7import { processImage } from '../../../helpers/image-utils' 7import { processImage } from '../../../helpers/image-utils'
8import { logger } from '../../../helpers/logger' 8import { logger } from '../../../helpers/logger'
9import { createReqFiles, getFormattedObjects, getServerActor, resetSequelizeInstance } from '../../../helpers/utils' 9import { getFormattedObjects, getServerActor, resetSequelizeInstance } from '../../../helpers/utils'
10import { 10import {
11 CONFIG, 11 CONFIG,
12 IMAGE_MIMETYPE_EXT, 12 IMAGE_MIMETYPE_EXT,
@@ -19,11 +19,7 @@ import {
19 VIDEO_MIMETYPE_EXT, 19 VIDEO_MIMETYPE_EXT,
20 VIDEO_PRIVACIES 20 VIDEO_PRIVACIES
21} from '../../../initializers' 21} from '../../../initializers'
22import { 22import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub'
23 fetchRemoteVideoDescription,
24 getVideoActivityPubUrl,
25 shareVideoByServerAndChannel
26} from '../../../lib/activitypub'
27import { sendCreateVideo, sendCreateView, sendUpdateVideo } from '../../../lib/activitypub/send' 23import { sendCreateVideo, sendCreateView, sendUpdateVideo } from '../../../lib/activitypub/send'
28import { JobQueue } from '../../../lib/job-queue' 24import { JobQueue } from '../../../lib/job-queue'
29import { Redis } from '../../../lib/redis' 25import { Redis } from '../../../lib/redis'
@@ -49,9 +45,9 @@ import { blacklistRouter } from './blacklist'
49import { videoChannelRouter } from './channel' 45import { videoChannelRouter } from './channel'
50import { videoCommentRouter } from './comment' 46import { videoCommentRouter } from './comment'
51import { rateVideoRouter } from './rate' 47import { rateVideoRouter } from './rate'
52import { User } from '../../../../shared/models/users'
53import { VideoFilter } from '../../../../shared/models/videos/video-query.type' 48import { VideoFilter } from '../../../../shared/models/videos/video-query.type'
54import { VideoSortField } from '../../../../client/src/app/shared/video/sort-field.type' 49import { VideoSortField } from '../../../../client/src/app/shared/video/sort-field.type'
50import { isNSFWHidden, createReqFiles } from '../../../helpers/express-utils'
55 51
56const videosRouter = express.Router() 52const videosRouter = express.Router()
57 53
@@ -444,12 +440,3 @@ async function searchVideos (req: express.Request, res: express.Response, next:
444 440
445 return res.json(getFormattedObjects(resultList.data, resultList.total)) 441 return res.json(getFormattedObjects(resultList.data, resultList.total))
446} 442}
447
448function isNSFWHidden (res: express.Response) {
449 if (res.locals.oauth) {
450 const user: User = res.locals.oauth.token.User
451 if (user) return user.nsfwPolicy === 'do_not_list'
452 }
453
454 return CONFIG.INSTANCE.DEFAULT_NSFW_POLICY === 'do_not_list'
455}