Add ability to search by URL with query params

This commit is contained in:
Chocobozzz
2021-10-20 15:01:17 +02:00
parent ebe9b6b3f3
commit 400043b1be
10 changed files with 109 additions and 33 deletions

View 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()
@@ -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({

View File

@@ -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({

View File

@@ -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({

View File

@@ -0,0 +1 @@
export * from './utils'

View 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()
}