mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00

Sorry for the very big commit that may lead to git log issues and merge conflicts, but it's a major step forward: * Server can be faster at startup because imports() are async and we can easily lazy import big modules * Angular doesn't seem to support ES import (with .js extension), so we had to correctly organize peertube into a monorepo: * Use yarn workspace feature * Use typescript reference projects for dependencies * Shared projects have been moved into "packages", each one is now a node module (with a dedicated package.json/tsconfig.json) * server/tools have been moved into apps/ and is now a dedicated app bundled and published on NPM so users don't have to build peertube cli tools manually * server/tests have been moved into packages/ so we don't compile them every time we want to run the server * Use isolatedModule option: * Had to move from const enum to const (https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums) * Had to explictely specify "type" imports when used in decorators * Prefer tsx (that uses esbuild under the hood) instead of ts-node to load typescript files (tests with mocha or scripts): * To reduce test complexity as esbuild doesn't support decorator metadata, we only test server files that do not import server models * We still build tests files into js files for a faster CI * Remove unmaintained peertube CLI import script * Removed some barrels to speed up execution (less imports)
108 lines
3 KiB
TypeScript
108 lines
3 KiB
TypeScript
import { Component, OnInit } from '@angular/core'
|
|
import { ServerService } from '@app/core'
|
|
import { formatICU } from '@app/helpers'
|
|
import { ServerConfig } from '@peertube/peertube-models'
|
|
|
|
@Component({
|
|
selector: 'my-instance-features-table',
|
|
templateUrl: './instance-features-table.component.html',
|
|
styleUrls: [ './instance-features-table.component.scss' ]
|
|
})
|
|
export class InstanceFeaturesTableComponent implements OnInit {
|
|
quotaHelpIndication = ''
|
|
serverConfig: ServerConfig
|
|
|
|
constructor (
|
|
private serverService: ServerService
|
|
) { }
|
|
|
|
get initialUserVideoQuota () {
|
|
return this.serverConfig.user.videoQuota
|
|
}
|
|
|
|
get dailyUserVideoQuota () {
|
|
return Math.min(this.initialUserVideoQuota, this.serverConfig.user.videoQuotaDaily)
|
|
}
|
|
|
|
get maxInstanceLives () {
|
|
const value = this.serverConfig.live.maxInstanceLives
|
|
if (value === -1) return $localize`Unlimited`
|
|
|
|
return value
|
|
}
|
|
|
|
get maxUserLives () {
|
|
const value = this.serverConfig.live.maxUserLives
|
|
if (value === -1) return $localize`Unlimited`
|
|
|
|
return value
|
|
}
|
|
|
|
ngOnInit () {
|
|
this.serverService.getConfig()
|
|
.subscribe(config => {
|
|
this.serverConfig = config
|
|
this.buildQuotaHelpIndication()
|
|
})
|
|
}
|
|
|
|
buildNSFWLabel () {
|
|
const policy = this.serverConfig.instance.defaultNSFWPolicy
|
|
|
|
if (policy === 'do_not_list') return $localize`Hidden`
|
|
if (policy === 'blur') return $localize`Blurred with confirmation request`
|
|
if (policy === 'display') return $localize`Displayed`
|
|
}
|
|
|
|
buildRegistrationLabel () {
|
|
const config = this.serverConfig.signup
|
|
|
|
if (config.allowed !== true) return $localize`Disabled`
|
|
if (config.requiresApproval === true) return $localize`Requires approval by moderators`
|
|
|
|
return $localize`Enabled`
|
|
}
|
|
|
|
getServerVersionAndCommit () {
|
|
return this.serverService.getServerVersionAndCommit()
|
|
}
|
|
|
|
private getApproximateTime (seconds: number) {
|
|
const hours = Math.floor(seconds / 3600)
|
|
|
|
if (hours !== 0) {
|
|
return formatICU(
|
|
$localize`~ {hours, plural, =1 {1 hour} other {{hours} hours}}`,
|
|
{ hours }
|
|
)
|
|
}
|
|
|
|
const minutes = Math.floor(seconds % 3600 / 60)
|
|
|
|
return formatICU(
|
|
$localize`~ {minutes, plural, =1 {1 minute} other {{minutes} minutes}}`,
|
|
{ minutes }
|
|
)
|
|
}
|
|
|
|
private buildQuotaHelpIndication () {
|
|
if (this.initialUserVideoQuota === -1) return
|
|
|
|
const initialUserVideoQuotaBit = this.initialUserVideoQuota * 8
|
|
|
|
// 1080p: ~ 6Mbps
|
|
// 720p: ~ 4Mbps
|
|
// 360p: ~ 1.5Mbps
|
|
const fullHdSeconds = initialUserVideoQuotaBit / (6 * 1000 * 1000)
|
|
const hdSeconds = initialUserVideoQuotaBit / (4 * 1000 * 1000)
|
|
const normalSeconds = initialUserVideoQuotaBit / (1.5 * 1000 * 1000)
|
|
|
|
const lines = [
|
|
$localize`${this.getApproximateTime(fullHdSeconds)} of full HD videos`,
|
|
$localize`${this.getApproximateTime(hdSeconds)} of HD videos`,
|
|
$localize`${this.getApproximateTime(normalSeconds)} of average quality videos`
|
|
]
|
|
|
|
this.quotaHelpIndication = lines.join('<br />')
|
|
}
|
|
}
|