From b4c3c51dc874711febf43b719ca878436b31084d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 14 Aug 2020 17:28:54 +0200 Subject: Fix circular dependencies --- .../account/actor-avatar-info.component.ts | 8 +++---- .../app/shared/shared-main/angular/bytes.pipe.ts | 26 ++-------------------- .../app/shared/shared-main/video/video.service.ts | 3 ++- 3 files changed, 8 insertions(+), 29 deletions(-) (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/shared-main/account/actor-avatar-info.component.ts b/client/src/app/shared/shared-main/account/actor-avatar-info.component.ts index 3a86e5b21..5daa54cb5 100644 --- a/client/src/app/shared/shared-main/account/actor-avatar-info.component.ts +++ b/client/src/app/shared/shared-main/account/actor-avatar-info.component.ts @@ -1,7 +1,9 @@ import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' import { Notifier, ServerService } from '@app/core' -import { Account, BytesPipe, VideoChannel } from '@app/shared/shared-main' +import { getBytes } from '@root-helpers/bytes' import { ServerConfig } from '@shared/models' +import { VideoChannel } from '../video-channel/video-channel.model' +import { Account } from '../account/account.model' @Component({ selector: 'my-actor-avatar-info', @@ -18,13 +20,11 @@ export class ActorAvatarInfoComponent implements OnInit { maxSizeText: string private serverConfig: ServerConfig - private bytesPipe: BytesPipe constructor ( private serverService: ServerService, private notifier: Notifier ) { - this.bytesPipe = new BytesPipe() this.maxSizeText = $localize`max size` } @@ -52,7 +52,7 @@ export class ActorAvatarInfoComponent implements OnInit { } get maxAvatarSizeInBytes () { - return this.bytesPipe.transform(this.maxAvatarSize) + return getBytes(this.maxAvatarSize) } get avatarExtensions () { diff --git a/client/src/app/shared/shared-main/angular/bytes.pipe.ts b/client/src/app/shared/shared-main/angular/bytes.pipe.ts index f4f473568..f3f57b825 100644 --- a/client/src/app/shared/shared-main/angular/bytes.pipe.ts +++ b/client/src/app/shared/shared-main/angular/bytes.pipe.ts @@ -1,34 +1,12 @@ import { Pipe, PipeTransform } from '@angular/core' +import { getBytes } from '@root-helpers/bytes' // Thanks: https://github.com/danrevah/ngx-pipes/blob/master/src/ng-pipes/pipes/math/bytes.ts @Pipe({ name: 'bytes' }) export class BytesPipe implements PipeTransform { - private dictionary: Array<{ max: number; type: string }> = [ - { max: 1024, type: 'B' }, - { max: 1048576, type: 'KB' }, - { max: 1073741824, type: 'MB' }, - { max: 1.0995116e12, type: 'GB' } - ] transform (value: number, precision?: number | undefined): string | number { - const format = this.dictionary.find(d => value < d.max) || this.dictionary[this.dictionary.length - 1] - const calc = value / (format.max / 1024) - - const num = precision === undefined - ? calc - : applyPrecision(calc, precision) - - return `${num} ${format.type}` + return getBytes(value, precision) } } - -function applyPrecision (num: number, precision: number) { - if (precision <= 0) { - return Math.round(num) - } - - const tho = 10 ** precision - - return Math.round(num * tho) / tho -} diff --git a/client/src/app/shared/shared-main/video/video.service.ts b/client/src/app/shared/shared-main/video/video.service.ts index b01e919aa..48aff82b4 100644 --- a/client/src/app/shared/shared-main/video/video.service.ts +++ b/client/src/app/shared/shared-main/video/video.service.ts @@ -21,7 +21,8 @@ import { VideoUpdate } from '@shared/models' import { environment } from '../../../../environments/environment' -import { Account, AccountService } from '../account' +import { Account } from '../account/account.model' +import { AccountService } from '../account/account.service' import { VideoChannel, VideoChannelService } from '../video-channel' import { VideoDetails } from './video-details.model' import { VideoEdit } from './video-edit.model' -- cgit v1.2.3