Skip to content

Commit

Permalink
Add abuse and registration requests stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobozzz committed Feb 21, 2024
1 parent fbe47a9 commit db69d94
Show file tree
Hide file tree
Showing 25 changed files with 615 additions and 204 deletions.
2 changes: 1 addition & 1 deletion client/src/app/+signup/+register/register.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h1 class="title-page-v2">
<div i18n>on {{ instanceName }}</div>
</my-signup-step-title>

<my-register-step-about [requiresApproval]="requiresApproval" [videoUploadDisabled]="videoUploadDisabled"></my-register-step-about>
<my-register-step-about [serverStats]="serverStats" [requiresApproval]="requiresApproval" [videoUploadDisabled]="videoUploadDisabled"></my-register-step-about>

<div class="step-buttons">
<a i18n class="skip-step underline-orange" routerLink="/login">
Expand Down
11 changes: 8 additions & 3 deletions client/src/app/+signup/+register/register.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { CdkStep } from '@angular/cdk/stepper'
import { Component, OnInit, ViewChild } from '@angular/core'
import { FormGroup } from '@angular/forms'
import { ActivatedRoute } from '@angular/router'
import { AuthService } from '@app/core'
import { AuthService, ServerService } from '@app/core'
import { HooksService } from '@app/core/plugins/hooks.service'
import { InstanceAboutAccordionComponent } from '@app/shared/shared-instance'
import { ServerConfig, UserRegister } from '@peertube/peertube-models'
import { ServerConfig, ServerStats, UserRegister } from '@peertube/peertube-models'
import { SignupService } from '../shared/signup.service'

