From 67ed6552b831df66713bac9e672738796128d33f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Jun 2020 14:10:17 +0200 Subject: Reorganize client shared modules --- .../shared/video-channel/video-channel.model.ts | 43 ---------- .../shared/video-channel/video-channel.service.ts | 98 ---------------------- 2 files changed, 141 deletions(-) delete mode 100644 client/src/app/shared/video-channel/video-channel.model.ts delete mode 100644 client/src/app/shared/video-channel/video-channel.service.ts (limited to 'client/src/app/shared/video-channel') 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 @@ -import { VideoChannel as ServerVideoChannel, ViewsPerDate } from '../../../../../shared/models/videos' -import { Actor } from '../actor/actor.model' -import { Account } from '../../../../../shared/models/actors' - -export class VideoChannel extends Actor implements ServerVideoChannel { - displayName: string - description: string - support: string - isLocal: boolean - nameWithHost: string - nameWithHostForced: string - - ownerAccount?: Account - ownerBy?: string - ownerAvatarUrl?: string - - videosCount?: number - - viewsPerDay?: ViewsPerDate[] - - constructor (hash: ServerVideoChannel) { - super(hash) - - this.displayName = hash.displayName - this.description = hash.description - this.support = hash.support - this.isLocal = hash.isLocal - this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host) - this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true) - - this.videosCount = hash.videosCount - - if (hash.viewsPerDay) { - this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) })) - } - - if (hash.ownerAccount) { - this.ownerAccount = hash.ownerAccount - this.ownerBy = Actor.CREATE_BY_STRING(hash.ownerAccount.name, hash.ownerAccount.host) - this.ownerAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.ownerAccount) - } - } -} 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 @@ -import { catchError, map, tap } from 'rxjs/operators' -import { Injectable } from '@angular/core' -import { Observable, ReplaySubject } from 'rxjs' -import { RestExtractor } from '../rest/rest-extractor.service' -import { HttpClient, HttpParams } from '@angular/common/http' -import { VideoChannel as VideoChannelServer, VideoChannelCreate, VideoChannelUpdate } from '../../../../../shared/models/videos' -import { AccountService } from '../account/account.service' -import { ResultList } from '../../../../../shared' -import { VideoChannel } from './video-channel.model' -import { environment } from '../../../environments/environment' -import { Account } from '@app/shared/account/account.model' -import { Avatar } from '../../../../../shared/models/avatars/avatar.model' -import { ComponentPaginationLight } from '@app/shared/rest/component-pagination.model' -import { RestService } from '@app/shared/rest' - -@Injectable() -export class VideoChannelService { - static BASE_VIDEO_CHANNEL_URL = environment.apiUrl + '/api/v1/video-channels/' - - videoChannelLoaded = new ReplaySubject(1) - - static extractVideoChannels (result: ResultList) { - const videoChannels: VideoChannel[] = [] - - for (const videoChannelJSON of result.data) { - videoChannels.push(new VideoChannel(videoChannelJSON)) - } - - return { data: videoChannels, total: result.total } - } - - constructor ( - private authHttp: HttpClient, - private restService: RestService, - private restExtractor: RestExtractor - ) { } - - getVideoChannel (videoChannelName: string) { - return this.authHttp.get(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannelName) - .pipe( - map(videoChannelHash => new VideoChannel(videoChannelHash)), - tap(videoChannel => this.videoChannelLoaded.next(videoChannel)), - catchError(err => this.restExtractor.handleError(err)) - ) - } - - listAccountVideoChannels ( - account: Account, - componentPagination?: ComponentPaginationLight, - withStats = false - ): Observable> { - const pagination = componentPagination - ? this.restService.componentPaginationToRestPagination(componentPagination) - : { start: 0, count: 20 } - - let params = new HttpParams() - params = this.restService.addRestGetParams(params, pagination) - params = params.set('withStats', withStats + '') - - const url = AccountService.BASE_ACCOUNT_URL + account.nameWithHost + '/video-channels' - return this.authHttp.get>(url, { params }) - .pipe( - map(res => VideoChannelService.extractVideoChannels(res)), - catchError(err => this.restExtractor.handleError(err)) - ) - } - - createVideoChannel (videoChannel: VideoChannelCreate) { - return this.authHttp.post(VideoChannelService.BASE_VIDEO_CHANNEL_URL, videoChannel) - .pipe( - map(this.restExtractor.extractDataBool), - catchError(err => this.restExtractor.handleError(err)) - ) - } - - updateVideoChannel (videoChannelName: string, videoChannel: VideoChannelUpdate) { - return this.authHttp.put(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannelName, videoChannel) - .pipe( - map(this.restExtractor.extractDataBool), - catchError(err => this.restExtractor.handleError(err)) - ) - } - - changeVideoChannelAvatar (videoChannelName: string, avatarForm: FormData) { - const url = VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannelName + '/avatar/pick' - - return this.authHttp.post<{ avatar: Avatar }>(url, avatarForm) - .pipe(catchError(err => this.restExtractor.handleError(err))) - } - - removeVideoChannel (videoChannel: VideoChannel) { - return this.authHttp.delete(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannel.nameWithHost) - .pipe( - map(this.restExtractor.extractDataBool), - catchError(err => this.restExtractor.handleError(err)) - ) - } -} -- cgit v1.2.3