From ed31c059851a30bd5ba9999f8ecb3822d576b9f4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 2 Aug 2018 17:48:50 +0200 Subject: Add ability to list video imports --- server/controllers/api/users.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'server/controllers/api/users.ts') diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index dbe736bff..6e5f9913e 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts @@ -29,7 +29,12 @@ import { usersUpdateValidator, usersVideoRatingValidator } from '../../middlewares' -import { usersAskResetPasswordValidator, usersResetPasswordValidator, videosSortValidator } from '../../middlewares/validators' +import { + usersAskResetPasswordValidator, + usersResetPasswordValidator, + videoImportsSortValidator, + videosSortValidator +} from '../../middlewares/validators' import { AccountVideoRateModel } from '../../models/account/account-video-rate' import { UserModel } from '../../models/account/user' import { OAuthTokenModel } from '../../models/oauth/oauth-token' @@ -40,6 +45,7 @@ import { UserVideoQuota } from '../../../shared/models/users/user-video-quota.mo import { updateAvatarValidator } from '../../middlewares/validators/avatar' import { updateActorAvatarFile } from '../../lib/avatar' import { auditLoggerFactory, UserAuditView } from '../../helpers/audit-logger' +import { VideoImportModel } from '../../models/video/video-import' const auditLogger = auditLoggerFactory('users') @@ -62,6 +68,16 @@ usersRouter.get('/me/video-quota-used', asyncMiddleware(getUserVideoQuotaUsed) ) + +usersRouter.get('/me/videos/imports', + authenticate, + paginationValidator, + videoImportsSortValidator, + setDefaultSort, + setDefaultPagination, + asyncMiddleware(getUserVideoImports) +) + usersRouter.get('/me/videos', authenticate, paginationValidator, @@ -178,6 +194,18 @@ async function getUserVideos (req: express.Request, res: express.Response, next: return res.json(getFormattedObjects(resultList.data, resultList.total, { additionalAttributes })) } +async function getUserVideoImports (req: express.Request, res: express.Response, next: express.NextFunction) { + const user = res.locals.oauth.token.User as UserModel + const resultList = await VideoImportModel.listUserVideoImportsForApi( + user.Account.id, + req.query.start as number, + req.query.count as number, + req.query.sort + ) + + return res.json(getFormattedObjects(resultList.data, resultList.total)) +} + async function createUser (req: express.Request, res: express.Response) { const body: UserCreate = req.body const userToCreate = new UserModel({ -- cgit v1.2.3