aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/video-channel
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-06-23 14:10:17 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-06-23 16:00:49 +0200
commit67ed6552b831df66713bac9e672738796128d33f (patch)
tree59c97d41e0b49d75a90aa3de987968ab9b1ff447 /client/src/app/shared/video-channel
parent0c4bacbff53bc732f5a2677d62a6ead7752e2405 (diff)
downloadPeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.gz
PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.zst
PeerTube-67ed6552b831df66713bac9e672738796128d33f.zip
Reorganize client shared modules
Diffstat (limited to 'client/src/app/shared/video-channel')
-rw-r--r--client/src/app/shared/video-channel/video-channel.model.ts43
-rw-r--r--client/src/app/shared/video-channel/video-channel.service.ts98
2 files changed, 0 insertions, 141 deletions
diff --git a/client/src/app/shared/video-channel/video-channel.model.ts b/client/src/app/shared/video-channel/video-channel.model.ts
deleted file mode 100644
index 2f4597343..000000000
--- a/client/src/app/shared/video-channel/video-channel.model.ts
+++ /dev/null
@@ -1,43 +0,0 @@
1import { VideoChannel as ServerVideoChannel, ViewsPerDate } from '../../../../../shared/models/videos'
2import { Actor } from '../actor/actor.model'
3import { Account } from '../../../../../shared/models/actors'
4
5export class VideoChannel extends Actor implements ServerVideoChannel {
6 displayName: string
7 description: string
8 support: string
9 isLocal: boolean
10 nameWithHost: string
11 nameWithHostForced: string
12
13 ownerAccount?: Account
14 ownerBy?: string
15 ownerAvatarUrl?: string
16
17 videosCount?: number
18
19 viewsPerDay?: ViewsPerDate[]
20
21 constructor (hash: ServerVideoChannel) {
22 super(hash)
23
24 this.displayName = hash.displayName
25 this.description = hash.description
26 this.support = hash.support
27 this.isLocal = hash.isLocal
28 this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host)
29 this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true)
30
31 this.videosCount = hash.videosCount
32
33 if (hash.viewsPerDay) {
34 this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) }))
35 }
36
37 if (hash.ownerAccount) {
38 this.ownerAccount = hash.ownerAccount
39 this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host)
40 this.ownerAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.ownerAccount)
41 }
42 }
43}
diff --git a/client/src/app/shared/video-channel/video-channel.service.ts b/client/src/app/shared/video-channel/video-channel.service.ts
deleted file mode 100644
index 0e036bda7..000000000
--- a/client/src/app/shared/video-channel/video-channel.service.ts
+++ /dev/null
@@ -1,98 +0,0 @@
1import { catchError, map, tap } from 'rxjs/operators'
2import { Injectable } from '@angular/core'
3import { Observable, ReplaySubject } from 'rxjs'
4import { RestExtractor } from '../rest/rest-extractor.service'
5import { HttpClient, HttpParams } from '@angular/common/http'
6import { VideoChannel as VideoChannelServer, VideoChannelCreate, VideoChannelUpdate } from '../../../../../shared/models/videos'
7import { AccountService } from '../account/account.service'
8import { ResultList } from '../../../../../shared'
9import { VideoChannel } from './video-channel.model'
10import { environment } from '../../../environments/environment'
11import { Account } from '@app/shared/account/account.model'
12import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
13import { ComponentPaginationLight } from '@app/shared/rest/component-pagination.model'
14import { RestService } from '@app/shared/rest'
15
16@Injectable()
17export class VideoChannelService {
18 static BASE_VIDEO_CHANNEL_URL = environment.apiUrl + '/api/v1/video-channels/'
19
20 videoChannelLoaded = new ReplaySubject<VideoChannel>(1)
21
22 static extractVideoChannels (result: ResultList<VideoChannelServer>) {
23 const videoChannels: VideoChannel[] = []
24
25 for (const videoChannelJSON of result.data) {
26 videoChannels.push(new VideoChannel(videoChannelJSON))
27 }
28
29 return { data: videoChannels, total: result.total }
30 }
31
32 constructor (
33 private authHttp: HttpClient,
34 private restService: RestService,
35 private restExtractor: RestExtractor
36 ) { }
37
38 getVideoChannel (videoChannelName: string) {
39 return this.authHttp.get<VideoChannel>(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannelName)
40 .pipe(
41 map(videoChannelHash => new VideoChannel(videoChannelHash)),
42 tap(videoChannel => this.videoChannelLoaded.next(videoChannel)),
43 catchError(err => this.restExtractor.handleError(err))
44 )
45 }
46
47 listAccountVideoChannels (
48 account: Account,
49 componentPagination?: ComponentPaginationLight,
50 withStats = false
51 ): Observable<ResultList<VideoChannel>> {
52 const pagination = componentPagination
53 ? this.restService.componentPaginationToRestPagination(componentPagination)
54 : { start: 0, count: 20 }
55
56 let params = new HttpParams()
57 params = this.restService.addRestGetParams(params, pagination)
58 params = params.set('withStats', withStats + '')
59
60 const url = AccountService.BASE_ACCOUNT_URL + account.nameWithHost + '/video-channels'
61 return this.authHttp.get<ResultList<VideoChannelServer>>(url, { params })
62 .pipe(
63 map(res => VideoChannelService.extractVideoChannels(res)),
64 catchError(err => this.restExtractor.handleError(err))
65 )
66 }
67
68 createVideoChannel (videoChannel: VideoChannelCreate) {
69 return this.authHttp.post(VideoChannelService.BASE_VIDEO_CHANNEL_URL, videoChannel)
70 .pipe(
71 map(this.restExtractor.extractDataBool),
72 catchError(err => this.restExtractor.handleError(err))
73 )
74 }
75
76 updateVideoChannel (videoChannelName: string, videoChannel: VideoChannelUpdate) {
77 return this.authHttp.put(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannelName, videoChannel)
78 .pipe(
79 map(this.restExtractor.extractDataBool),
80 catchError(err => this.restExtractor.handleError(err))
81 )
82 }
83
84 changeVideoChannelAvatar (videoChannelName: string, avatarForm: FormData) {
85 const url = VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannelName + '/avatar/pick'
86
87 return this.authHttp.post<{ avatar: Avatar }>(url, avatarForm)
88 .pipe(catchError(err => this.restExtractor.handleError(err)))
89 }
90
91 removeVideoChannel (videoChannel: VideoChannel) {
92 return this.authHttp.delete(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannel.nameWithHost)
93 .pipe(
94 map(this.restExtractor.extractDataBool),
95 catchError(err => this.restExtractor.handleError(err))
96 )
97 }
98}