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 | 40 | ||||
-rw-r--r-- | client/src/app/shared/shared-main/video-channel/video-channel.service.ts | 10 |
2 files changed, 41 insertions, 9 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 b4c3365a9..d8be42eef 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,3 +1,4 @@ | |||
1 | import { getAbsoluteAPIUrl } from '@app/helpers' | ||
1 | import { Account as ServerAccount, ActorImage, VideoChannel as ServerVideoChannel, ViewsPerDate } from '@shared/models' | 2 | import { Account as ServerAccount, ActorImage, VideoChannel as ServerVideoChannel, ViewsPerDate } from '@shared/models' |
2 | import { Account } from '../account/account.model' | 3 | import { Account } from '../account/account.model' |
3 | import { Actor } from '../account/actor.model' | 4 | import { Actor } from '../account/actor.model' |
@@ -6,10 +7,15 @@ export class VideoChannel extends Actor implements ServerVideoChannel { | |||
6 | displayName: string | 7 | displayName: string |
7 | description: string | 8 | description: string |
8 | support: string | 9 | support: string |
10 | |||
9 | isLocal: boolean | 11 | isLocal: boolean |
12 | |||
10 | nameWithHost: string | 13 | nameWithHost: string |
11 | nameWithHostForced: string | 14 | nameWithHostForced: string |
12 | 15 | ||
16 | banner: ActorImage | ||
17 | bannerUrl: string | ||
18 | |||
13 | ownerAccount?: ServerAccount | 19 | ownerAccount?: ServerAccount |
14 | ownerBy?: string | 20 | ownerBy?: string |
15 | ownerAvatarUrl?: string | 21 | ownerAvatarUrl?: string |
@@ -22,6 +28,18 @@ export class VideoChannel extends Actor implements ServerVideoChannel { | |||
22 | 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() |
23 | } | 29 | } |
24 | 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 | |||
25 | static GET_DEFAULT_AVATAR_URL () { | 43 | static GET_DEFAULT_AVATAR_URL () { |
26 | return `${window.location.origin}/client/assets/images/default-avatar-videochannel.png` | 44 | return `${window.location.origin}/client/assets/images/default-avatar-videochannel.png` |
27 | } | 45 | } |
@@ -29,12 +47,14 @@ export class VideoChannel extends Actor implements ServerVideoChannel { | |||
29 | constructor (hash: ServerVideoChannel) { | 47 | constructor (hash: ServerVideoChannel) { |
30 | super(hash) | 48 | super(hash) |
31 | 49 | ||
32 | this.updateComputedAttributes() | ||
33 | |||
34 | this.displayName = hash.displayName | 50 | this.displayName = hash.displayName |
35 | this.description = hash.description | 51 | this.description = hash.description |
36 | this.support = hash.support | 52 | this.support = hash.support |
53 | |||
54 | this.banner = hash.banner | ||
55 | |||
37 | this.isLocal = hash.isLocal | 56 | this.isLocal = hash.isLocal |
57 | |||
38 | this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host) | 58 | this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host) |
39 | this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true) | 59 | this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true) |
40 | 60 | ||
@@ -49,6 +69,8 @@ export class VideoChannel extends Actor implements ServerVideoChannel { | |||
49 | 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) |
50 | this.ownerAvatarUrl = Account.GET_ACTOR_AVATAR_URL(this.ownerAccount) | 70 | this.ownerAvatarUrl = Account.GET_ACTOR_AVATAR_URL(this.ownerAccount) |
51 | } | 71 | } |
72 | |||
73 | this.updateComputedAttributes() | ||
52 | } | 74 | } |
53 | 75 | ||
54 | updateAvatar (newAvatar: ActorImage) { | 76 | updateAvatar (newAvatar: ActorImage) { |
@@ -58,11 +80,21 @@ export class VideoChannel extends Actor implements ServerVideoChannel { | |||
58 | } | 80 | } |
59 | 81 | ||
60 | resetAvatar () { | 82 | resetAvatar () { |
61 | this.avatar = null | 83 | this.updateAvatar(null) |
62 | 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) | ||
63 | } | 94 | } |
64 | 95 | ||
65 | private updateComputedAttributes () { | 96 | private updateComputedAttributes () { |
66 | 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) | ||
67 | } | 99 | } |
68 | } | 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 3f9ef74fa..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 | |||
@@ -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: ActorImage }>(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( |