mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 19:42:24 +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
|
@ -1,11 +1,12 @@
|
|||
import { Response } from 'express'
|
||||
import { AbuseModel } from '../../models/abuse/abuse'
|
||||
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
async function doesAbuseExist (abuseId: number | string, res: Response) {
|
||||
const abuse = await AbuseModel.loadByIdWithReporter(parseInt(abuseId + '', 10))
|
||||
|
||||
if (!abuse) {
|
||||
res.status(404)
|
||||
res.status(HttpStatusCode.NOT_FOUND_404)
|
||||
.json({ error: 'Abuse not found' })
|
||||
|
||||
return false
|
||||
|
|
|
@ -3,6 +3,7 @@ import { AccountModel } from '../../models/account/account'
|
|||
import * as Bluebird from 'bluebird'
|
||||
import { MAccountDefault } from '../../types/models'
|
||||
import { UserModel } from '@server/models/account/user'
|
||||
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
function doesAccountIdExist (id: number | string, res: Response, sendNotFound = true) {
|
||||
const promise = AccountModel.load(parseInt(id + '', 10))
|
||||
|
@ -27,7 +28,7 @@ async function doesAccountExist (p: Bluebird<MAccountDefault>, res: Response, se
|
|||
|
||||
if (!account) {
|
||||
if (sendNotFound === true) {
|
||||
res.status(404)
|
||||
res.status(HttpStatusCode.NOT_FOUND_404)
|
||||
.json({ error: 'Account not found' })
|
||||
}
|
||||
|
||||
|
@ -43,7 +44,7 @@ async function doesUserFeedTokenCorrespond (id: number, token: string, res: Resp
|
|||
const user = await UserModel.loadByIdWithChannels(parseInt(id + '', 10))
|
||||
|
||||
if (token !== user.feedToken) {
|
||||
res.status(403)
|
||||
res.status(HttpStatusCode.FORBIDDEN_403)
|
||||
.json({ error: 'User and token mismatch' })
|
||||
|
||||
return false
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import { Response } from 'express'
|
||||
import { VideoBlacklistModel } from '../../models/video/video-blacklist'
|
||||
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
async function doesVideoBlacklistExist (videoId: number, res: Response) {
|
||||
const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId)
|
||||
|
||||
if (videoBlacklist === null) {
|
||||
res.status(404)
|
||||
res.status(HttpStatusCode.NOT_FOUND_404)
|
||||
.json({ error: 'Blacklisted video not found' })
|
||||
.end()
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import { Response } from 'express'
|
||||
import { VideoCaptionModel } from '../../models/video/video-caption'
|
||||
import { MVideoId } from '@server/types/models'
|
||||
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
async function doesVideoCaptionExist (video: MVideoId, language: string, res: Response) {
|
||||
const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language)
|
||||
|
||||
if (!videoCaption) {
|
||||
res.status(404)
|
||||
res.status(HttpStatusCode.NOT_FOUND_404)
|
||||
.json({ error: 'Video caption not found' })
|
||||
.end()
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import * as express from 'express'
|
||||
import { VideoChannelModel } from '../../models/video/video-channel'
|
||||
import { MChannelAccountDefault } from '@server/types/models'
|
||||
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
async function doesLocalVideoChannelNameExist (name: string, res: express.Response) {
|
||||
const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
|
||||
|
@ -30,7 +31,7 @@ export {
|
|||
|
||||
function processVideoChannelExist (videoChannel: MChannelAccountDefault, res: express.Response) {
|
||||
if (!videoChannel) {
|
||||
res.status(404)
|
||||
res.status(HttpStatusCode.NOT_FOUND_404)
|
||||
.json({ error: 'Video channel not found' })
|
||||
.end()
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import * as express from 'express'
|
||||
import { VideoPlaylistModel } from '../../models/video/video-playlist'
|
||||
import { MVideoPlaylist } from '../../types/models/video/video-playlist'
|
||||
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
export type VideoPlaylistFetchType = 'summary' | 'all'
|
||||
async function doesVideoPlaylistExist (id: number | string, res: express.Response, fetchType: VideoPlaylistFetchType = 'summary') {
|
||||
|
@ -27,7 +28,7 @@ export {
|
|||
|
||||
function handleVideoPlaylist (videoPlaylist: MVideoPlaylist, res: express.Response) {
|
||||
if (!videoPlaylist) {
|
||||
res.status(404)
|
||||
res.status(HttpStatusCode.NOT_FOUND_404)
|
||||
.json({ error: 'Video playlist not found' })
|
||||
.end()
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import {
|
|||
MVideoWithRights
|
||||
} from '@server/types/models'
|
||||
import { VideoFileModel } from '@server/models/video/video-file'
|
||||
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') {
|
||||
const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined
|
||||
|
@ -20,7 +21,7 @@ async function doesVideoExist (id: number | string, res: Response, fetchType: Vi
|
|||
const video = await fetchVideo(id, fetchType, userId)
|
||||
|
||||
if (video === null) {
|
||||
res.status(404)
|
||||
res.status(HttpStatusCode.NOT_FOUND_404)
|
||||
.json({ error: 'Video not found' })
|
||||
.end()
|
||||
|
||||
|
@ -54,7 +55,7 @@ async function doesVideoExist (id: number | string, res: Response, fetchType: Vi
|
|||
|
||||
async function doesVideoFileOfVideoExist (id: number, videoIdOrUUID: number | string, res: Response) {
|
||||
if (!await VideoFileModel.doesVideoExistForVideoFile(id, videoIdOrUUID)) {
|
||||
res.status(404)
|
||||
res.status(HttpStatusCode.NOT_FOUND_404)
|
||||
.json({ error: 'VideoFile matching Video not found' })
|
||||
.end()
|
||||
|
||||
|
@ -68,7 +69,7 @@ async function doesVideoChannelOfAccountExist (channelId: number, user: MUserAcc
|
|||
if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) {
|
||||
const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId)
|
||||
if (videoChannel === null) {
|
||||
res.status(400)
|
||||
res.status(HttpStatusCode.BAD_REQUEST_400)
|
||||
.json({ error: 'Unknown video `video channel` on this instance.' })
|
||||
.end()
|
||||
|
||||
|
@ -81,7 +82,7 @@ async function doesVideoChannelOfAccountExist (channelId: number, user: MUserAcc
|
|||
|
||||
const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id)
|
||||
if (videoChannel === null) {
|
||||
res.status(400)
|
||||
res.status(HttpStatusCode.BAD_REQUEST_400)
|
||||
.json({ error: 'Unknown video `video channel` for this account.' })
|
||||
.end()
|
||||
|
||||
|
@ -95,7 +96,7 @@ async function doesVideoChannelOfAccountExist (channelId: number, user: MUserAcc
|
|||
function checkUserCanManageVideo (user: MUser, video: MVideoAccountLight, right: UserRight, res: Response, onlyOwned = true) {
|
||||
// Retrieve the user who did the request
|
||||
if (onlyOwned && video.isOwned() === false) {
|
||||
res.status(403)
|
||||
res.status(HttpStatusCode.FORBIDDEN_403)
|
||||
.json({ error: 'Cannot manage a video of another server.' })
|
||||
.end()
|
||||
return false
|
||||
|
@ -106,7 +107,7 @@ function checkUserCanManageVideo (user: MUser, video: MVideoAccountLight, right:
|
|||
// Or if s/he is the video's account
|
||||
const account = video.VideoChannel.Account
|
||||
if (user.hasRight(right) === false && account.userId !== user.id) {
|
||||
res.status(403)
|
||||
res.status(HttpStatusCode.FORBIDDEN_403)
|
||||
.json({ error: 'Cannot manage a video of another user.' })
|
||||
.end()
|
||||
return false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue