diff options
Diffstat (limited to 'client/src/app/shared')
3 files changed, 8 insertions, 29 deletions
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 @@ | |||
1 | import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' | 1 | import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' |
2 | import { Notifier, ServerService } from '@app/core' | 2 | import { Notifier, ServerService } from '@app/core' |
3 | import { Account, BytesPipe, VideoChannel } from '@app/shared/shared-main' | 3 | import { getBytes } from '@root-helpers/bytes' |
4 | import { ServerConfig } from '@shared/models' | 4 | import { ServerConfig } from '@shared/models' |
5 | import { VideoChannel } from '../video-channel/video-channel.model' | ||
6 | import { Account } from '../account/account.model' | ||
5 | 7 | ||
6 | @Component({ | 8 | @Component({ |
7 | selector: 'my-actor-avatar-info', | 9 | selector: 'my-actor-avatar-info', |
@@ -18,13 +20,11 @@ export class ActorAvatarInfoComponent implements OnInit { | |||
18 | maxSizeText: string | 20 | maxSizeText: string |
19 | 21 | ||
20 | private serverConfig: ServerConfig | 22 | private serverConfig: ServerConfig |
21 | private bytesPipe: BytesPipe | ||
22 | 23 | ||
23 | constructor ( | 24 | constructor ( |
24 | private serverService: ServerService, | 25 | private serverService: ServerService, |
25 | private notifier: Notifier | 26 | private notifier: Notifier |
26 | ) { | 27 | ) { |
27 | this.bytesPipe = new BytesPipe() | ||
28 | this.maxSizeText = $localize`max size` | 28 | this.maxSizeText = $localize`max size` |
29 | } | 29 | } |
30 | 30 | ||
@@ -52,7 +52,7 @@ export class ActorAvatarInfoComponent implements OnInit { | |||
52 | } | 52 | } |
53 | 53 | ||
54 | get maxAvatarSizeInBytes () { | 54 | get maxAvatarSizeInBytes () { |
55 | return this.bytesPipe.transform(this.maxAvatarSize) | 55 | return getBytes(this.maxAvatarSize) |
56 | } | 56 | } |
57 | 57 | ||
58 | get avatarExtensions () { | 58 | 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 @@ | |||
1 | import { Pipe, PipeTransform } from '@angular/core' | 1 | import { Pipe, PipeTransform } from '@angular/core' |
2 | import { getBytes } from '@root-helpers/bytes' | ||
2 | 3 | ||
3 | // Thanks: https://github.com/danrevah/ngx-pipes/blob/master/src/ng-pipes/pipes/math/bytes.ts | 4 | // Thanks: https://github.com/danrevah/ngx-pipes/blob/master/src/ng-pipes/pipes/math/bytes.ts |
4 | 5 | ||
5 | @Pipe({ name: 'bytes' }) | 6 | @Pipe({ name: 'bytes' }) |
6 | export class BytesPipe implements PipeTransform { | 7 | export class BytesPipe implements PipeTransform { |
7 | private dictionary: Array<{ max: number; type: string }> = [ | ||
8 | { max: 1024, type: 'B' }, | ||
9 | { max: 1048576, type: 'KB' }, | ||
10 | { max: 1073741824, type: 'MB' }, | ||
11 | { max: 1.0995116e12, type: 'GB' } | ||
12 | ] | ||
13 | 8 | ||
14 | transform (value: number, precision?: number | undefined): string | number { | 9 | transform (value: number, precision?: number | undefined): string | number { |
15 | const format = this.dictionary.find(d => value < d.max) || this.dictionary[this.dictionary.length - 1] | 10 | return getBytes(value, precision) |
16 | const calc = value / (format.max / 1024) | ||
17 | |||
18 | const num = precision === undefined | ||
19 | ? calc | ||
20 | : applyPrecision(calc, precision) | ||
21 | |||
22 | return `${num} ${format.type}` | ||
23 | } | 11 | } |
24 | } | 12 | } |
25 | |||
26 | function applyPrecision (num: number, precision: number) { | ||
27 | if (precision <= 0) { | ||
28 | return Math.round(num) | ||
29 | } | ||
30 | |||
31 | const tho = 10 ** precision | ||
32 | |||
33 | return Math.round(num * tho) / tho | ||
34 | } | ||
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 { | |||
21 | VideoUpdate | 21 | VideoUpdate |
22 | } from '@shared/models' | 22 | } from '@shared/models' |
23 | import { environment } from '../../../../environments/environment' | 23 | import { environment } from '../../../../environments/environment' |
24 | import { Account, AccountService } from '../account' | 24 | import { Account } from '../account/account.model' |
25 | import { AccountService } from '../account/account.service' | ||
25 | import { VideoChannel, VideoChannelService } from '../video-channel' | 26 | import { VideoChannel, VideoChannelService } from '../video-channel' |
26 | import { VideoDetails } from './video-details.model' | 27 | import { VideoDetails } from './video-details.model' |
27 | import { VideoEdit } from './video-edit.model' | 28 | import { VideoEdit } from './video-edit.model' |