From b5b687550d8ef8beafdf706e45d6556fb5f4c876 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 26 Oct 2020 16:44:23 +0100 Subject: Add ability to save live replay --- .../shared-main/angular/duration-formatter.pipe.ts | 32 ++++++++++++++++++++++ client/src/app/shared/shared-main/angular/index.ts | 1 + .../app/shared/shared-main/shared-main.module.ts | 14 ++++++++-- .../shared/shared-main/video/live-video.service.ts | 10 +++++-- 4 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 client/src/app/shared/shared-main/angular/duration-formatter.pipe.ts (limited to 'client/src/app/shared/shared-main') diff --git a/client/src/app/shared/shared-main/angular/duration-formatter.pipe.ts b/client/src/app/shared/shared-main/angular/duration-formatter.pipe.ts new file mode 100644 index 000000000..29ff864ec --- /dev/null +++ b/client/src/app/shared/shared-main/angular/duration-formatter.pipe.ts @@ -0,0 +1,32 @@ +import { Pipe, PipeTransform } from '@angular/core' + +@Pipe({ + name: 'myDurationFormatter' +}) +export class DurationFormatterPipe implements PipeTransform { + + transform (value: number): string { + const hours = Math.floor(value / 3600) + const minutes = Math.floor((value % 3600) / 60) + const seconds = value % 60 + + if (hours > 0) { + let result = $localize`${hours}h` + + if (minutes !== 0) result += ' ' + $localize`${minutes}min` + if (seconds !== 0) result += ' ' + $localize`${seconds}sec` + + return result + } + + if (minutes > 0) { + let result = $localize`${minutes}min` + + if (seconds !== 0) result += ' ' + `${seconds}sec` + + return result + } + + return $localize`${seconds} sec` + } +} diff --git a/client/src/app/shared/shared-main/angular/index.ts b/client/src/app/shared/shared-main/angular/index.ts index 9ba815136..29f8b3650 100644 --- a/client/src/app/shared/shared-main/angular/index.ts +++ b/client/src/app/shared/shared-main/angular/index.ts @@ -1,4 +1,5 @@ export * from './bytes.pipe' +export * from './duration-formatter.pipe' export * from './from-now.pipe' export * from './infinite-scroller.directive' export * from './number-formatter.pipe' diff --git a/client/src/app/shared/shared-main/shared-main.module.ts b/client/src/app/shared/shared-main/shared-main.module.ts index 0580872f4..3816cab19 100644 --- a/client/src/app/shared/shared-main/shared-main.module.ts +++ b/client/src/app/shared/shared-main/shared-main.module.ts @@ -15,7 +15,14 @@ import { } from '@ng-bootstrap/ng-bootstrap' import { SharedGlobalIconModule } from '../shared-icons' import { AccountService, ActorAvatarInfoComponent, AvatarComponent } from './account' -import { FromNowPipe, InfiniteScrollerDirective, NumberFormatterPipe, PeerTubeTemplateDirective, BytesPipe } from './angular' +import { + BytesPipe, + DurationFormatterPipe, + FromNowPipe, + InfiniteScrollerDirective, + NumberFormatterPipe, + PeerTubeTemplateDirective +} from './angular' import { AUTH_INTERCEPTOR_PROVIDER } from './auth' import { ActionDropdownComponent, ButtonComponent, DeleteButtonComponent, EditButtonComponent } from './buttons' import { DateToggleComponent } from './date' @@ -23,7 +30,7 @@ import { FeedComponent } from './feeds' import { LoaderComponent, SmallLoaderComponent } from './loaders' import { HelpComponent, ListOverflowComponent, TopMenuDropdownComponent } from './misc' import { UserHistoryService, UserNotificationsComponent, UserNotificationService, UserQuotaComponent } from './users' -import { RedundancyService, VideoImportService, VideoOwnershipService, VideoService, LiveVideoService } from './video' +import { LiveVideoService, RedundancyService, VideoImportService, VideoOwnershipService, VideoService } from './video' import { VideoCaptionService } from './video-caption' import { VideoChannelService } from './video-channel' @@ -56,6 +63,8 @@ import { VideoChannelService } from './video-channel' FromNowPipe, NumberFormatterPipe, BytesPipe, + DurationFormatterPipe, + InfiniteScrollerDirective, PeerTubeTemplateDirective, @@ -103,6 +112,7 @@ import { VideoChannelService } from './video-channel' FromNowPipe, BytesPipe, NumberFormatterPipe, + DurationFormatterPipe, InfiniteScrollerDirective, PeerTubeTemplateDirective, diff --git a/client/src/app/shared/shared-main/video/live-video.service.ts b/client/src/app/shared/shared-main/video/live-video.service.ts index 2cd1c66a5..093d65e83 100644 --- a/client/src/app/shared/shared-main/video/live-video.service.ts +++ b/client/src/app/shared/shared-main/video/live-video.service.ts @@ -2,7 +2,7 @@ import { catchError } from 'rxjs/operators' import { HttpClient } from '@angular/common/http' import { Injectable } from '@angular/core' import { RestExtractor } from '@app/core' -import { VideoCreate, LiveVideo } from '@shared/models' +import { LiveVideo, LiveVideoCreate, LiveVideoUpdate } from '@shared/models' import { environment } from '../../../../environments/environment' @Injectable() @@ -14,7 +14,7 @@ export class LiveVideoService { private restExtractor: RestExtractor ) {} - goLive (video: VideoCreate) { + goLive (video: LiveVideoCreate) { return this.authHttp .post<{ video: { id: number, uuid: string } }>(LiveVideoService.BASE_VIDEO_LIVE_URL, video) .pipe(catchError(err => this.restExtractor.handleError(err))) @@ -25,4 +25,10 @@ export class LiveVideoService { .get(LiveVideoService.BASE_VIDEO_LIVE_URL + videoId) .pipe(catchError(err => this.restExtractor.handleError(err))) } + + updateLive (videoId: number | string, liveUpdate: LiveVideoUpdate) { + return this.authHttp + .put(LiveVideoService.BASE_VIDEO_LIVE_URL + videoId, liveUpdate) + .pipe(catchError(err => this.restExtractor.handleError(err))) + } } -- cgit v1.2.3