mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Add ability to search by URL with query params
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
videoPlaylistsListSearchValidator,
|
||||
videoPlaylistsSearchSortValidator
|
||||
} from '../../../middlewares'
|
||||
import { searchLocalUrl } from './shared'
|
||||
|
||||
const searchPlaylistsRouter = express.Router()
|
||||
|
||||
@@ -109,7 +110,7 @@ async function searchVideoPlaylistsURI (search: string, res: express.Response) {
|
||||
logger.info('Cannot search remote video playlist %s.', search, { err })
|
||||
}
|
||||
} else {
|
||||
videoPlaylist = await VideoPlaylistModel.loadByUrlWithAccountAndChannelSummary(sanitizeLocalUrl(search))
|
||||
videoPlaylist = await searchLocalUrl(sanitizeLocalUrl(search), url => VideoPlaylistModel.loadByUrlWithAccountAndChannelSummary(url))
|
||||
}
|
||||
|
||||
return res.json({
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
} from '../../../middlewares'
|
||||
import { VideoModel } from '../../../models/video/video'
|
||||
import { MVideoAccountLightBlacklistAllFiles } from '../../../types/models'
|
||||
import { searchLocalUrl } from './shared'
|
||||
|
||||
const searchVideosRouter = express.Router()
|
||||
|
||||
@@ -141,7 +142,7 @@ async function searchVideoURI (url: string, res: express.Response) {
|
||||
logger.info('Cannot search remote video %s.', url, { err })
|
||||
}
|
||||
} else {
|
||||
video = await VideoModel.loadByUrlAndPopulateAccount(sanitizeLocalUrl(url))
|
||||
video = await searchLocalUrl(sanitizeLocalUrl(url), url => VideoModel.loadByUrlAndPopulateAccount(url))
|
||||
}
|
||||
|
||||
return res.json({
|
||||
|
||||
1
server/controllers/api/search/shared/index.ts
Normal file
1
server/controllers/api/search/shared/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './utils'
|
||||
16
server/controllers/api/search/shared/utils.ts
Normal file
16
server/controllers/api/search/shared/utils.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
async function searchLocalUrl <T> (url: string, finder: (url: string) => Promise<T>) {
|
||||
const data = await finder(url)
|
||||
if (data) return data
|
||||
|
||||
return finder(removeQueryParams(url))
|
||||
}
|
||||
|
||||
export {
|
||||
searchLocalUrl
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function removeQueryParams (url: string) {
|
||||
return url.split('?').shift()
|
||||
}
|
||||
Reference in New Issue
Block a user