aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/search.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/search.ts')
-rw-r--r--server/controllers/api/search.ts38
1 files changed, 25 insertions, 13 deletions
diff --git a/server/controllers/api/search.ts b/server/controllers/api/search.ts
index 9c2c7d6c1..d95e7cac9 100644
--- a/server/controllers/api/search.ts
+++ b/server/controllers/api/search.ts
@@ -13,8 +13,10 @@ 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' 16import { getOrCreateVideoAndAccountAndChannel } from '../../lib/activitypub'
17import { logger } from '../../helpers/logger' 17import { logger } from '../../helpers/logger'
18import { User } from '../../../shared/models/users'
19import { CONFIG } from '../../initializers/constants'
18 20
19const searchRouter = express.Router() 21const searchRouter = express.Router()
20 22
@@ -56,20 +58,30 @@ async function searchVideosDB (query: VideosSearchQuery, res: express.Response)
56 58
57async function searchVideoUrl (url: string, res: express.Response) { 59async function searchVideoUrl (url: string, res: express.Response) {
58 let video: VideoModel 60 let video: VideoModel
61 const user: User = res.locals.oauth ? res.locals.oauth.token.User : undefined
59 62
60 try { 63 // Check if we can fetch a remote video with the URL
61 const syncParam = { 64 if (
62 likes: false, 65 CONFIG.SEARCH.REMOTE_URI.ANONYMOUS === true ||
63 dislikes: false, 66 (CONFIG.SEARCH.REMOTE_URI.USERS === true && user !== undefined)
64 shares: false, 67 ) {
65 comments: false, 68 try {
66 thumbnail: true 69 const syncParam = {
67 } 70 likes: false,
71 dislikes: false,
72 shares: false,
73 comments: false,
74 thumbnail: true,
75 refreshVideo: false
76 }
68 77
69 const res = await getOrCreateAccountAndVideoAndChannel(url, syncParam) 78 const res = await getOrCreateVideoAndAccountAndChannel(url, syncParam)
70 video = res ? res.video : undefined 79 video = res ? res.video : undefined
71 } catch (err) { 80 } catch (err) {
72 logger.info('Cannot search remote video %s.', url) 81 logger.info('Cannot search remote video %s.', url)
82 }
83 } else {
84 video = await VideoModel.loadByUrlAndPopulateAccount(url)
73 } 85 }
74 86
75 return res.json({ 87 return res.json({