aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/search.ts35
1 files changed, 34 insertions, 1 deletions
diff --git a/server/controllers/api/search.ts b/server/controllers/api/search.ts
index 7a7504b7d..9c2c7d6c1 100644
--- a/server/controllers/api/search.ts
+++ b/server/controllers/api/search.ts
@@ -13,6 +13,8 @@ import {
13 videosSearchSortValidator 13 videosSearchSortValidator
14} from '../../middlewares' 14} from '../../middlewares'
15import { VideosSearchQuery } from '../../../shared/models/search' 15import { VideosSearchQuery } from '../../../shared/models/search'
16import { getOrCreateAccountAndVideoAndChannel } from '../../lib/activitypub'
17import { logger } from '../../helpers/logger'
16 18
17const searchRouter = express.Router() 19const searchRouter = express.Router()
18 20
@@ -33,9 +35,16 @@ export { searchRouter }
33 35
34// --------------------------------------------------------------------------- 36// ---------------------------------------------------------------------------
35 37
36async function searchVideos (req: express.Request, res: express.Response) { 38function searchVideos (req: express.Request, res: express.Response) {
37 const query: VideosSearchQuery = req.query 39 const query: VideosSearchQuery = req.query
40 if (query.search.startsWith('http://') || query.search.startsWith('https://')) {
41 return searchVideoUrl(query.search, res)
42 }
38 43
44 return searchVideosDB(query, res)
45}
46
47async function searchVideosDB (query: VideosSearchQuery, res: express.Response) {
39 const options = Object.assign(query, { 48 const options = Object.assign(query, {
40 includeLocalVideos: true, 49 includeLocalVideos: true,
41 nsfw: buildNSFWFilter(res, query.nsfw) 50 nsfw: buildNSFWFilter(res, query.nsfw)
@@ -44,3 +53,27 @@ async function searchVideos (req: express.Request, res: express.Response) {
44 53
45 return res.json(getFormattedObjects(resultList.data, resultList.total)) 54 return res.json(getFormattedObjects(resultList.data, resultList.total))
46} 55}
56
57async function searchVideoUrl (url: string, res: express.Response) {
58 let video: VideoModel
59
60 try {
61 const syncParam = {
62 likes: false,
63 dislikes: false,
64 shares: false,
65 comments: false,
66 thumbnail: true
67 }
68
69 const res = await getOrCreateAccountAndVideoAndChannel(url, syncParam)
70 video = res ? res.video : undefined
71 } catch (err) {
72 logger.info('Cannot search remote video %s.', url)
73 }
74
75 return res.json({
76 total: video ? 1 : 0,
77 data: video ? [ video.toFormattedJSON() ] : []
78 })
79}