diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-12-07 14:32:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-07 14:32:36 +0100 |
commit | 2d53be0267acc49cda46707b885096193a1f4e9c (patch) | |
tree | 887061a34bc67f40acbb96a6278f9544bf83caeb /server/controllers/api/users | |
parent | adc1f09c0dbd997f34028c1c82d1c118dc8ead80 (diff) | |
download | PeerTube-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.ts | 19 | ||||
-rw-r--r-- | server/controllers/api/users/me.ts | 5 | ||||
-rw-r--r-- | server/controllers/api/users/my-blocklist.ts | 9 | ||||
-rw-r--r-- | server/controllers/api/users/my-history.ts | 5 | ||||
-rw-r--r-- | server/controllers/api/users/my-notifications.ts | 7 | ||||
-rw-r--r-- | server/controllers/api/users/my-subscriptions.ts | 7 |
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' | |||
52 | import { myNotificationsRouter } from './my-notifications' | 52 | import { myNotificationsRouter } from './my-notifications' |
53 | import { mySubscriptionsRouter } from './my-subscriptions' | 53 | import { mySubscriptionsRouter } from './my-subscriptions' |
54 | import { myVideoPlaylistsRouter } from './my-video-playlists' | 54 | import { myVideoPlaylistsRouter } from './my-video-playlists' |
55 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
55 | 56 | ||
56 | const auditLogger = auditLoggerFactory('users') | 57 | const 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 | ||
261 | async function unblockUser (req: express.Request, res: express.Response) { | 262 | async 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 | ||
271 | async function blockUser (req: express.Request, res: express.Response) { | 272 | async 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 | ||
282 | function getUser (req: express.Request, res: express.Response) { | 283 | function 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 | ||
316 | async function updateUser (req: express.Request, res: express.Response) { | 317 | async 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 | ||
344 | async function askResetUserPassword (req: express.Request, res: express.Response) { | 345 | async 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 | ||
354 | async function resetUserPassword (req: express.Request, res: express.Response) { | 355 | async 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 | ||
364 | async function reSendVerifyUserEmail (req: express.Request, res: express.Response) { | 365 | async 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 | ||
372 | async function verifyUserEmail (req: express.Request, res: express.Response) { | 373 | async 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 | ||
386 | async function changeUserBlock (res: express.Response, user: MUserAccountDefault, block: boolean, reason?: string) { | 387 | async 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 | |||
28 | import { UserModel } from '../../../models/account/user' | 28 | import { UserModel } from '../../../models/account/user' |
29 | import { VideoModel } from '../../../models/video/video' | 29 | import { VideoModel } from '../../../models/video/video' |
30 | import { VideoImportModel } from '../../../models/video/video-import' | 30 | import { VideoImportModel } from '../../../models/video/video-import' |
31 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
31 | 32 | ||
32 | const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR }) | 33 | const 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 | ||
168 | async function updateMe (req: express.Request, res: express.Response) { | 169 | async 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 | ||
216 | async function updateMyAvatar (req: express.Request, res: express.Response) { | 217 | async 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 | |||
22 | import { ServerBlocklistModel } from '../../../models/server/server-blocklist' | 22 | import { ServerBlocklistModel } from '../../../models/server/server-blocklist' |
23 | import { UserNotificationModel } from '@server/models/account/user-notification' | 23 | import { UserNotificationModel } from '@server/models/account/user-notification' |
24 | import { logger } from '@server/helpers/logger' | 24 | import { logger } from '@server/helpers/logger' |
25 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
25 | 26 | ||
26 | const myBlocklistRouter = express.Router() | 27 | const 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 | ||
105 | async function unblockAccount (req: express.Request, res: express.Response) { | 106 | async 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 | ||
113 | async function listBlockedServers (req: express.Request, res: express.Response) { | 114 | async 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 | ||
142 | async function unblockServer (req: express.Request, res: express.Response) { | 143 | async 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 { | |||
10 | import { getFormattedObjects } from '../../../helpers/utils' | 10 | import { getFormattedObjects } from '../../../helpers/utils' |
11 | import { UserVideoHistoryModel } from '../../../models/account/user-video-history' | 11 | import { UserVideoHistoryModel } from '../../../models/account/user-video-history' |
12 | import { sequelizeTypescript } from '../../../initializers/database' | 12 | import { sequelizeTypescript } from '../../../initializers/database' |
13 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
13 | 14 | ||
14 | const myVideosHistoryRouter = express.Router() | 15 | const 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' |
20 | import { UserNotificationSetting } from '../../../../shared/models/users' | 20 | import { UserNotificationSetting } from '../../../../shared/models/users' |
21 | import { UserNotificationSettingModel } from '../../../models/account/user-notification-setting' | 21 | import { UserNotificationSettingModel } from '../../../models/account/user-notification-setting' |
22 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
22 | 23 | ||
23 | const myNotificationsRouter = express.Router() | 24 | const 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 | ||
90 | async function listUserNotifications (req: express.Request, res: express.Response) { | 91 | async 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 | ||
106 | async function markAsReadAllUserNotifications (req: express.Request, res: express.Response) { | 107 | async 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 { | |||
27 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 27 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
28 | import { VideoModel } from '../../../models/video/video' | 28 | import { VideoModel } from '../../../models/video/video' |
29 | import { sendUndoFollow } from '@server/lib/activitypub/send' | 29 | import { sendUndoFollow } from '@server/lib/activitypub/send' |
30 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
30 | 31 | ||
31 | const mySubscriptionsRouter = express.Router() | 32 | const 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 | ||
132 | function getUserSubscription (req: express.Request, res: express.Response) { | 133 | function 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 | ||
150 | async function getUserSubscriptions (req: express.Request, res: express.Response) { | 153 | async function getUserSubscriptions (req: express.Request, res: express.Response) { |