+async function getUserVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
+ const user = res.locals.oauth.token.User as UserModel
+ const resultList = await VideoModel.listAccountVideosForApi(
+ user.Account.id,
+ req.query.start as number,
+ req.query.count as number,
+ req.query.sort as VideoSortField,
+ false // Display my NSFW videos
+ )
+
+ return res.json(getFormattedObjects(resultList.data, resultList.total))
+}
+
+async function createUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
+ const options = {
+ arguments: [ req ],
+ errorMessage: 'Cannot insert the user with many retries.'
+ }
+
+ const { user, account } = await retryTransactionWrapper(createUser, options)
+
+ return res.json({
+ user: {
+ id: user.id,
+ account: {
+ id: account.id,
+ uuid: account.Actor.uuid
+ }
+ }
+ }).end()
+}
+
+async function createUser (req: express.Request) {
+ const body: UserCreate = req.body
+ const userToCreate = new UserModel({
+ username: body.username,
+ password: body.password,
+ email: body.email,
+ nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
+ autoPlayVideo: true,
+ role: body.role,
+ videoQuota: body.videoQuota
+ })
+
+ const { user, account } = await createUserAccountAndChannel(userToCreate)
+
+ logger.info('User %s with its channel and account created.', body.username)
+
+ return { user, account }
+}
+
+async function registerUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
+ const options = {
+ arguments: [ req ],
+ errorMessage: 'Cannot insert the user with many retries.'
+ }
+
+ await retryTransactionWrapper(registerUser, options)
+
+ return res.type('json').status(204).end()
+}
+
+async function registerUser (req: express.Request) {