diff --git a/client/src/app/+search/channel-lazy-load.resolver.ts b/client/src/app/+search/channel-lazy-load.resolver.ts index 17a212829..d9f7ec901 100644 --- a/client/src/app/+search/channel-lazy-load.resolver.ts +++ b/client/src/app/+search/channel-lazy-load.resolver.ts @@ -12,20 +12,12 @@ export class ChannelLazyLoadResolver implements Resolve { resolve (route: ActivatedRouteSnapshot) { const url = route.params.url - const externalRedirect = route.params.externalRedirect - const fromPath = route.params.fromPath if (!url) { console.error('Could not find url param.', { params: route.params }) return this.router.navigateByUrl('/404') } - if (externalRedirect === 'true') { - window.open(url) - this.router.navigateByUrl(fromPath) - return - } - return this.searchService.searchVideoChannels({ search: url }) .pipe( map(result => { diff --git a/client/src/app/+search/search.component.html b/client/src/app/+search/search.component.html index 9bff024ad..84be4fb14 100644 --- a/client/src/app/+search/search.component.html +++ b/client/src/app/+search/search.component.html @@ -35,15 +35,27 @@
- + + Avatar + + + Avatar
- + + + + + + + + +
{{ result.displayName }}
{{ result.nameWithHost }}
- +
{{ result.followersCount }} subscribers
@@ -54,7 +66,7 @@
diff --git a/client/src/app/+search/search.component.ts b/client/src/app/+search/search.component.ts index 1ed54937b..70116fab3 100644 --- a/client/src/app/+search/search.component.ts +++ b/client/src/app/+search/search.component.ts @@ -5,7 +5,7 @@ import { AuthService, ComponentPagination, HooksService, Notifier, ServerService 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' @@ -119,6 +119,25 @@ export class SearchComponent implements OnInit, OnDestroy { 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(), @@ -184,17 +203,16 @@ export class SearchComponent implements OnInit, OnDestroy { } 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 - - return [ '/search/lazy-load-channel', { url: channel.url, externalRedirect, fromPath } ] + // Same algorithm than videos + if (this.getVideoLinkType() === 'external') { + return channel.url } - return [ '/video-channels', channel.nameWithHost ] + if (this.getVideoLinkType() === 'internal') { + return [ '/video-channels', channel.nameWithHost ] + } + + return [ '/search/lazy-load-channel', { url: channel.url } ] } hideActions () { diff --git a/client/src/app/+search/video-lazy-load.resolver.ts b/client/src/app/+search/video-lazy-load.resolver.ts index e8b2b8c74..d4fe6ed79 100644 --- a/client/src/app/+search/video-lazy-load.resolver.ts +++ b/client/src/app/+search/video-lazy-load.resolver.ts @@ -12,20 +12,12 @@ export class VideoLazyLoadResolver implements Resolve { resolve (route: ActivatedRouteSnapshot) { const url = route.params.url - const externalRedirect = route.params.externalRedirect - const fromPath = route.params.fromPath if (!url) { console.error('Could not find url param.', { params: route.params }) return this.router.navigateByUrl('/404') } - if (externalRedirect === 'true') { - window.open(url) - this.router.navigateByUrl(fromPath) - return - } - return this.searchService.searchVideos({ search: url }) .pipe( map(result => { diff --git a/client/src/app/shared/shared-thumbnail/video-thumbnail.component.html b/client/src/app/shared/shared-thumbnail/video-thumbnail.component.html index fe5510c56..0cb0f321b 100644 --- a/client/src/app/shared/shared-thumbnail/video-thumbnail.component.html +++ b/client/src/app/shared/shared-thumbnail/video-thumbnail.component.html @@ -1,7 +1,12 @@ - + + + + + + + + +
@@ -30,4 +35,4 @@
- + diff --git a/client/src/app/shared/shared-thumbnail/video-thumbnail.component.ts b/client/src/app/shared/shared-thumbnail/video-thumbnail.component.ts index 3ff45d9b7..812c7a508 100644 --- a/client/src/app/shared/shared-thumbnail/video-thumbnail.component.ts +++ b/client/src/app/shared/shared-thumbnail/video-thumbnail.component.ts @@ -11,8 +11,11 @@ import { Video } from '../shared-main' export class VideoThumbnailComponent { @Input() video: Video @Input() nsfw = false - @Input() routerLink: any[] + + @Input() videoRouterLink: any[] @Input() queryParams: { [ p: string ]: any } + @Input() videoHref: string + @Input() videoTarget: string @Input() displayWatchLaterPlaylist: boolean @Input() inWatchLaterPlaylist: boolean @@ -49,7 +52,7 @@ export class VideoThumbnailComponent { } getVideoRouterLink () { - if (this.routerLink) return this.routerLink + if (this.videoRouterLink) return this.videoRouterLink return [ '/videos/watch', this.video.uuid ] } diff --git a/client/src/app/shared/shared-video-miniature/video-miniature.component.html b/client/src/app/shared/shared-video-miniature/video-miniature.component.html index e5d91e69a..a88b3bc9e 100644 --- a/client/src/app/shared/shared-video-miniature/video-miniature.component.html +++ b/client/src/app/shared/shared-video-miniature/video-miniature.component.html @@ -1,6 +1,6 @@
Unlisted @@ -15,10 +15,12 @@
- {{ video.name }} + + {{ video.name }} diff --git a/client/src/app/shared/shared-video-miniature/video-miniature.component.ts b/client/src/app/shared/shared-video-miniature/video-miniature.component.ts index e1adbb6ad..f434550dd 100644 --- a/client/src/app/shared/shared-video-miniature/video-miniature.component.ts +++ b/client/src/app/shared/shared-video-miniature/video-miniature.component.ts @@ -29,6 +29,7 @@ export type MiniatureDisplayOptions = { blacklistInfo?: boolean nsfw?: boolean } +export type VideoLinkType = 'internal' | 'lazy-load' | 'external' @Component({ selector: 'my-video-miniature', @@ -55,7 +56,7 @@ export class VideoMiniatureComponent implements OnInit { @Input() displayVideoActions = true @Input() fitWidth = false - @Input() useLazyLoadUrl = false + @Input() videoLinkType: VideoLinkType = 'internal' @Output() videoBlocked = new EventEmitter() @Output() videoUnblocked = new EventEmitter() @@ -85,7 +86,9 @@ export class VideoMiniatureComponent implements OnInit { playlistElementId?: number } - videoLink: any[] = [] + videoRouterLink: any[] = [] + videoHref: string + videoTarget: string private ownerDisplayTypeChosen: 'account' | 'videoChannel' @@ -125,18 +128,20 @@ export class VideoMiniatureComponent implements OnInit { } buildVideoLink () { - if (this.useLazyLoadUrl && this.video.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 - - this.videoLink = [ '/search/lazy-load-video', { url: this.video.url, externalRedirect, fromPath } ] + if (this.videoLinkType === 'internal' || !this.video.url) { + this.videoRouterLink = [ '/videos/watch', this.video.uuid ] return } - this.videoLink = [ '/videos/watch', this.video.uuid ] + if (this.videoLinkType === 'external') { + this.videoRouterLink = null + this.videoHref = this.video.url + this.videoTarget = '_blank' + return + } + + // Lazy load + this.videoRouterLink = [ '/search/lazy-load-video', { url: this.video.url } ] } displayOwnerAccount () { diff --git a/client/src/app/shared/shared-video-playlist/video-playlist-element-miniature.component.html b/client/src/app/shared/shared-video-playlist/video-playlist-element-miniature.component.html index e3f7ef017..473fdc102 100644 --- a/client/src/app/shared/shared-video-playlist/video-playlist-element-miniature.component.html +++ b/client/src/app/shared/shared-video-playlist/video-playlist-element-miniature.component.html @@ -8,7 +8,7 @@