diff --git a/.eslintrc.json b/.eslintrc.json index 0d14c82..57ecfe4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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" diff --git a/server.ts b/server.ts index 34bd6b5..db16c1b 100644 --- a/server.ts +++ b/server.ts @@ -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) }) diff --git a/server/controllers/api/search-channels.ts b/server/controllers/api/search-channels.ts index ddb8a1c..a08314e 100644 --- a/server/controllers/api/search-channels.ts +++ b/server/controllers/api/search-channels.ts @@ -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({ diff --git a/server/controllers/api/search-videos.ts b/server/controllers/api/search-videos.ts index 5280df4..f734bec 100644 --- a/server/controllers/api/search-videos.ts +++ b/server/controllers/api/search-videos.ts @@ -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) diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index 36c1d4c..ad01964 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts @@ -22,9 +22,14 @@ function getFormattedObjects (objects: T[], obje } as ResultList } +function buildUrl (host: string, path: string) { + return 'https://' + host + path +} + // --------------------------------------------------------------------------- export { badRequest, - getFormattedObjects + getFormattedObjects, + buildUrl } diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 9f3571b..633205b 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -52,7 +52,7 @@ const REQUESTS = { } if (isTestInstance()) { - SCHEDULER_INTERVALS_MS.videosIndexer = 30000 + SCHEDULER_INTERVALS_MS.videosIndexer = 1000 * 60 * 5 // 5 minutes } export { diff --git a/server/lib/elastic-search-avatar.ts b/server/lib/elastic-search-avatar.ts index 18d8c97..f157ade 100644 --- a/server/lib/elastic-search-avatar.ts +++ b/server/lib/elastic-search-avatar.ts @@ -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 diff --git a/server/lib/elastic-search-videos.ts b/server/lib/elastic-search-videos.ts index 26ee52a..cb0a9db 100644 --- a/server/lib/elastic-search-videos.ts +++ b/server/lib/elastic-search-videos.ts @@ -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, diff --git a/server/middlewares/validators/pagination.ts b/server/middlewares/validators/pagination.ts index 1621c4c..cc69ea9 100644 --- a/server/middlewares/validators/pagination.ts +++ b/server/middlewares/validators/pagination.ts @@ -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() diff --git a/server/middlewares/validators/search.ts b/server/middlewares/validators/search.ts index 46cc32d..83bfcbe 100644 --- a/server/middlewares/validators/search.ts +++ b/server/middlewares/validators/search.ts @@ -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 diff --git a/server/middlewares/validators/utils.ts b/server/middlewares/validators/utils.ts index c02a7c5..32bbbf5 100644 --- a/server/middlewares/validators/utils.ts +++ b/server/middlewares/validators/utils.ts @@ -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()