} from '../../../middlewares'
import { VideoChannelModel } from '../../../models/video/video-channel'
import { MChannelAccountDefault } from '../../../types/models'
+import { searchLocalUrl } from './shared'
const searchChannelsRouter = express.Router()
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({
videoPlaylistsListSearchValidator,
videoPlaylistsSearchSortValidator
} from '../../../middlewares'
+import { searchLocalUrl } from './shared'
const searchPlaylistsRouter = express.Router()
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({
} from '../../../middlewares'
import { VideoModel } from '../../../models/video/video'
import { MVideoAccountLightBlacklistAllFiles } from '../../../types/models'
+import { searchLocalUrl } from './shared'
const searchVideosRouter = express.Router()
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({
--- /dev/null
+export * from './utils'
--- /dev/null
+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()
+}
return host
}
-function badRequest (req: express.Request, res: express.Response) {
+function badRequest (_req: express.Request, res: express.Response) {
return res.type('json')
.status(HttpStatusCode.BAD_REQUEST_400)
.end()
const { playlistObject } = await fetchRemoteVideoPlaylist(playlistUrl)
if (!playlistObject) throw new Error('Cannot fetch remote playlist with url: ' + playlistUrl)
- // playlistUrl is just an alias/rediraction, so process object id instead
+ // playlistUrl is just an alias/redirection, so process object id instead
if (playlistObject.id !== playlistUrl) return getOrCreateAPVideoPlaylist(playlistObject)
const playlistCreated = await createOrUpdateVideoPlaylist(playlistObject)
this.timeout(15000)
{
- const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server3'
+ const search = servers[1].url + '/video-channels/channel1_server3'
const body = await command.searchChannels({ search, token: servers[0].accessToken })
expect(body.total).to.equal(0)
{
// Without token
- const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
+ const search = servers[1].url + '/video-channels/channel1_server2'
const body = await command.searchChannels({ search })
expect(body.total).to.equal(0)
it('Should search a local video channel', async function () {
const searches = [
- 'http://localhost:' + servers[0].port + '/video-channels/channel1_server1',
+ servers[0].url + '/video-channels/channel1_server1',
'channel1_server1@localhost:' + servers[0].port
]
})
it('Should search a local video channel with an alternative URL', async function () {
- const search = 'http://localhost:' + servers[0].port + '/c/channel1_server1'
+ const search = servers[0].url + '/c/channel1_server1'
for (const token of [ undefined, servers[0].accessToken ]) {
const body = await command.searchChannels({ search, token })
}
})
+ it('Should search a local video channel with a query in URL', async function () {
+ const searches = [
+ servers[0].url + '/video-channels/channel1_server1',
+ servers[0].url + '/c/channel1_server1'
+ ]
+
+ for (const search of searches) {
+ for (const token of [ undefined, servers[0].accessToken ]) {
+ const body = await command.searchChannels({ search: search + '?param=2', token })
+
+ expect(body.total).to.equal(1)
+ expect(body.data).to.be.an('array')
+ expect(body.data).to.have.lengthOf(1)
+ expect(body.data[0].name).to.equal('channel1_server1')
+ expect(body.data[0].displayName).to.equal('Channel 1 server 1')
+ }
+ }
+ })
+
it('Should search a remote video channel with URL or handle', async function () {
const searches = [
- 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2',
- 'http://localhost:' + servers[1].port + '/c/channel1_server2',
- 'http://localhost:' + servers[1].port + '/c/channel1_server2/videos',
+ servers[1].url + '/video-channels/channel1_server2',
+ servers[1].url + '/c/channel1_server2',
+ servers[1].url + '/c/channel1_server2/videos',
'channel1_server2@localhost:' + servers[1].port
]
// Expire video channel
await wait(10000)
- const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
+ const search = servers[1].url + '/video-channels/channel1_server2'
const body = await command.searchChannels({ search, token: servers[0].accessToken })
expect(body.total).to.equal(1)
expect(body.data).to.have.lengthOf(1)
// Expire video channel
await wait(10000)
- const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
+ const search = servers[1].url + '/video-channels/channel1_server2'
await command.searchChannels({ search, token: servers[0].accessToken })
await waitJobs(servers)
// Expire video
await wait(10000)
- const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
+ const search = servers[1].url + '/video-channels/channel1_server2'
const body = await command.searchChannels({ search, token: servers[0].accessToken })
expect(body.total).to.equal(0)
expect(body.data).to.have.lengthOf(0)
it('Should not find a remote playlist', async function () {
{
- const search = 'http://localhost:' + servers[1].port + '/video-playlists/43'
+ const search = servers[1].url + '/video-playlists/43'
const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
expect(body.total).to.equal(0)
{
// Without token
- const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID
+ const search = servers[1].url + '/video-playlists/' + playlistServer2UUID
const body = await command.searchPlaylists({ search })
expect(body.total).to.equal(0)
})
it('Should search a local playlist', async function () {
- const search = 'http://localhost:' + servers[0].port + '/video-playlists/' + playlistServer1UUID
+ const search = servers[0].url + '/video-playlists/' + playlistServer1UUID
const body = await command.searchPlaylists({ search })
expect(body.total).to.equal(1)
it('Should search a local playlist with an alternative URL', async function () {
const searches = [
- 'http://localhost:' + servers[0].port + '/videos/watch/playlist/' + playlistServer1UUID,
- 'http://localhost:' + servers[0].port + '/w/p/' + playlistServer1UUID
+ servers[0].url + '/videos/watch/playlist/' + playlistServer1UUID,
+ servers[0].url + '/w/p/' + playlistServer1UUID
]
for (const search of searches) {
}
})
+ it('Should search a local playlist with a query in URL', async function () {
+ const searches = [
+ servers[0].url + '/videos/watch/playlist/' + playlistServer1UUID,
+ servers[0].url + '/w/p/' + playlistServer1UUID
+ ]
+
+ for (const search of searches) {
+ for (const token of [ undefined, servers[0].accessToken ]) {
+ const body = await command.searchPlaylists({ search: search + '?param=1', token })
+
+ expect(body.total).to.equal(1)
+ expect(body.data).to.be.an('array')
+ expect(body.data).to.have.lengthOf(1)
+ expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
+ expect(body.data[0].videosLength).to.equal(2)
+ }
+ }
+ })
+
it('Should search a remote playlist', async function () {
const searches = [
- 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID,
- 'http://localhost:' + servers[1].port + '/videos/watch/playlist/' + playlistServer2UUID,
- 'http://localhost:' + servers[1].port + '/w/p/' + playlistServer2UUID
+ servers[1].url + '/video-playlists/' + playlistServer2UUID,
+ servers[1].url + '/videos/watch/playlist/' + playlistServer2UUID,
+ servers[1].url + '/w/p/' + playlistServer2UUID
]
for (const search of searches) {
await wait(10000)
// Will run refresh async
- const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID
+ const search = servers[1].url + '/video-playlists/' + playlistServer2UUID
await command.searchPlaylists({ search, token: servers[0].accessToken })
// Wait refresh
await wait(10000)
// Will run refresh async
- const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID
+ const search = servers[1].url + '/video-playlists/' + playlistServer2UUID
await command.searchPlaylists({ search, token: servers[0].accessToken })
// Wait refresh
it('Should not find a remote video', async function () {
{
- const search = 'http://localhost:' + servers[1].port + '/videos/watch/43'
+ const search = servers[1].url + '/videos/watch/43'
const body = await command.searchVideos({ search, token: servers[0].accessToken })
expect(body.total).to.equal(0)
{
// Without token
- const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
+ const search = servers[1].url + '/videos/watch/' + videoServer2UUID
const body = await command.searchVideos({ search })
expect(body.total).to.equal(0)
})
it('Should search a local video', async function () {
- const search = 'http://localhost:' + servers[0].port + '/videos/watch/' + videoServer1UUID
+ const search = servers[0].url + '/videos/watch/' + videoServer1UUID
const body = await command.searchVideos({ search })
expect(body.total).to.equal(1)
})
it('Should search a local video with an alternative URL', async function () {
- const search = 'http://localhost:' + servers[0].port + '/w/' + videoServer1UUID
+ const search = servers[0].url + '/w/' + videoServer1UUID
const body1 = await command.searchVideos({ search })
const body2 = await command.searchVideos({ search, token: servers[0].accessToken })
}
})
+ it('Should search a local video with a query in URL', async function () {
+ const searches = [
+ servers[0].url + '/w/' + videoServer1UUID,
+ servers[0].url + '/videos/watch/' + videoServer1UUID
+ ]
+
+ for (const search of searches) {
+ for (const token of [ undefined, servers[0].accessToken ]) {
+ const body = await command.searchVideos({ search: search + '?startTime=4', token })
+
+ expect(body.total).to.equal(1)
+ expect(body.data).to.be.an('array')
+ expect(body.data).to.have.lengthOf(1)
+ expect(body.data[0].name).to.equal('video 1 on server 1')
+ }
+ }
+ })
+
it('Should search a remote video', async function () {
const searches = [
- 'http://localhost:' + servers[1].port + '/w/' + videoServer2UUID,
- 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
+ servers[1].url + '/w/' + videoServer2UUID,
+ servers[1].url + '/videos/watch/' + videoServer2UUID
]
for (const search of searches) {
await wait(10000)
// Will run refresh async
- const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
+ const search = servers[1].url + '/videos/watch/' + videoServer2UUID
await command.searchVideos({ search, token: servers[0].accessToken })
// Wait refresh
await wait(10000)
// Will run refresh async
- const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
+ const search = servers[1].url + '/videos/watch/' + videoServer2UUID
await command.searchVideos({ search, token: servers[0].accessToken })
// Wait refresh