@Component({
Expand Down Expand Up @@ -45,12 +45,15 @@ export class RegisterComponent implements OnInit {

signupDisabled = false

serverStats: ServerStats

private serverConfig: ServerConfig

constructor (
private route: ActivatedRoute,
private authService: AuthService,
private signupService: SignupService,
private server: ServerService,
private hooks: HooksService
) { }

Expand Down Expand Up @@ -85,8 +88,10 @@ export class RegisterComponent implements OnInit {
? $localize`:Button on the registration form to finalize the account and channel creation:Signup`
: this.defaultNextStepButtonLabel

this.hooks.runAction('action:signup.register.init', 'signup')
this.server.getServerStats()
.subscribe(stats => this.serverStats = stats)

this.hooks.runAction('action:signup.register.init', 'signup')
}

hasSameChannelAndAccountNames () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<my-instance-banner class="d-block mb-3" rounded="true"></my-instance-banner>
<my-instance-banner class="d-block mb-4" rounded="true"></my-instance-banner>

<div class="why">
<h3 i18n>Why creating an account?</h3>
Expand All @@ -18,15 +18,15 @@ <h3 i18n>Why creating an account?</h3>

<p *ngIf="requiresApproval" i18n>
Moderators of {{ instanceName }} will have to approve your registration request once you have finished to fill the form.

<ng-container *ngIf="averageResponseTime">They usually respond within {{ averageResponseTime | myDaysDurationFormatter }}.</ng-container>
</p>
</div>

<div>
<h4 i18n>Do you use Mastodon, ActivityPub or a RSS feed aggregator?</h4>

<p i18n>
You can already follow {{ instanceName }} using your favorite tool.
</p>
<p i18n>You can already follow {{ instanceName }} using your favorite tool.</p>
</div>

<div class="callout callout-orange callout-light">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, Input } from '@angular/core'
import { ServerService } from '@app/core'
import { ServerStats } from '@peertube/peertube-models'

@Component({
selector: 'my-register-step-about',
Expand All @@ -9,6 +10,7 @@ import { ServerService } from '@app/core'
export class RegisterStepAboutComponent {
@Input() requiresApproval: boolean
@Input() videoUploadDisabled: boolean
@Input() serverStats: ServerStats

constructor (private serverService: ServerService) {

Expand All @@ -17,4 +19,8 @@ export class RegisterStepAboutComponent {
get instanceName () {
return this.serverService.getHTMLConfig().instance.name
}

get averageResponseTime () {
return this.serverStats?.averageRegistrationRequestResponseTimeMs
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</div>

<div class="alert pt-alert-primary" i18n *ngIf="isInUpdateForm && getMaxLiveDuration() >= 0">
Max live duration is {{ getMaxLiveDuration() | myDurationFormatter }}.
Max live duration is {{ getMaxLiveDuration() | myTimeDurationFormatter }}.
If your live reaches this limit, it will be automatically terminated.
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

<div class="attribute attribute-duration" *ngIf="!video.isLive">
<span i18n class="attribute-label">Duration</span>
<span class="attribute-value">{{ video.duration | myDurationFormatter }}</span>
<span class="attribute-value">{{ video.duration | myTimeDurationFormatter }}</span>
</div>

<div class="attribute attribute-plugin" *ngFor="let metadata of pluginMetadata">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div *ngIf="instanceBannerUrl" class="banner" [ngClass]="{ rounded }">
<img class="rounded" [src]="instanceBannerUrl" alt="Instance banner">
<img class="rounded" [src]="instanceBannerUrl" alt="">
</div>
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Component, OnInit } from '@angular/core'
import { ServerService } from '@app/core'
import { formatICU } from '@app/helpers'
import { ServerConfig } from '@peertube/peertube-models'
import { ServerConfig, ServerStats } from '@peertube/peertube-models'
import { DaysDurationFormatterPipe } from '../shared-main'

@Component({
selector: 'my-instance-features-table',
Expand All @@ -11,6 +12,7 @@ import { ServerConfig } from '@peertube/peertube-models'
export class InstanceFeaturesTableComponent implements OnInit {
quotaHelpIndication = ''
serverConfig: ServerConfig
serverStats: ServerStats

constructor (
private serverService: ServerService
Expand Down Expand Up @@ -42,8 +44,12 @@ export class InstanceFeaturesTableComponent implements OnInit {
this.serverService.getConfig()
.subscribe(config => {
this.serverConfig = config

this.buildQuotaHelpIndication()
})

this.serverService.getServerStats()
.subscribe(stats => this.serverStats = stats)
}

buildNSFWLabel () {
Expand All @@ -58,7 +64,17 @@ export class InstanceFeaturesTableComponent implements OnInit {
const config = this.serverConfig.signup

if (config.allowed !== true) return $localize`Disabled`
if (config.requiresApproval === true) return $localize`Requires approval by moderators`

if (config.requiresApproval === true) {
const responseTimeMS = this.serverStats?.averageRegistrationRequestResponseTimeMs

if (!responseTimeMS) {
return $localize`Requires approval by moderators`
}

const responseTime = new DaysDurationFormatterPipe().transform(responseTimeMS)
return $localize`Requires approval by moderators (~ ${responseTime})`
}

return $localize`Enabled`
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Pipe, PipeTransform } from '@angular/core'

@Pipe({
name: 'myDaysDurationFormatter'
})
export class DaysDurationFormatterPipe implements PipeTransform {

transform (value: number): string {
const days = Math.floor(value / (3600 * 24 * 1000))

if (days <= 1) return $localize`1 day`

return $localize`${days} days`
}
}
3 changes: 2 additions & 1 deletion client/src/app/shared/shared-main/angular/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export * from './auto-colspan.directive'
export * from './autofocus.directive'
export * from './bytes.pipe'
export * from './days-duration-formatter.pipe'
export * from './defer-loading.directive'
export * from './duration-formatter.pipe'
export * from './from-now.pipe'
export * from './infinite-scroller.directive'
export * from './link.component'
export * from './login-link.component'
export * from './number-formatter.pipe'
export * from './peertube-template.directive'
export * from './time-duration-formatter.pipe'
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Pipe, PipeTransform } from '@angular/core'

@Pipe({
name: 'myDurationFormatter'
name: 'myTimeDurationFormatter'
})
export class DurationFormatterPipe implements PipeTransform {
export class TimeDurationFormatterPipe implements PipeTransform {

transform (value: number): string {
const hours = Math.floor(value / 3600)
Expand Down
9 changes: 6 additions & 3 deletions client/src/app/shared/shared-main/shared-main.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
AutofocusDirective,
BytesPipe,
DeferLoadingDirective,
DurationFormatterPipe,
TimeDurationFormatterPipe,
DaysDurationFormatterPipe,
FromNowPipe,
InfiniteScrollerDirective,
LinkComponent,
Expand Down Expand Up @@ -89,7 +90,8 @@ import { VideoChannelService } from './video-channel'
FromNowPipe,
NumberFormatterPipe,
BytesPipe,
DurationFormatterPipe,
TimeDurationFormatterPipe,
DaysDurationFormatterPipe,
AutofocusDirective,
DeferLoadingDirective,
AutoColspanDirective,
Expand Down Expand Up @@ -152,7 +154,8 @@ import { VideoChannelService } from './video-channel'
FromNowPipe,
BytesPipe,
NumberFormatterPipe,
DurationFormatterPipe,
TimeDurationFormatterPipe,
DaysDurationFormatterPipe,
AutofocusDirective,
DeferLoadingDirective,
AutoColspanDirective,
Expand Down
9 changes: 9 additions & 0 deletions config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,15 @@ thumbnails:
# Minimum value is 2
frames_to_analyze: 50

stats:
# Display registration requests stats (average response time, total requests...)
registration_requests:
enabled: true

# Display abuses stats (average response time, total abuses...)
abuses:
enabled: true

cache:
previews:
size: 500 # Max number of previews you want to cache
Expand Down
9 changes: 9 additions & 0 deletions config/production.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,15 @@ thumbnails:
# Minimum value is 2
frames_to_analyze: 50

stats:
# Display registration requests stats (average response time, total requests...)
registration_requests:
enabled: true

# Display abuses stats (average response time, total abuses...)
abuses:
enabled: true

###############################################################################
#
# From this point, almost all following keys can be overridden by the web interface
Expand Down
8 changes: 8 additions & 0 deletions packages/models/src/server/server-stats.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ export interface ServerStats extends ActivityPubMessagesSuccess, ActivityPubMess

activityPubMessagesProcessedPerSecond: number
totalActivityPubMessagesWaiting: number

averageRegistrationRequestResponseTimeMs: number
totalRegistrationRequestsProcessed: number
totalRegistrationRequests: number

averageAbuseResponseTimeMs: number
totalAbusesProcessed: number
totalAbuses: number
}

export interface VideosRedundancyStats {
Expand Down
Loading

0 comments on commit db69d94

Please sign in to comment.