aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/users
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-12-07 14:32:36 +0100
committerGitHub <noreply@github.com>2020-12-07 14:32:36 +0100
commit2d53be0267acc49cda46707b885096193a1f4e9c (patch)
tree887061a34bc67f40acbb96a6278f9544bf83caeb /server/controllers/api/users
parentadc1f09c0dbd997f34028c1c82d1c118dc8ead80 (diff)
downloadPeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.gz
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.zst
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.zip
replace numbers with typed http status codes (#3409)
Diffstat (limited to 'server/controllers/api/users')
-rw-r--r--server/controllers/api/users/index.ts19
-rw-r--r--server/controllers/api/users/me.ts5
-rw-r--r--server/controllers/api/users/my-blocklist.ts9
-rw-r--r--server/controllers/api/users/my-history.ts5
-rw-r--r--server/controllers/api/users/my-notifications.ts7
-rw-r--r--server/controllers/api/users/my-subscriptions.ts7
6 files changed, 31 insertions, 21 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts
index 5b113feac..d743a9912 100644
--- a/server/controllers/api/users/index.ts
+++ b/server/controllers/api/users/index.ts
@@ -52,6 +52,7 @@ import { myVideosHistoryRouter } from './my-history'
52import { myNotificationsRouter } from './my-notifications' 52import { myNotificationsRouter } from './my-notifications'
53import { mySubscriptionsRouter } from './my-subscriptions' 53import { mySubscriptionsRouter } from './my-subscriptions'
54import { myVideoPlaylistsRouter } from './my-video-playlists' 54import { myVideoPlaylistsRouter } from './my-video-playlists'
55import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
55 56
56const auditLogger = auditLoggerFactory('users') 57const auditLogger = auditLoggerFactory('users')
57 58
@@ -255,7 +256,7 @@ async function registerUser (req: express.Request, res: express.Response) {
255 256
256 Hooks.runAction('action:api.user.registered', { body, user, account, videoChannel }) 257 Hooks.runAction('action:api.user.registered', { body, user, account, videoChannel })
257 258
258 return res.type('json').status(204).end() 259 return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
259} 260}
260 261
261async function unblockUser (req: express.Request, res: express.Response) { 262async function unblockUser (req: express.Request, res: express.Response) {
@@ -265,7 +266,7 @@ async function unblockUser (req: express.Request, res: express.Response) {
265 266
266 Hooks.runAction('action:api.user.unblocked', { user }) 267 Hooks.runAction('action:api.user.unblocked', { user })
267 268
268 return res.status(204).end() 269 return res.status(HttpStatusCode.NO_CONTENT_204).end()
269} 270}
270 271
271async function blockUser (req: express.Request, res: express.Response) { 272async function blockUser (req: express.Request, res: express.Response) {
@@ -276,7 +277,7 @@ async function blockUser (req: express.Request, res: express.Response) {
276 277
277 Hooks.runAction('action:api.user.blocked', { user }) 278 Hooks.runAction('action:api.user.blocked', { user })
278 279
279 return res.status(204).end() 280 return res.status(HttpStatusCode.NO_CONTENT_204).end()
280} 281}
281 282
282function getUser (req: express.Request, res: express.Response) { 283function getUser (req: express.Request, res: express.Response) {
@@ -310,7 +311,7 @@ async function removeUser (req: express.Request, res: express.Response) {
310 311
311 Hooks.runAction('action:api.user.deleted', { user }) 312 Hooks.runAction('action:api.user.deleted', { user })
312 313
313 return res.sendStatus(204) 314 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
314} 315}
315 316
316async function updateUser (req: express.Request, res: express.Response) { 317async function updateUser (req: express.Request, res: express.Response) {
@@ -338,7 +339,7 @@ async function updateUser (req: express.Request, res: express.Response) {
338 339
339 // Don't need to send this update to followers, these attributes are not federated 340 // Don't need to send this update to followers, these attributes are not federated
340 341
341 return res.sendStatus(204) 342 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
342} 343}
343 344
344async function askResetUserPassword (req: express.Request, res: express.Response) { 345async function askResetUserPassword (req: express.Request, res: express.Response) {
@@ -348,7 +349,7 @@ async function askResetUserPassword (req: express.Request, res: express.Response
348 const url = WEBSERVER.URL + '/reset-password?userId=' + user.id + '&verificationString=' + verificationString 349 const url = WEBSERVER.URL + '/reset-password?userId=' + user.id + '&verificationString=' + verificationString
349 await Emailer.Instance.addPasswordResetEmailJob(user.username, user.email, url) 350 await Emailer.Instance.addPasswordResetEmailJob(user.username, user.email, url)
350 351
351 return res.status(204).end() 352 return res.status(HttpStatusCode.NO_CONTENT_204).end()
352} 353}
353 354
354async function resetUserPassword (req: express.Request, res: express.Response) { 355async function resetUserPassword (req: express.Request, res: express.Response) {
@@ -358,7 +359,7 @@ async function resetUserPassword (req: express.Request, res: express.Response) {
358 await user.save() 359 await user.save()
359 await Redis.Instance.removePasswordVerificationString(user.id) 360 await Redis.Instance.removePasswordVerificationString(user.id)
360 361
361 return res.status(204).end() 362 return res.status(HttpStatusCode.NO_CONTENT_204).end()
362} 363}
363 364
364async function reSendVerifyUserEmail (req: express.Request, res: express.Response) { 365async function reSendVerifyUserEmail (req: express.Request, res: express.Response) {
@@ -366,7 +367,7 @@ async function reSendVerifyUserEmail (req: express.Request, res: express.Respons
366 367
367 await sendVerifyUserEmail(user) 368 await sendVerifyUserEmail(user)
368 369
369 return res.status(204).end() 370 return res.status(HttpStatusCode.NO_CONTENT_204).end()
370} 371}
371 372
372async function verifyUserEmail (req: express.Request, res: express.Response) { 373async function verifyUserEmail (req: express.Request, res: express.Response) {
@@ -380,7 +381,7 @@ async function verifyUserEmail (req: express.Request, res: express.Response) {
380 381
381 await user.save() 382 await user.save()
382 383
383 return res.status(204).end() 384 return res.status(HttpStatusCode.NO_CONTENT_204).end()
384} 385}
385 386
386async function changeUserBlock (res: express.Response, user: MUserAccountDefault, block: boolean, reason?: string) { 387async function changeUserBlock (res: express.Response, user: MUserAccountDefault, block: boolean, reason?: string) {
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts
index b490518fc..3d2a325fe 100644
--- a/server/controllers/api/users/me.ts
+++ b/server/controllers/api/users/me.ts
@@ -28,6 +28,7 @@ import { AccountVideoRateModel } from '../../../models/account/account-video-rat
28import { UserModel } from '../../../models/account/user' 28import { UserModel } from '../../../models/account/user'
29import { VideoModel } from '../../../models/video/video' 29import { VideoModel } from '../../../models/video/video'
30import { VideoImportModel } from '../../../models/video/video-import' 30import { VideoImportModel } from '../../../models/video/video-import'
31import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
31 32
32const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR }) 33const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR })
33 34
@@ -162,7 +163,7 @@ async function deleteMe (req: express.Request, res: express.Response) {
162 163
163 await user.destroy() 164 await user.destroy()
164 165
165 return res.sendStatus(204) 166 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
166} 167}
167 168
168async function updateMe (req: express.Request, res: express.Response) { 169async function updateMe (req: express.Request, res: express.Response) {
@@ -210,7 +211,7 @@ async function updateMe (req: express.Request, res: express.Response) {
210 await sendVerifyUserEmail(user, true) 211 await sendVerifyUserEmail(user, true)
211 } 212 }
212 213
213 return res.sendStatus(204) 214 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
214} 215}
215 216
216async function updateMyAvatar (req: express.Request, res: express.Response) { 217async function updateMyAvatar (req: express.Request, res: express.Response) {
diff --git a/server/controllers/api/users/my-blocklist.ts b/server/controllers/api/users/my-blocklist.ts
index 6eba22d52..faaef3ac0 100644
--- a/server/controllers/api/users/my-blocklist.ts
+++ b/server/controllers/api/users/my-blocklist.ts
@@ -22,6 +22,7 @@ import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist
22import { ServerBlocklistModel } from '../../../models/server/server-blocklist' 22import { ServerBlocklistModel } from '../../../models/server/server-blocklist'
23import { UserNotificationModel } from '@server/models/account/user-notification' 23import { UserNotificationModel } from '@server/models/account/user-notification'
24import { logger } from '@server/helpers/logger' 24import { logger } from '@server/helpers/logger'
25import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
25 26
26const myBlocklistRouter = express.Router() 27const myBlocklistRouter = express.Router()
27 28
@@ -99,7 +100,7 @@ async function blockAccount (req: express.Request, res: express.Response) {
99 forUserId: user.id 100 forUserId: user.id
100 }).catch(err => logger.error('Cannot remove notifications after an account mute.', { err })) 101 }).catch(err => logger.error('Cannot remove notifications after an account mute.', { err }))
101 102
102 return res.status(204).end() 103 return res.status(HttpStatusCode.NO_CONTENT_204).end()
103} 104}
104 105
105async function unblockAccount (req: express.Request, res: express.Response) { 106async function unblockAccount (req: express.Request, res: express.Response) {
@@ -107,7 +108,7 @@ async function unblockAccount (req: express.Request, res: express.Response) {
107 108
108 await removeAccountFromBlocklist(accountBlock) 109 await removeAccountFromBlocklist(accountBlock)
109 110
110 return res.status(204).end() 111 return res.status(HttpStatusCode.NO_CONTENT_204).end()
111} 112}
112 113
113async function listBlockedServers (req: express.Request, res: express.Response) { 114async function listBlockedServers (req: express.Request, res: express.Response) {
@@ -136,7 +137,7 @@ async function blockServer (req: express.Request, res: express.Response) {
136 forUserId: user.id 137 forUserId: user.id
137 }).catch(err => logger.error('Cannot remove notifications after a server mute.', { err })) 138 }).catch(err => logger.error('Cannot remove notifications after a server mute.', { err }))
138 139
139 return res.status(204).end() 140 return res.status(HttpStatusCode.NO_CONTENT_204).end()
140} 141}
141 142
142async function unblockServer (req: express.Request, res: express.Response) { 143async function unblockServer (req: express.Request, res: express.Response) {
@@ -144,5 +145,5 @@ async function unblockServer (req: express.Request, res: express.Response) {
144 145
145 await removeServerFromBlocklist(serverBlock) 146 await removeServerFromBlocklist(serverBlock)
146 147
147 return res.status(204).end() 148 return res.status(HttpStatusCode.NO_CONTENT_204).end()
148} 149}
diff --git a/server/controllers/api/users/my-history.ts b/server/controllers/api/users/my-history.ts
index dc915977f..80d4dc748 100644
--- a/server/controllers/api/users/my-history.ts
+++ b/server/controllers/api/users/my-history.ts
@@ -10,6 +10,7 @@ import {
10import { getFormattedObjects } from '../../../helpers/utils' 10import { getFormattedObjects } from '../../../helpers/utils'
11import { UserVideoHistoryModel } from '../../../models/account/user-video-history' 11import { UserVideoHistoryModel } from '../../../models/account/user-video-history'
12import { sequelizeTypescript } from '../../../initializers/database' 12import { sequelizeTypescript } from '../../../initializers/database'
13import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
13 14
14const myVideosHistoryRouter = express.Router() 15const myVideosHistoryRouter = express.Router()
15 16
@@ -50,5 +51,7 @@ async function removeUserHistory (req: express.Request, res: express.Response) {
50 return UserVideoHistoryModel.removeUserHistoryBefore(user, beforeDate, t) 51 return UserVideoHistoryModel.removeUserHistoryBefore(user, beforeDate, t)
51 }) 52 })
52 53
53 return res.type('json').status(204).end() 54 return res.type('json')
55 .status(HttpStatusCode.NO_CONTENT_204)
56 .end()
54} 57}
diff --git a/server/controllers/api/users/my-notifications.ts b/server/controllers/api/users/my-notifications.ts
index 050866960..5f5e4c5e6 100644
--- a/server/controllers/api/users/my-notifications.ts
+++ b/server/controllers/api/users/my-notifications.ts
@@ -19,6 +19,7 @@ import {
19} from '../../../middlewares/validators/user-notifications' 19} from '../../../middlewares/validators/user-notifications'
20import { UserNotificationSetting } from '../../../../shared/models/users' 20import { UserNotificationSetting } from '../../../../shared/models/users'
21import { UserNotificationSettingModel } from '../../../models/account/user-notification-setting' 21import { UserNotificationSettingModel } from '../../../models/account/user-notification-setting'
22import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
22 23
23const myNotificationsRouter = express.Router() 24const myNotificationsRouter = express.Router()
24 25
@@ -84,7 +85,7 @@ async function updateNotificationSettings (req: express.Request, res: express.Re
84 85
85 await UserNotificationSettingModel.update(values, query) 86 await UserNotificationSettingModel.update(values, query)
86 87
87 return res.status(204).end() 88 return res.status(HttpStatusCode.NO_CONTENT_204).end()
88} 89}
89 90
90async function listUserNotifications (req: express.Request, res: express.Response) { 91async function listUserNotifications (req: express.Request, res: express.Response) {
@@ -100,7 +101,7 @@ async function markAsReadUserNotifications (req: express.Request, res: express.R
100 101
101 await UserNotificationModel.markAsRead(user.id, req.body.ids) 102 await UserNotificationModel.markAsRead(user.id, req.body.ids)
102 103
103 return res.status(204).end() 104 return res.status(HttpStatusCode.NO_CONTENT_204).end()
104} 105}
105 106
106async function markAsReadAllUserNotifications (req: express.Request, res: express.Response) { 107async function markAsReadAllUserNotifications (req: express.Request, res: express.Response) {
@@ -108,5 +109,5 @@ async function markAsReadAllUserNotifications (req: express.Request, res: expres
108 109
109 await UserNotificationModel.markAllAsRead(user.id) 110 await UserNotificationModel.markAllAsRead(user.id)
110 111
111 return res.status(204).end() 112 return res.status(HttpStatusCode.NO_CONTENT_204).end()
112} 113}
diff --git a/server/controllers/api/users/my-subscriptions.ts b/server/controllers/api/users/my-subscriptions.ts
index 66b33c477..ec77ddd7a 100644
--- a/server/controllers/api/users/my-subscriptions.ts
+++ b/server/controllers/api/users/my-subscriptions.ts
@@ -27,6 +27,7 @@ import {
27import { ActorFollowModel } from '../../../models/activitypub/actor-follow' 27import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
28import { VideoModel } from '../../../models/video/video' 28import { VideoModel } from '../../../models/video/video'
29import { sendUndoFollow } from '@server/lib/activitypub/send' 29import { sendUndoFollow } from '@server/lib/activitypub/send'
30import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
30 31
31const mySubscriptionsRouter = express.Router() 32const mySubscriptionsRouter = express.Router()
32 33
@@ -126,7 +127,7 @@ function addUserSubscription (req: express.Request, res: express.Response) {
126 127
127 JobQueue.Instance.createJob({ type: 'activitypub-follow', payload }) 128 JobQueue.Instance.createJob({ type: 'activitypub-follow', payload })
128 129
129 return res.status(204).end() 130 return res.status(HttpStatusCode.NO_CONTENT_204).end()
130} 131}
131 132
132function getUserSubscription (req: express.Request, res: express.Response) { 133function getUserSubscription (req: express.Request, res: express.Response) {
@@ -144,7 +145,9 @@ async function deleteUserSubscription (req: express.Request, res: express.Respon
144 return subscription.destroy({ transaction: t }) 145 return subscription.destroy({ transaction: t })
145 }) 146 })
146 147
147 return res.type('json').status(204).end() 148 return res.type('json')
149 .status(HttpStatusCode.NO_CONTENT_204)
150 .end()
148} 151}
149 152
150async function getUserSubscriptions (req: express.Request, res: express.Response) { 153async function getUserSubscriptions (req: express.Request, res: express.Response) {