]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/search/search-video-channels.ts
Add ability to search by URL with query params
[github/Chocobozzz/PeerTube.git] / server / controllers / api / search / search-video-channels.ts
index 25173ac20b79683e656db3ca03d00fb347cfe6ce..c9e81bffad6d12eae553db5685ef48753d26f0e9 100644 (file)
@@ -25,6 +25,7 @@ import {
 } from '../../../middlewares'
 import { VideoChannelModel } from '../../../models/video/video-channel'
 import { MChannelAccountDefault } from '../../../types/models'
+import { searchLocalUrl } from './shared'
 
 const searchChannelsRouter = express.Router()
 
@@ -47,7 +48,7 @@ export { searchChannelsRouter }
 
 function searchVideoChannels (req: express.Request, res: express.Response) {
   const query = pickSearchChannelQuery(req.query)
-  let search = query.search || ''
+  const search = query.search || ''
 
   const parts = search.split('@')
 
@@ -58,7 +59,7 @@ function searchVideoChannels (req: express.Request, res: express.Response) {
   if (isURISearch(search) || isWebfingerSearch) return searchVideoChannelURI(search, isWebfingerSearch, res)
 
   // @username -> username to search in DB
-  if (search.startsWith('@')) search = search.replace(/^@/, '')
+  if (search.startsWith('@')) query.search = search.replace(/^@/, '')
 
   if (isSearchIndexSearch(query)) {
     return searchVideoChannelsIndex(query, res)
@@ -131,7 +132,7 @@ async function searchVideoChannelURI (search: string, isWebfingerSearch: boolean
       logger.info('Cannot search remote video channel %s.', uri, { err })
     }
   } else {
-    videoChannel = await VideoChannelModel.loadByUrlAndPopulateAccount(sanitizeLocalUrl(uri))
+    videoChannel = await searchLocalUrl(sanitizeLocalUrl(uri), url => VideoChannelModel.loadByUrlAndPopulateAccount(url))
   }
 
   return res.json({