Fix body payload

This commit is contained in:
Chocobozzz 2020-05-29 16:16:55 +02:00
parent 9e734f891a
commit fdbf6ede5f
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
11 changed files with 45 additions and 27 deletions

View File

@ -63,16 +63,27 @@
"allowNumber": "true"
}
],
"@typescript-eslint/no-this-alias": [
"error",
{
"allowDestructuring": true, // Allow `const { props, state } = this`; false by default
"allowedNames": ["self"] // Allow `const self = this`; `[]` by default
}
],
"@typescript-eslint/return-await": "off",
"@typescript-eslint/no-base-to-string": "off",
"@typescript-eslint/quotes": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/promise-function-async": "off",
"@typescript-eslint/no-dynamic-delete": "off",
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "off",
"@typescript-eslint/strict-boolean-expressions": "off",
"@typescript-eslint/consistent-type-definitions": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-extraneous-class": "off",
// bugged but useful
"@typescript-eslint/restrict-plus-operands": "off"

View File

@ -23,7 +23,7 @@ app.use(morgan('combined', {
app.use(bodyParser.json({
type: [ 'application/json', 'application/*+json' ],
limit: '500kb'
limit: '5mb'
}))
app.use(bodyParser.urlencoded({ extended: false }))
@ -38,8 +38,8 @@ app.use(apiRoute, apiRouter)
// Catch 404 and forward to error handler
app.use(function (req, res, next) {
const err = new Error('Not Found')
err['status'] = 404
const err = new Error('Not Found') as any
err.status = 404
next(err)
})

View File

@ -27,7 +27,7 @@ export { searchChannelsRouter }
// ---------------------------------------------------------------------------
async function searchChannels (req: express.Request, res: express.Response) {
const query = (req.query || req.body) as ChannelsSearchQuery
const query = Object.assign(req.query || {}, req.body || {}) as ChannelsSearchQuery
const resultList = await queryChannels(query)
return res.json({

View File

@ -28,7 +28,7 @@ export { searchVideosRouter }
// ---------------------------------------------------------------------------
async function searchVideos (req: express.Request, res: express.Response) {
const query = (req.query || req.body) as VideosSearchQuery
const query = Object.assign(req.query || {}, req.body || {}) as VideosSearchQuery
const resultList = await queryVideos(query)

View File

@ -22,9 +22,14 @@ function getFormattedObjects<U, T extends FormattableToJSON> (objects: T[], obje
} as ResultList<U>
}
function buildUrl (host: string, path: string) {
return 'https://' + host + path
}
// ---------------------------------------------------------------------------
export {
badRequest,
getFormattedObjects
getFormattedObjects,
buildUrl
}

View File

@ -52,7 +52,7 @@ const REQUESTS = {
}
if (isTestInstance()) {
SCHEDULER_INTERVALS_MS.videosIndexer = 30000
SCHEDULER_INTERVALS_MS.videosIndexer = 1000 * 60 * 5 // 5 minutes
}
export {

View File

@ -1,4 +1,5 @@
import { Avatar } from '@shared/models'
import { buildUrl } from '../helpers/utils'
function formatAvatarForAPI (obj: { avatar?: Avatar }) {
if (!obj.avatar) return null
@ -10,10 +11,11 @@ function formatAvatarForAPI (obj: { avatar?: Avatar }) {
}
}
function formatAvatarForDB (obj: { avatar?: Avatar }) {
function formatAvatarForDB (obj: { avatar?: Avatar, host: string }) {
if (!obj.avatar) return null
return {
url: buildUrl(obj.host, obj.avatar.path),
path: obj.avatar.path,
createdAt: obj.avatar.createdAt,
updatedAt: obj.avatar.updatedAt

View File

@ -1,11 +1,11 @@
import { CONFIG } from '../initializers/constants'
import { DBVideo, DBVideoDetails, IndexableVideo, IndexableVideoDetails } from '../types/video.model'
import { Video } from '@shared/models'
import { buildIndex, buildSort, elasticSearch, extractQueryResult, indexDocuments } from '../helpers/elastic-search'
import { VideosSearchQuery } from '../types/video-search.model'
import { logger } from '../helpers/logger'
import { buildAvatarMapping, formatAvatarForAPI, formatAvatarForDB } from './elastic-search-avatar'
import { difference } from 'lodash'
import { buildUrl } from '../helpers/utils'
import { buildIndex, buildSort, elasticSearch, extractQueryResult, indexDocuments } from '../helpers/elastic-search'
import { logger } from '../helpers/logger'
import { CONFIG } from '../initializers/constants'
import { VideosSearchQuery } from '../types/video-search.model'
import { DBVideo, DBVideoDetails, IndexableVideo, IndexableVideoDetails } from '../types/video.model'
import { buildAvatarMapping, formatAvatarForAPI, formatAvatarForDB } from './elastic-search-avatar'
function initVideosIndex () {
return buildIndex(CONFIG.ELASTIC_SEARCH.INDEXES.VIDEOS, buildVideosMapping())
@ -354,7 +354,7 @@ function formatVideoForDB (v: IndexableVideo | IndexableVideoDetails): DBVideo |
}
}
function formatVideoForAPI (v: DBVideo, fromHost?: string): Video {
function formatVideoForAPI (v: DBVideo, fromHost?: string): any {
return {
id: v.id,
uuid: v.uuid,
@ -384,9 +384,16 @@ function formatVideoForAPI (v: DBVideo, fromHost?: string): Video {
name: v.name,
description: v.description,
duration: v.duration,
thumbnailPath: v.thumbnailPath,
thumbnailUrl: buildUrl(v.host, v.thumbnailPath),
previewPath: v.previewPath,
previewUrl: buildUrl(v.host, v.previewPath),
embedPath: v.embedPath,
embedUrl: buildUrl(v.host, v.embedPath),
isLocal: fromHost && fromHost === v.host,
views: v.views,

View File

@ -1,6 +1,5 @@
import * as express from 'express'
import { check } from 'express-validator'
import { logger } from '../../helpers/logger'
import { areValidationErrors } from './utils'
const paginationValidator = [
@ -8,8 +7,6 @@ const paginationValidator = [
check('count').optional().isInt({ min: 0 }).withMessage('Should have a number count'),
(req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug({ parameters: req.query }, 'Checking pagination parameters')
if (areValidationErrors(req, res)) return
return next()

View File

@ -16,7 +16,7 @@ const commonFiltersValidators = [
.custom(isStringArray).withMessage('Should have a valid hosts array'),
(req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug({ parameters: req.query }, 'Checking commons filters query')
logger.debug({ query: req.query, body: req.body }, 'Checking commons filters query')
if (areValidationErrors(req, res)) return
@ -50,8 +50,6 @@ const commonVideosFiltersValidator = [
.custom(isNSFWQueryValid).withMessage('Should have a valid NSFW attribute'),
(req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug({ parameters: req.query }, 'Checking commons video filters query')
if (areValidationErrors(req, res)) return
return next()
@ -71,7 +69,7 @@ const videosSearchValidator = [
check('durationMax').optional().isInt().withMessage('Should have a valid max duration'),
(req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug({ parameters: req.query }, 'Checking videos search query')
logger.debug({ query: req.query, body: req.body }, 'Checking videos search query')
if (areValidationErrors(req, res)) return
@ -83,7 +81,7 @@ const videoChannelsSearchValidator = [
check('search').not().isEmpty().withMessage('Should have a valid search'),
(req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug({ parameters: req.query }, 'Checking video channels search query')
logger.debug({ query: req.query, body: req.body }, 'Checking video channels search query')
if (areValidationErrors(req, res)) return

View File

@ -20,8 +20,6 @@ function checkSort (sortableColumns: string[]) {
check('sort').optional().isIn(sortableColumns).withMessage('Should have correct sortable column'),
(req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug({ parameters: req.query }, 'Checking sort parameters')
if (areValidationErrors(req, res)) return
return next()