pull/6288/head
Chocobozzz 2024-03-26 17:07:32 +01:00
parent 2ff7dee3f1
commit 705c60ce92
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 14 additions and 14 deletions

View File

@ -1,11 +1,11 @@
import { HttpStatusCode } from '@peertube/peertube-models'
import { logger } from '@server/helpers/logger.js'
import express from 'express' import express from 'express'
import { ProblemDocument, ProblemDocumentExtension } from 'http-problem-details' import { ProblemDocument, ProblemDocumentExtension } from 'http-problem-details'
import { logger } from '@server/helpers/logger.js'
import { HttpStatusCode } from '@peertube/peertube-models'
function apiFailMiddleware (req: express.Request, res: express.Response, next: express.NextFunction) { function apiFailMiddleware (req: express.Request, res: express.Response, next: express.NextFunction) {
res.fail = options => { res.fail = options => {
const { status = HttpStatusCode.BAD_REQUEST_400, message, title, type, data, instance, tags } = options const { status = HttpStatusCode.BAD_REQUEST_400, message, title, type, data, instance, tags, logLevel = 'debug' } = options
const extension = new ProblemDocumentExtension({ const extension = new ProblemDocumentExtension({
...data, ...data,
@ -29,7 +29,7 @@ function apiFailMiddleware (req: express.Request, res: express.Response, next: e
: undefined : undefined
}, extension) }, extension)
logger.debug('Bad HTTP request.', { json, tags }) logger.log(logLevel, 'Bad HTTP request.', { json, tags })
res.status(status) res.status(status)

View File

@ -1,12 +1,11 @@
import express from 'express'
import { body, param } from 'express-validator'
import { HttpStatusCode } from '@peertube/peertube-models' import { HttpStatusCode } from '@peertube/peertube-models'
import { isVideoTimeValid } from '@server/helpers/custom-validators/video-view.js' import { isVideoTimeValid } from '@server/helpers/custom-validators/video-view.js'
import { getCachedVideoDuration } from '@server/lib/video.js' import { getCachedVideoDuration } from '@server/lib/video.js'
import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer.js' import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer.js'
import express from 'express'
import { body, param } from 'express-validator'
import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc.js' import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc.js'
import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared/index.js' import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared/index.js'
import { logger } from '@server/helpers/logger.js'
const getVideoLocalViewerValidator = [ const getVideoLocalViewerValidator = [
param('localViewerId') param('localViewerId')
@ -43,12 +42,12 @@ const videoViewValidator = [
const video = res.locals.onlyImmutableVideo const video = res.locals.onlyImmutableVideo
const { duration } = await getCachedVideoDuration(video.id) const { duration } = await getCachedVideoDuration(video.id)
if (!isVideoTimeValid(req.body.currentTime, duration)) { const currentTime = req.body.currentTime
logger.warn('Current time is invalid', { duration, currentTime: req.body.currentTime, videoId: video.id }) if (!isVideoTimeValid(currentTime, duration)) {
return res.fail({ return res.fail({
status: HttpStatusCode.BAD_REQUEST_400, status: HttpStatusCode.BAD_REQUEST_400,
message: 'Current time is invalid' message: `Current time ${currentTime} is invalid (video ${video.uuid} duration: ${duration})`,
logLevel: 'warn'
}) })
} }
@ -59,6 +58,6 @@ const videoViewValidator = [
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
export { export {
videoViewValidator, getVideoLocalViewerValidator, videoViewValidator
getVideoLocalViewerValidator
} }

View File

@ -1,4 +1,4 @@
import { HttpMethodType, PeerTubeProblemDocumentData, VideoCreate } from '@peertube/peertube-models' import { HttpMethodType, PeerTubeProblemDocumentData, ServerLogLevel, VideoCreate } from '@peertube/peertube-models'
import { RegisterServerAuthExternalOptions } from '@server/types/index.js' import { RegisterServerAuthExternalOptions } from '@server/types/index.js'
import { import {
MAbuseMessage, MAbuseMessage,
@ -109,6 +109,7 @@ declare module 'express' {
data?: PeerTubeProblemDocumentData data?: PeerTubeProblemDocumentData
logLevel?: ServerLogLevel // Default debug
tags?: string[] tags?: string[]
}) => void }) => void