aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/search/search-videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/search/search-videos.ts')
-rw-r--r--server/controllers/api/search/search-videos.ts27
1 files changed, 16 insertions, 11 deletions
diff --git a/server/controllers/api/search/search-videos.ts b/server/controllers/api/search/search-videos.ts
index b626baa28..4a6ce0de4 100644
--- a/server/controllers/api/search/search-videos.ts
+++ b/server/controllers/api/search/search-videos.ts
@@ -1,14 +1,14 @@
1import * as express from 'express' 1import * as express from 'express'
2import { sanitizeUrl } from '@server/helpers/core-utils' 2import { sanitizeUrl } from '@server/helpers/core-utils'
3import { pickSearchVideoQuery } from '@server/helpers/query'
3import { doJSONRequest } from '@server/helpers/requests' 4import { doJSONRequest } from '@server/helpers/requests'
4import { CONFIG } from '@server/initializers/config' 5import { CONFIG } from '@server/initializers/config'
5import { WEBSERVER } from '@server/initializers/constants' 6import { WEBSERVER } from '@server/initializers/constants'
6import { getOrCreateAPVideo } from '@server/lib/activitypub/videos' 7import { getOrCreateAPVideo } from '@server/lib/activitypub/videos'
7import { Hooks } from '@server/lib/plugins/hooks' 8import { Hooks } from '@server/lib/plugins/hooks'
8import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@server/lib/search' 9import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@server/lib/search'
9import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' 10import { HttpStatusCode, ResultList, Video } from '@shared/models'
10import { ResultList, Video } from '@shared/models' 11import { VideosSearchQueryAfterSanitize } from '../../../../shared/models/search'
11import { VideosSearchQuery } from '../../../../shared/models/search'
12import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils' 12import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils'
13import { logger } from '../../../helpers/logger' 13import { logger } from '../../../helpers/logger'
14import { getFormattedObjects } from '../../../helpers/utils' 14import { getFormattedObjects } from '../../../helpers/utils'
@@ -47,7 +47,7 @@ export { searchVideosRouter }
47// --------------------------------------------------------------------------- 47// ---------------------------------------------------------------------------
48 48
49function searchVideos (req: express.Request, res: express.Response) { 49function searchVideos (req: express.Request, res: express.Response) {
50 const query: VideosSearchQuery = req.query 50 const query = pickSearchVideoQuery(req.query)
51 const search = query.search 51 const search = query.search
52 52
53 if (isURISearch(search)) { 53 if (isURISearch(search)) {
@@ -61,10 +61,10 @@ function searchVideos (req: express.Request, res: express.Response) {
61 return searchVideosDB(query, res) 61 return searchVideosDB(query, res)
62} 62}
63 63
64async function searchVideosIndex (query: VideosSearchQuery, res: express.Response) { 64async function searchVideosIndex (query: VideosSearchQueryAfterSanitize, res: express.Response) {
65 const result = await buildMutedForSearchIndex(res) 65 const result = await buildMutedForSearchIndex(res)
66 66
67 let body: VideosSearchQuery = Object.assign(query, result) 67 let body = { ...query, ...result }
68 68
69 // Use the default instance NSFW policy if not specified 69 // Use the default instance NSFW policy if not specified
70 if (!body.nsfw) { 70 if (!body.nsfw) {
@@ -98,13 +98,18 @@ async function searchVideosIndex (query: VideosSearchQuery, res: express.Respons
98 } 98 }
99} 99}
100 100
101async function searchVideosDB (query: VideosSearchQuery, res: express.Response) { 101async function searchVideosDB (query: VideosSearchQueryAfterSanitize, res: express.Response) {
102 const apiOptions = await Hooks.wrapObject(Object.assign(query, { 102 const apiOptions = await Hooks.wrapObject({
103 ...query,
104
103 includeLocalVideos: true, 105 includeLocalVideos: true,
104 nsfw: buildNSFWFilter(res, query.nsfw),
105 filter: query.filter, 106 filter: query.filter,
106 user: res.locals.oauth ? res.locals.oauth.token.User : undefined 107
107 }), 'filter:api.search.videos.local.list.params') 108 nsfw: buildNSFWFilter(res, query.nsfw),
109 user: res.locals.oauth
110 ? res.locals.oauth.token.User
111 : undefined
112 }, 'filter:api.search.videos.local.list.params')
108 113
109 const resultList = await Hooks.wrapPromiseFun( 114 const resultList = await Hooks.wrapPromiseFun(
110 VideoModel.searchAndPopulateAccountAndServer, 115 VideoModel.searchAndPopulateAccountAndServer,