aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-22 11:51:39 +0200
committerChocobozzz <me@florianbigard.com>2018-08-27 09:41:54 +0200
commitf6eebcb336c067e160a62020a5140d8d992ba384 (patch)
tree48fbf9c292243c9cc13beb3749eceaf61fe2baef /server/controllers
parent22a16e36f6526887ed8f5e5d3c9f9e5da0b4a8cd (diff)
downloadPeerTube-f6eebcb336c067e160a62020a5140d8d992ba384.tar.gz
PeerTube-f6eebcb336c067e160a62020a5140d8d992ba384.tar.zst
PeerTube-f6eebcb336c067e160a62020a5140d8d992ba384.zip
Add ability to search a video with an URL
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}