diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/search.ts | 38 |
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' |
15 | import { VideosSearchQuery } from '../../../shared/models/search' | 15 | import { VideosSearchQuery } from '../../../shared/models/search' |
16 | import { getOrCreateAccountAndVideoAndChannel } from '../../lib/activitypub' | 16 | import { getOrCreateVideoAndAccountAndChannel } from '../../lib/activitypub' |
17 | import { logger } from '../../helpers/logger' | 17 | import { logger } from '../../helpers/logger' |
18 | import { User } from '../../../shared/models/users' | ||
19 | import { CONFIG } from '../../initializers/constants' | ||
18 | 20 | ||
19 | const searchRouter = express.Router() | 21 | const searchRouter = express.Router() |
20 | 22 | ||
@@ -56,20 +58,30 @@ async function searchVideosDB (query: VideosSearchQuery, res: express.Response) | |||
56 | 58 | ||
57 | async function searchVideoUrl (url: string, res: express.Response) { | 59 | async 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({ |