Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Fix circular dependencies

Chocobozzzb4c3c51dc874
diff --git a/client/src/app/core/users/user.service.ts b/client/src/app/core/users/user.service.ts
index 01c9be5bf6..2f39451690 100644
--- a/client/src/app/core/users/user.service.ts
+++ b/client/src/app/core/users/user.service.ts
@@ -4,7 +4,7 @@ import { catchError, concatMap, filter, first, map, shareReplay, throttleTime, t
import { HttpClient, HttpParams } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { AuthService } from '@app/core/auth'
-import { BytesPipe } from '@app/shared/shared-main'
+import { getBytes } from '@root-helpers/bytes'
import { UserLocalStorageKeys } from '@root-helpers/users'
import {
Avatar,
@@ -27,8 +27,6 @@ import { User } from './user.model'
export class UserService {
static BASE_USERS_URL = environment.apiUrl + '/api/v1/users/'
- private bytesPipe = new BytesPipe()
-
private userCache: { [ id: number ]: Observable<UserServerModel> } = {}
constructor (
@@ -365,19 +363,19 @@ export class UserService {
if (user.videoQuota === -1) {
videoQuota = '∞'
} else {
- videoQuota = this.bytesPipe.transform(user.videoQuota, 0)
+ videoQuota = getBytes(user.videoQuota, 0)
}
- const videoQuotaUsed = this.bytesPipe.transform(user.videoQuotaUsed, 0)
+ const videoQuotaUsed = getBytes(user.videoQuotaUsed, 0)
let videoQuotaDaily: string
let videoQuotaUsedDaily: string
if (user.videoQuotaDaily === -1) {
videoQuotaDaily = '∞'
- videoQuotaUsedDaily = this.bytesPipe.transform(0, 0) + ''
+ videoQuotaUsedDaily = getBytes(0, 0) + ''
} else {
- videoQuotaDaily = this.bytesPipe.transform(user.videoQuotaDaily, 0) + ''
- videoQuotaUsedDaily = this.bytesPipe.transform(user.videoQuotaUsedDaily || 0, 0) + ''
+ videoQuotaDaily = getBytes(user.videoQuotaDaily, 0) + ''
+ videoQuotaUsedDaily = getBytes(user.videoQuotaUsedDaily || 0, 0) + ''
}
const roleLabels: { [ id in UserRole ]: string } = {
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 3a86e5b21a..5daa54cb59 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 f4f473568b..f3f57b8255 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 b01e919aae..48aff82b48 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'
diff --git a/client/src/root-helpers/bytes.ts b/client/src/root-helpers/bytes.ts
new file mode 100644
index 0000000000..ec8b55faae
--- /dev/null
+++ b/client/src/root-helpers/bytes.ts
@@ -0,0 +1,31 @@
+const dictionary: Array<{ max: number; type: string }> = [
+ { max: 1024, type: 'B' },
+ { max: 1048576, type: 'KB' },
+ { max: 1073741824, type: 'MB' },
+ { max: 1.0995116e12, type: 'GB' }
+]
+
+function getBytes (value: number, precision?: number | undefined): string | number {
+ const format = dictionary.find(d => value < d.max) || dictionary[dictionary.length - 1]
+ const calc = value / (format.max / 1024)
+
+ const num = precision === undefined
+ ? calc
+ : applyPrecision(calc, precision)
+
+ return `${num} ${format.type}`
+}
+
+function applyPrecision (num: number, precision: number) {
+ if (precision <= 0) {
+ return Math.round(num)
+ }
+
+ const tho = 10 ** precision
+
+ return Math.round(num * tho) / tho
+}
+
+export {
+ getBytes
+}
diff --git a/client/src/root-helpers/index.ts b/client/src/root-helpers/index.ts
index 59468b31ce..036a7677db 100644
--- a/client/src/root-helpers/index.ts
+++ b/client/src/root-helpers/index.ts
@@ -1,3 +1,4 @@
export * from './users'
+export * from './bytes'
export * from './peertube-web-storage'
export * from './utils'