mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
replace numbers with typed http status codes (#3409)
This commit is contained in:
parent
adc1f09c0d
commit
2d53be0267
149 changed files with 1721 additions and 1108 deletions
|
@ -18,6 +18,7 @@ import {
|
|||
videosBlacklistUpdateValidator
|
||||
} from '../../../middlewares'
|
||||
import { VideoBlacklistModel } from '../../../models/video/video-blacklist'
|
||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
const blacklistRouter = express.Router()
|
||||
|
||||
|
@ -69,7 +70,7 @@ async function addVideoToBlacklistController (req: express.Request, res: express
|
|||
|
||||
logger.info('Video %s blacklisted.', videoInstance.uuid)
|
||||
|
||||
return res.type('json').sendStatus(204)
|
||||
return res.type('json').sendStatus(HttpStatusCode.NO_CONTENT_204)
|
||||
}
|
||||
|
||||
async function updateVideoBlacklistController (req: express.Request, res: express.Response) {
|
||||
|
@ -81,7 +82,7 @@ async function updateVideoBlacklistController (req: express.Request, res: expres
|
|||
return videoBlacklist.save({ transaction: t })
|
||||
})
|
||||
|
||||
return res.type('json').sendStatus(204)
|
||||
return res.type('json').sendStatus(HttpStatusCode.NO_CONTENT_204)
|
||||
}
|
||||
|
||||
async function listBlacklist (req: express.Request, res: express.Response) {
|
||||
|
@ -104,5 +105,5 @@ async function removeVideoFromBlacklistController (req: express.Request, res: ex
|
|||
|
||||
logger.info('Video %s removed from blacklist.', video.uuid)
|
||||
|
||||
return res.type('json').sendStatus(204)
|
||||
return res.type('json').sendStatus(HttpStatusCode.NO_CONTENT_204)
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils'
|
|||
import { CONFIG } from '../../../initializers/config'
|
||||
import { sequelizeTypescript } from '../../../initializers/database'
|
||||
import { MVideoCaptionVideo } from '@server/types/models'
|
||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
const reqVideoCaptionAdd = createReqFiles(
|
||||
[ 'captionfile' ],
|
||||
|
@ -72,7 +73,7 @@ async function addVideoCaption (req: express.Request, res: express.Response) {
|
|||
await federateVideoIfNeeded(video, false, t)
|
||||
})
|
||||
|
||||
return res.status(204).end()
|
||||
return res.status(HttpStatusCode.NO_CONTENT_204).end()
|
||||
}
|
||||
|
||||
async function deleteVideoCaption (req: express.Request, res: express.Response) {
|
||||
|
@ -88,5 +89,5 @@ async function deleteVideoCaption (req: express.Request, res: express.Response)
|
|||
|
||||
logger.info('Video caption %s of video %s deleted.', videoCaption.language, video.uuid)
|
||||
|
||||
return res.type('json').status(204).end()
|
||||
return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import {
|
|||
} from '../../../middlewares/validators'
|
||||
import { AccountModel } from '../../../models/account/account'
|
||||
import { VideoCommentModel } from '../../../models/video/video-comment'
|
||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
const auditLogger = auditLoggerFactory('comments')
|
||||
const videoCommentRouter = express.Router()
|
||||
|
@ -161,7 +162,7 @@ async function listVideoThreadComments (req: express.Request, res: express.Respo
|
|||
}
|
||||
|
||||
if (resultList.data.length === 0) {
|
||||
return res.sendStatus(404)
|
||||
return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
|
||||
}
|
||||
|
||||
return res.json(buildFormattedCommentTree(resultList))
|
||||
|
@ -218,5 +219,7 @@ async function removeVideoComment (req: express.Request, res: express.Response)
|
|||
|
||||
auditLogger.delete(getAuditIdFromRes(res), new CommentAuditView(videoCommentInstance.toFormattedJSON()))
|
||||
|
||||
return res.type('json').status(204).end()
|
||||
return res.type('json')
|
||||
.status(HttpStatusCode.NO_CONTENT_204)
|
||||
.end()
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoIm
|
|||
import { VideoModel } from '../../../models/video/video'
|
||||
import { VideoCaptionModel } from '../../../models/video/video-caption'
|
||||
import { VideoImportModel } from '../../../models/video/video-import'
|
||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
const auditLogger = auditLoggerFactory('video-imports')
|
||||
const videoImportsRouter = express.Router()
|
||||
|
@ -146,7 +147,7 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response)
|
|||
} catch (err) {
|
||||
logger.info('Cannot fetch information from import for URL %s.', targetUrl, { err })
|
||||
|
||||
return res.status(400).json({
|
||||
return res.status(HttpStatusCode.BAD_REQUEST_400).json({
|
||||
error: 'Cannot fetch remote information of this URL.'
|
||||
}).end()
|
||||
}
|
||||
|
|
|
@ -66,6 +66,7 @@ import { liveRouter } from './live'
|
|||
import { ownershipVideoRouter } from './ownership'
|
||||
import { rateVideoRouter } from './rate'
|
||||
import { watchingRouter } from './watching'
|
||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
const auditLogger = auditLoggerFactory('videos')
|
||||
const videosRouter = express.Router()
|
||||
|
@ -178,7 +179,7 @@ async function addVideo (req: express.Request, res: express.Response) {
|
|||
// Set timeout to 10 minutes, as Express's default is 2 minutes
|
||||
req.setTimeout(1000 * 60 * 10, () => {
|
||||
logger.error('Upload video has timed out.')
|
||||
return res.sendStatus(408)
|
||||
return res.sendStatus(HttpStatusCode.REQUEST_TIMEOUT_408)
|
||||
})
|
||||
|
||||
const videoPhysicalFile = req.files['videofile'][0]
|
||||
|
@ -394,7 +395,9 @@ async function updateVideo (req: express.Request, res: express.Response) {
|
|||
throw err
|
||||
}
|
||||
|
||||
return res.type('json').status(204).end()
|
||||
return res.type('json')
|
||||
.status(HttpStatusCode.NO_CONTENT_204)
|
||||
.end()
|
||||
}
|
||||
|
||||
async function getVideo (req: express.Request, res: express.Response) {
|
||||
|
@ -421,7 +424,7 @@ async function viewVideo (req: express.Request, res: express.Response) {
|
|||
const exists = await Redis.Instance.doesVideoIPViewExist(ip, immutableVideoAttrs.uuid)
|
||||
if (exists) {
|
||||
logger.debug('View for ip %s and video %s already exists.', ip, immutableVideoAttrs.uuid)
|
||||
return res.sendStatus(204)
|
||||
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
|
||||
}
|
||||
|
||||
const video = await VideoModel.load(immutableVideoAttrs.id)
|
||||
|
@ -454,7 +457,7 @@ async function viewVideo (req: express.Request, res: express.Response) {
|
|||
|
||||
Hooks.runAction('action:api.video.viewed', { video, ip })
|
||||
|
||||
return res.sendStatus(204)
|
||||
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
|
||||
}
|
||||
|
||||
async function getVideoDescription (req: express.Request, res: express.Response) {
|
||||
|
@ -517,5 +520,7 @@ async function removeVideo (req: express.Request, res: express.Response) {
|
|||
|
||||
Hooks.runAction('action:api.video.deleted', { video: videoInstance })
|
||||
|
||||
return res.type('json').status(204).end()
|
||||
return res.type('json')
|
||||
.status(HttpStatusCode.NO_CONTENT_204)
|
||||
.end()
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import { sequelizeTypescript } from '../../../initializers/database'
|
|||
import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail'
|
||||
import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares'
|
||||
import { VideoModel } from '../../../models/video/video'
|
||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
const liveRouter = express.Router()
|
||||
|
||||
|
@ -75,7 +76,7 @@ async function updateLiveVideo (req: express.Request, res: express.Response) {
|
|||
|
||||
await federateVideoIfNeeded(video, false)
|
||||
|
||||
return res.sendStatus(204)
|
||||
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
|
||||
}
|
||||
|
||||
async function addLiveVideo (req: express.Request, res: express.Response) {
|
||||
|
|
|
@ -19,6 +19,7 @@ import { changeVideoChannelShare } from '../../../lib/activitypub/share'
|
|||
import { sendUpdateVideo } from '../../../lib/activitypub/send'
|
||||
import { VideoModel } from '../../../models/video/video'
|
||||
import { MVideoFullLight } from '@server/types/models'
|
||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
const ownershipVideoRouter = express.Router()
|
||||
|
||||
|
@ -80,7 +81,9 @@ async function giveVideoOwnership (req: express.Request, res: express.Response)
|
|||
})
|
||||
|
||||
logger.info('Ownership change for video %s created.', videoInstance.name)
|
||||
return res.type('json').status(204).end()
|
||||
return res.type('json')
|
||||
.status(HttpStatusCode.NO_CONTENT_204)
|
||||
.end()
|
||||
}
|
||||
|
||||
async function listVideoOwnership (req: express.Request, res: express.Response) {
|
||||
|
@ -119,7 +122,7 @@ async function acceptOwnership (req: express.Request, res: express.Response) {
|
|||
videoChangeOwnership.status = VideoChangeOwnershipStatus.ACCEPTED
|
||||
await videoChangeOwnership.save({ transaction: t })
|
||||
|
||||
return res.sendStatus(204)
|
||||
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -130,6 +133,6 @@ async function refuseOwnership (req: express.Request, res: express.Response) {
|
|||
videoChangeOwnership.status = VideoChangeOwnershipStatus.REFUSED
|
||||
await videoChangeOwnership.save({ transaction: t })
|
||||
|
||||
return res.sendStatus(204)
|
||||
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoUp
|
|||
import { AccountModel } from '../../../models/account/account'
|
||||
import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
|
||||
import { sequelizeTypescript } from '../../../initializers/database'
|
||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
const rateVideoRouter = express.Router()
|
||||
|
||||
|
@ -78,5 +79,7 @@ async function rateVideo (req: express.Request, res: express.Response) {
|
|||
logger.info('Account video rate for video %s of account %s updated.', videoInstance.name, accountInstance.name)
|
||||
})
|
||||
|
||||
return res.type('json').status(204).end()
|
||||
return res.type('json')
|
||||
.status(HttpStatusCode.NO_CONTENT_204)
|
||||
.end()
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ import * as express from 'express'
|
|||
import { UserWatchingVideo } from '../../../../shared'
|
||||
import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoWatchingValidator } from '../../../middlewares'
|
||||
import { UserVideoHistoryModel } from '../../../models/account/user-video-history'
|
||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
const watchingRouter = express.Router()
|
||||
|
||||
|
@ -31,5 +32,7 @@ async function userWatchVideo (req: express.Request, res: express.Response) {
|
|||
currentTime: body.currentTime
|
||||
})
|
||||
|
||||
return res.type('json').status(204).end()
|
||||
return res.type('json')
|
||||
.status(HttpStatusCode.NO_CONTENT_204)
|
||||
.end()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue