diff options
author | Chocobozzz <me@florianbigard.com> | 2020-07-20 11:37:06 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-07-20 11:37:06 +0200 |
commit | 0bdad52fbbad81e7654adc495088da56a00437df (patch) | |
tree | 206f4693cc7fa62531fdf6830d6bf9fbbdc07cc1 /client/src/app/+search | |
parent | 69a019968e225f1eac4a3df3041f141d0047d7f0 (diff) | |
download | PeerTube-0bdad52fbbad81e7654adc495088da56a00437df.tar.gz PeerTube-0bdad52fbbad81e7654adc495088da56a00437df.tar.zst PeerTube-0bdad52fbbad81e7654adc495088da56a00437df.zip |
Fix issues with external links in search page
Diffstat (limited to 'client/src/app/+search')
-rw-r--r-- | client/src/app/+search/channel-lazy-load.resolver.ts | 8 | ||||
-rw-r--r-- | client/src/app/+search/search.component.html | 20 | ||||
-rw-r--r-- | client/src/app/+search/search.component.ts | 36 | ||||
-rw-r--r-- | client/src/app/+search/video-lazy-load.resolver.ts | 8 |
4 files changed, 43 insertions, 29 deletions
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<any> { | |||
12 | 12 | ||
13 | resolve (route: ActivatedRouteSnapshot) { | 13 | resolve (route: ActivatedRouteSnapshot) { |
14 | const url = route.params.url | 14 | const url = route.params.url |
15 | const externalRedirect = route.params.externalRedirect | ||
16 | const fromPath = route.params.fromPath | ||
17 | 15 | ||
18 | if (!url) { | 16 | if (!url) { |
19 | console.error('Could not find url param.', { params: route.params }) | 17 | console.error('Could not find url param.', { params: route.params }) |
20 | return this.router.navigateByUrl('/404') | 18 | return this.router.navigateByUrl('/404') |
21 | } | 19 | } |
22 | 20 | ||
23 | if (externalRedirect === 'true') { | ||
24 | window.open(url) | ||
25 | this.router.navigateByUrl(fromPath) | ||
26 | return | ||
27 | } | ||
28 | |||
29 | return this.searchService.searchVideoChannels({ search: url }) | 21 | return this.searchService.searchVideoChannels({ search: url }) |
30 | .pipe( | 22 | .pipe( |
31 | map(result => { | 23 | 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 @@ | |||
35 | 35 | ||
36 | <ng-container *ngFor="let result of results"> | 36 | <ng-container *ngFor="let result of results"> |
37 | <div *ngIf="isVideoChannel(result)" class="entry video-channel"> | 37 | <div *ngIf="isVideoChannel(result)" class="entry video-channel"> |
38 | <a [routerLink]="getChannelUrl(result)"> | 38 | <a *ngIf="!isExternalChannelUrl()" [routerLink]="getChannelUrl(result)"> |
39 | <img [src]="result.avatarUrl" alt="Avatar" /> | ||
40 | </a> | ||
41 | |||
42 | <a *ngIf="isExternalChannelUrl()" [href]="getChannelUrl(result)" target="_blank"> | ||
39 | <img [src]="result.avatarUrl" alt="Avatar" /> | 43 | <img [src]="result.avatarUrl" alt="Avatar" /> |
40 | </a> | 44 | </a> |
41 | 45 | ||
42 | <div class="video-channel-info"> | 46 | <div class="video-channel-info"> |
43 | <a [routerLink]="getChannelUrl(result)" class="video-channel-names"> | 47 | <a *ngIf="!isExternalChannelUrl()" [routerLink]="getChannelUrl(result)" class="video-channel-names"> |
48 | <ng-container *ngTemplateOutlet="aContent"></ng-container> | ||
49 | </a> | ||
50 | |||
51 | <a *ngIf="isExternalChannelUrl()" [href]="getChannelUrl(result)" target="_blank" class="video-channel-names"> | ||
52 | <ng-container *ngTemplateOutlet="aContent"></ng-container> | ||
53 | </a> | ||
54 | |||
55 | <ng-template #aContent> | ||
44 | <div class="video-channel-display-name">{{ result.displayName }}</div> | 56 | <div class="video-channel-display-name">{{ result.displayName }}</div> |
45 | <div class="video-channel-name">{{ result.nameWithHost }}</div> | 57 | <div class="video-channel-name">{{ result.nameWithHost }}</div> |
46 | </a> | 58 | </ng-template> |
47 | 59 | ||
48 | <div i18n class="video-channel-followers">{{ result.followersCount }} subscribers</div> | 60 | <div i18n class="video-channel-followers">{{ result.followersCount }} subscribers</div> |
49 | </div> | 61 | </div> |
@@ -54,7 +66,7 @@ | |||
54 | <div *ngIf="isVideo(result)" class="entry video"> | 66 | <div *ngIf="isVideo(result)" class="entry video"> |
55 | <my-video-miniature | 67 | <my-video-miniature |
56 | [video]="result" [user]="userMiniature" [displayAsRow]="true" [displayVideoActions]="!hideActions()" | 68 | [video]="result" [user]="userMiniature" [displayAsRow]="true" [displayVideoActions]="!hideActions()" |
57 | [displayOptions]="videoDisplayOptions" [useLazyLoadUrl]="advancedSearch.searchTarget === 'search-index'" | 69 | [displayOptions]="videoDisplayOptions" [videoLinkType]="getVideoLinkType()" |
58 | (videoBlocked)="removeVideoFromArray(result)" (videoRemoved)="removeVideoFromArray(result)" | 70 | (videoBlocked)="removeVideoFromArray(result)" (videoRemoved)="removeVideoFromArray(result)" |
59 | ></my-video-miniature> | 71 | ></my-video-miniature> |
60 | </div> | 72 | </div> |
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 | |||
5 | import { immutableAssign } from '@app/helpers' | 5 | import { immutableAssign } from '@app/helpers' |
6 | import { Video, VideoChannel } from '@app/shared/shared-main' | 6 | import { Video, VideoChannel } from '@app/shared/shared-main' |
7 | import { AdvancedSearch, SearchService } from '@app/shared/shared-search' | 7 | import { AdvancedSearch, SearchService } from '@app/shared/shared-search' |
8 | import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature' | 8 | import { MiniatureDisplayOptions, VideoLinkType } from '@app/shared/shared-video-miniature' |
9 | import { MetaService } from '@ngx-meta/core' | 9 | import { MetaService } from '@ngx-meta/core' |
10 | import { I18n } from '@ngx-translate/i18n-polyfill' | 10 | import { I18n } from '@ngx-translate/i18n-polyfill' |
11 | import { SearchTargetType, ServerConfig } from '@shared/models' | 11 | import { SearchTargetType, ServerConfig } from '@shared/models' |
@@ -119,6 +119,25 @@ export class SearchComponent implements OnInit, OnDestroy { | |||
119 | return this.authService.isLoggedIn() | 119 | return this.authService.isLoggedIn() |
120 | } | 120 | } |
121 | 121 | ||
122 | getVideoLinkType (): VideoLinkType { | ||
123 | if (this.advancedSearch.searchTarget === 'search-index') { | ||
124 | const remoteUriConfig = this.serverConfig.search.remoteUri | ||
125 | |||
126 | // Redirect on the external instance if not allowed to fetch remote data | ||
127 | if ((!this.isUserLoggedIn() && !remoteUriConfig.anonymous) || !remoteUriConfig.users) { | ||
128 | return 'external' | ||
129 | } | ||
130 | |||
131 | return 'lazy-load' | ||
132 | } | ||
133 | |||
134 | return 'internal' | ||
135 | } | ||
136 | |||
137 | isExternalChannelUrl () { | ||
138 | return this.getVideoLinkType() === 'external' | ||
139 | } | ||
140 | |||
122 | search () { | 141 | search () { |
123 | forkJoin([ | 142 | forkJoin([ |
124 | this.getVideosObs(), | 143 | this.getVideosObs(), |
@@ -184,17 +203,16 @@ export class SearchComponent implements OnInit, OnDestroy { | |||
184 | } | 203 | } |
185 | 204 | ||
186 | getChannelUrl (channel: VideoChannel) { | 205 | getChannelUrl (channel: VideoChannel) { |
187 | if (this.advancedSearch.searchTarget === 'search-index' && channel.url) { | 206 | // Same algorithm than videos |
188 | const remoteUriConfig = this.serverConfig.search.remoteUri | 207 | if (this.getVideoLinkType() === 'external') { |
189 | 208 | return channel.url | |
190 | // Redirect on the external instance if not allowed to fetch remote data | 209 | } |
191 | const externalRedirect = (!this.authService.isLoggedIn() && !remoteUriConfig.anonymous) || !remoteUriConfig.users | ||
192 | const fromPath = window.location.pathname + window.location.search | ||
193 | 210 | ||
194 | return [ '/search/lazy-load-channel', { url: channel.url, externalRedirect, fromPath } ] | 211 | if (this.getVideoLinkType() === 'internal') { |
212 | return [ '/video-channels', channel.nameWithHost ] | ||
195 | } | 213 | } |
196 | 214 | ||
197 | return [ '/video-channels', channel.nameWithHost ] | 215 | return [ '/search/lazy-load-channel', { url: channel.url } ] |
198 | } | 216 | } |
199 | 217 | ||
200 | hideActions () { | 218 | 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<any> { | |||
12 | 12 | ||
13 | resolve (route: ActivatedRouteSnapshot) { | 13 | resolve (route: ActivatedRouteSnapshot) { |
14 | const url = route.params.url | 14 | const url = route.params.url |
15 | const externalRedirect = route.params.externalRedirect | ||
16 | const fromPath = route.params.fromPath | ||
17 | 15 | ||
18 | if (!url) { | 16 | if (!url) { |
19 | console.error('Could not find url param.', { params: route.params }) | 17 | console.error('Could not find url param.', { params: route.params }) |
20 | return this.router.navigateByUrl('/404') | 18 | return this.router.navigateByUrl('/404') |
21 | } | 19 | } |
22 | 20 | ||
23 | if (externalRedirect === 'true') { | ||
24 | window.open(url) | ||
25 | this.router.navigateByUrl(fromPath) | ||
26 | return | ||
27 | } | ||
28 | |||
29 | return this.searchService.searchVideos({ search: url }) | 21 | return this.searchService.searchVideos({ search: url }) |
30 | .pipe( | 22 | .pipe( |
31 | map(result => { | 23 | map(result => { |