diff options
Diffstat (limited to 'client/src/app/shared/shared-main/video-channel')
-rw-r--r-- | client/src/app/shared/shared-main/video-channel/video-channel.model.ts | 53 | ||||
-rw-r--r-- | client/src/app/shared/shared-main/video-channel/video-channel.service.ts | 12 |
2 files changed, 49 insertions, 16 deletions
diff --git a/client/src/app/shared/shared-main/video-channel/video-channel.model.ts b/client/src/app/shared/shared-main/video-channel/video-channel.model.ts index c6a63fe6c..1ba3fcc0e 100644 --- a/client/src/app/shared/shared-main/video-channel/video-channel.model.ts +++ b/client/src/app/shared/shared-main/video-channel/video-channel.model.ts | |||
@@ -1,15 +1,22 @@ | |||
1 | import { VideoChannel as ServerVideoChannel, ViewsPerDate, Account, Avatar } from '@shared/models' | 1 | import { getAbsoluteAPIUrl } from '@app/helpers' |
2 | import { Account as ServerAccount, ActorImage, VideoChannel as ServerVideoChannel, ViewsPerDate } from '@shared/models' | ||
3 | import { Account } from '../account/account.model' | ||
2 | import { Actor } from '../account/actor.model' | 4 | import { Actor } from '../account/actor.model' |
3 | 5 | ||
4 | export class VideoChannel extends Actor implements ServerVideoChannel { | 6 | export class VideoChannel extends Actor implements ServerVideoChannel { |
5 | displayName: string | 7 | displayName: string |
6 | description: string | 8 | description: string |
7 | support: string | 9 | support: string |
10 | |||
8 | isLocal: boolean | 11 | isLocal: boolean |
12 | |||
9 | nameWithHost: string | 13 | nameWithHost: string |
10 | nameWithHostForced: string | 14 | nameWithHostForced: string |
11 | 15 | ||
12 | ownerAccount?: Account | 16 | banner: ActorImage |
17 | bannerUrl: string | ||
18 | |||
19 | ownerAccount?: ServerAccount | ||
13 | ownerBy?: string | 20 | ownerBy?: string |
14 | ownerAvatarUrl?: string | 21 | ownerAvatarUrl?: string |
15 | 22 | ||
@@ -21,19 +28,33 @@ export class VideoChannel extends Actor implements ServerVideoChannel { | |||
21 | return Actor.GET_ACTOR_AVATAR_URL(actor) || this.GET_DEFAULT_AVATAR_URL() | 28 | return Actor.GET_ACTOR_AVATAR_URL(actor) || this.GET_DEFAULT_AVATAR_URL() |
22 | } | 29 | } |
23 | 30 | ||
31 | static GET_ACTOR_BANNER_URL (channel: ServerVideoChannel) { | ||
32 | if (channel?.banner?.url) return channel.banner.url | ||
33 | |||
34 | if (channel && channel.banner) { | ||
35 | const absoluteAPIUrl = getAbsoluteAPIUrl() | ||
36 | |||
37 | return absoluteAPIUrl + channel.banner.path | ||
38 | } | ||
39 | |||
40 | return '' | ||
41 | } | ||
42 | |||
24 | static GET_DEFAULT_AVATAR_URL () { | 43 | static GET_DEFAULT_AVATAR_URL () { |
25 | return `${window.location.origin}/client/assets/images/default-avatar-videochannel.png` | 44 | return `${window.location.origin}/client/assets/images/default-avatar-videochannel.png` |
26 | } | 45 | } |
27 | 46 | ||
28 | constructor (hash: ServerVideoChannel) { | 47 | constructor (hash: Partial<ServerVideoChannel>) { |
29 | super(hash) | 48 | super(hash) |
30 | 49 | ||
31 | this.updateComputedAttributes() | ||
32 | |||
33 | this.displayName = hash.displayName | 50 | this.displayName = hash.displayName |
34 | this.description = hash.description | 51 | this.description = hash.description |
35 | this.support = hash.support | 52 | this.support = hash.support |
53 | |||
54 | this.banner = hash.banner | ||
55 | |||
36 | this.isLocal = hash.isLocal | 56 | this.isLocal = hash.isLocal |
57 | |||
37 | this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host) | 58 | this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host) |
38 | this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true) | 59 | this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true) |
39 | 60 | ||
@@ -46,22 +67,34 @@ export class VideoChannel extends Actor implements ServerVideoChannel { | |||
46 | if (hash.ownerAccount) { | 67 | if (hash.ownerAccount) { |
47 | this.ownerAccount = hash.ownerAccount | 68 | this.ownerAccount = hash.ownerAccount |
48 | this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host) | 69 | this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host) |
49 | this.ownerAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.ownerAccount) | 70 | this.ownerAvatarUrl = Account.GET_ACTOR_AVATAR_URL(this.ownerAccount) |
50 | } | 71 | } |
72 | |||
73 | this.updateComputedAttributes() | ||
51 | } | 74 | } |
52 | 75 | ||
53 | updateAvatar (newAvatar: Avatar) { | 76 | updateAvatar (newAvatar: ActorImage) { |
54 | this.avatar = newAvatar | 77 | this.avatar = newAvatar |
55 | 78 | ||
56 | this.updateComputedAttributes() | 79 | this.updateComputedAttributes() |
57 | } | 80 | } |
58 | 81 | ||
59 | resetAvatar () { | 82 | resetAvatar () { |
60 | this.avatar = null | 83 | this.updateAvatar(null) |
61 | this.avatarUrl = VideoChannel.GET_DEFAULT_AVATAR_URL() | 84 | } |
85 | |||
86 | updateBanner (newBanner: ActorImage) { | ||
87 | this.banner = newBanner | ||
88 | |||
89 | this.updateComputedAttributes() | ||
90 | } | ||
91 | |||
92 | resetBanner () { | ||
93 | this.updateBanner(null) | ||
62 | } | 94 | } |
63 | 95 | ||
64 | private updateComputedAttributes () { | 96 | updateComputedAttributes () { |
65 | this.avatarUrl = VideoChannel.GET_ACTOR_AVATAR_URL(this) | 97 | this.avatarUrl = VideoChannel.GET_ACTOR_AVATAR_URL(this) |
98 | this.bannerUrl = VideoChannel.GET_ACTOR_BANNER_URL(this) | ||
66 | } | 99 | } |
67 | } | 100 | } |
diff --git a/client/src/app/shared/shared-main/video-channel/video-channel.service.ts b/client/src/app/shared/shared-main/video-channel/video-channel.service.ts index eff3fad4d..e65261763 100644 --- a/client/src/app/shared/shared-main/video-channel/video-channel.service.ts +++ b/client/src/app/shared/shared-main/video-channel/video-channel.service.ts | |||
@@ -3,7 +3,7 @@ import { catchError, map, tap } from 'rxjs/operators' | |||
3 | import { HttpClient, HttpParams } from '@angular/common/http' | 3 | import { HttpClient, HttpParams } from '@angular/common/http' |
4 | import { Injectable } from '@angular/core' | 4 | import { Injectable } from '@angular/core' |
5 | import { ComponentPaginationLight, RestExtractor, RestService } from '@app/core' | 5 | import { ComponentPaginationLight, RestExtractor, RestService } from '@app/core' |
6 | import { Avatar, ResultList, VideoChannel as VideoChannelServer, VideoChannelCreate, VideoChannelUpdate } from '@shared/models' | 6 | import { ActorImage, ResultList, VideoChannel as VideoChannelServer, VideoChannelCreate, VideoChannelUpdate } from '@shared/models' |
7 | import { environment } from '../../../../environments/environment' | 7 | import { environment } from '../../../../environments/environment' |
8 | import { Account } from '../account' | 8 | import { Account } from '../account' |
9 | import { AccountService } from '../account/account.service' | 9 | import { AccountService } from '../account/account.service' |
@@ -82,15 +82,15 @@ export class VideoChannelService { | |||
82 | ) | 82 | ) |
83 | } | 83 | } |
84 | 84 | ||
85 | changeVideoChannelAvatar (videoChannelName: string, avatarForm: FormData) { | 85 | changeVideoChannelImage (videoChannelName: string, avatarForm: FormData, type: 'avatar' | 'banner') { |
86 | const url = VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannelName + '/avatar/pick' | 86 | const url = VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannelName + '/' + type + '/pick' |
87 | 87 | ||
88 | return this.authHttp.post<{ avatar: Avatar }>(url, avatarForm) | 88 | return this.authHttp.post<{ avatar?: ActorImage, banner?: ActorImage }>(url, avatarForm) |
89 | .pipe(catchError(err => this.restExtractor.handleError(err))) | 89 | .pipe(catchError(err => this.restExtractor.handleError(err))) |
90 | } | 90 | } |
91 | 91 | ||
92 | deleteVideoChannelAvatar (videoChannelName: string) { | 92 | deleteVideoChannelImage (videoChannelName: string, type: 'avatar' | 'banner') { |
93 | const url = VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannelName + '/avatar' | 93 | const url = VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannelName + '/' + type |
94 | 94 | ||
95 | return this.authHttp.delete(url) | 95 | return this.authHttp.delete(url) |
96 | .pipe( | 96 | .pipe( |