import { immutableAssign } from '@app/helpers'
import { Video, VideoChannel } from '@app/shared/shared-main'
import { AdvancedSearch, SearchService } from '@app/shared/shared-search'
-import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature'
+import { MiniatureDisplayOptions, VideoLinkType } from '@app/shared/shared-video-miniature'
import { MetaService } from '@ngx-meta/core'
-import { I18n } from '@ngx-translate/i18n-polyfill'
import { SearchTargetType, ServerConfig } from '@shared/models'
@Component({
private lastSearchTarget: SearchTargetType
constructor (
- private i18n: I18n,
private route: ActivatedRoute,
private router: Router,
private metaService: MetaService,
return this.authService.isLoggedIn()
}
+ getVideoLinkType (): VideoLinkType {
+ if (this.advancedSearch.searchTarget === 'search-index') {
+ const remoteUriConfig = this.serverConfig.search.remoteUri
+
+ // Redirect on the external instance if not allowed to fetch remote data
+ if ((!this.isUserLoggedIn() && !remoteUriConfig.anonymous) || !remoteUriConfig.users) {
+ return 'external'
+ }
+
+ return 'lazy-load'
+ }
+
+ return 'internal'
+ }
+
+ isExternalChannelUrl () {
+ return this.getVideoLinkType() === 'external'
+ }
+
search () {
forkJoin([
this.getVideosObs(),
}
this.notifier.error(
- this.i18n('Search index is unavailable. Retrying with instance results instead.'),
- this.i18n('Search error')
+ $localize`Search index is unavailable. Retrying with instance results instead.`,
+ $localize`Search error`
)
this.advancedSearch.searchTarget = 'local'
this.search()
}
getChannelUrl (channel: VideoChannel) {
- if (this.advancedSearch.searchTarget === 'search-index' && channel.url) {
- const remoteUriConfig = this.serverConfig.search.remoteUri
-
- // Redirect on the external instance if not allowed to fetch remote data
- const externalRedirect = (!this.authService.isLoggedIn() && !remoteUriConfig.anonymous) || !remoteUriConfig.users
- const fromPath = window.location.pathname + window.location.search
+ // Same algorithm than videos
+ if (this.getVideoLinkType() === 'external') {
+ return channel.url
+ }
- return [ '/search/lazy-load-channel', { url: channel.url, externalRedirect, fromPath } ]
+ if (this.getVideoLinkType() === 'internal') {
+ return [ '/video-channels', channel.nameWithHost ]
}
- return [ '/video-channels', channel.nameWithHost ]
+ return [ '/search/lazy-load-channel', { url: channel.url } ]
}
hideActions () {
private updateTitle () {
const suffix = this.currentSearch ? ' ' + this.currentSearch : ''
- this.metaService.setTitle(this.i18n('Search') + suffix)
+ this.metaService.setTitle($localize`Search` + suffix)
}
private updateUrlFromAdvancedSearch () {