diff options
author | Chocobozzz <me@florianbigard.com> | 2022-09-28 13:59:23 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2022-09-28 14:04:06 +0200 |
commit | f67ac646a2c081e02b28a7ab1dc856db6ee20e2f (patch) | |
tree | 4bd19f2eb58d835aac0f58c44941197a402e5cab | |
parent | b0d6a800f84ac16fe541b1f098defe862d09069a (diff) | |
download | PeerTube-f67ac646a2c081e02b28a7ab1dc856db6ee20e2f.tar.gz PeerTube-f67ac646a2c081e02b28a7ab1dc856db6ee20e2f.tar.zst PeerTube-f67ac646a2c081e02b28a7ab1dc856db6ee20e2f.zip |
Put video quota info in its own component
12 files changed, 93 insertions, 54 deletions
diff --git a/client/src/app/+admin/admin.module.ts b/client/src/app/+admin/admin.module.ts index 366e29883..f01967ea6 100644 --- a/client/src/app/+admin/admin.module.ts +++ b/client/src/app/+admin/admin.module.ts | |||
@@ -49,6 +49,7 @@ import { | |||
49 | PluginSearchComponent, | 49 | PluginSearchComponent, |
50 | PluginShowInstalledComponent | 50 | PluginShowInstalledComponent |
51 | } from './plugins' | 51 | } from './plugins' |
52 | import { SharedAdminModule } from './shared' | ||
52 | import { JobService, LogsComponent, LogsService } from './system' | 53 | import { JobService, LogsComponent, LogsService } from './system' |
53 | import { DebugComponent, DebugService } from './system/debug' | 54 | import { DebugComponent, DebugService } from './system/debug' |
54 | import { JobsComponent } from './system/jobs/jobs.component' | 55 | import { JobsComponent } from './system/jobs/jobs.component' |
@@ -69,6 +70,7 @@ import { JobsComponent } from './system/jobs/jobs.component' | |||
69 | SharedVideoMiniatureModule, | 70 | SharedVideoMiniatureModule, |
70 | SharedTablesModule, | 71 | SharedTablesModule, |
71 | SharedUsersModule, | 72 | SharedUsersModule, |
73 | SharedAdminModule, | ||
72 | 74 | ||
73 | TableModule, | 75 | TableModule, |
74 | ChartModule | 76 | ChartModule |
diff --git a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html index 728185195..43f1438e0 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html +++ b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html | |||
@@ -218,10 +218,7 @@ | |||
218 | [clearable]="false" | 218 | [clearable]="false" |
219 | ></my-select-custom-value> | 219 | ></my-select-custom-value> |
220 | 220 | ||
221 | <div i18n class="transcoding-information" *ngIf="isTranscodingInformationDisplayed()"> | 221 | <my-user-real-quota-info [videoQuota]="getUserVideoQuota()"></my-user-real-quota-info> |
222 | Transcoding is enabled. The video quota only takes into account <strong>original</strong> video size. <br /> | ||
223 | At most, a user could upload ~ {{ computeQuotaWithTranscoding() | bytes: 0 }}. | ||
224 | </div> | ||
225 | 222 | ||
226 | <div *ngIf="formErrors.user.videoQuota" class="form-error">{{ formErrors.user.videoQuota }}</div> | 223 | <div *ngIf="formErrors.user.videoQuota" class="form-error">{{ formErrors.user.videoQuota }}</div> |
227 | </div> | 224 | </div> |
diff --git a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts index dc7802b2c..f7de4c7de 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts +++ b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts | |||
@@ -60,6 +60,10 @@ export class EditBasicConfigurationComponent implements OnInit, OnChanges { | |||
60 | return !!enabled.find((e: string) => e === algorithm) | 60 | return !!enabled.find((e: string) => e === algorithm) |
61 | } | 61 | } |
62 | 62 | ||
63 | getUserVideoQuota () { | ||
64 | return this.form.value['user']['videoQuota'] | ||
65 | } | ||
66 | |||
63 | isSignupEnabled () { | 67 | isSignupEnabled () { |
64 | return this.form.value['signup']['enabled'] === true | 68 | return this.form.value['signup']['enabled'] === true |
65 | } | 69 | } |
@@ -92,28 +96,6 @@ export class EditBasicConfigurationComponent implements OnInit, OnChanges { | |||
92 | return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true | 96 | return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true |
93 | } | 97 | } |
94 | 98 | ||
95 | computeQuotaWithTranscoding () { | ||
96 | const transcodingConfig = this.serverConfig.transcoding | ||
97 | |||
98 | const resolutions = transcodingConfig.enabledResolutions | ||
99 | const higherResolution = VideoResolution.H_4K | ||
100 | let multiplier = 0 | ||
101 | |||
102 | for (const resolution of resolutions) { | ||
103 | multiplier += resolution / higherResolution | ||
104 | } | ||
105 | |||
106 | if (transcodingConfig.hls.enabled) multiplier *= 2 | ||
107 | |||
108 | return multiplier * parseInt(this.form.value['user']['videoQuota'], 10) | ||
109 | } | ||
110 | |||
111 | isTranscodingInformationDisplayed () { | ||
112 | const formVideoQuota = parseInt(this.form.value['user']['videoQuota'], 10) | ||
113 | return this.serverConfig.transcoding.enabledResolutions.length !== 0 && | ||
114 | formVideoQuota > 0 | ||
115 | } | ||
116 | |||
117 | buildLandingPageOptions () { | 99 | buildLandingPageOptions () { |
118 | this.defaultLandingPageOptions = this.menuService.buildCommonLinks(this.serverConfig) | 100 | this.defaultLandingPageOptions = this.menuService.buildCommonLinks(this.serverConfig) |
119 | .links | 101 | .links |
diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.scss b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.scss index dda5d0b5e..764e626ec 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.scss +++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.scss | |||
@@ -150,3 +150,9 @@ ngb-tabset:not(.previews) ::ng-deep { | |||
150 | padding: 0 .3em; | 150 | padding: 0 .3em; |
151 | } | 151 | } |
152 | } | 152 | } |
153 | |||
154 | my-user-real-quota-info { | ||
155 | display: block; | ||
156 | margin-top: 5px; | ||
157 | font-size: 11px; | ||
158 | } | ||
diff --git a/client/src/app/+admin/overview/users/user-edit/user-edit.component.html b/client/src/app/+admin/overview/users/user-edit/user-edit.component.html index e484ab8b0..da5879a36 100644 --- a/client/src/app/+admin/overview/users/user-edit/user-edit.component.html +++ b/client/src/app/+admin/overview/users/user-edit/user-edit.component.html | |||
@@ -152,10 +152,7 @@ | |||
152 | [clearable]="false" | 152 | [clearable]="false" |
153 | ></my-select-custom-value> | 153 | ></my-select-custom-value> |
154 | 154 | ||
155 | <div i18n class="transcoding-information" *ngIf="isTranscodingInformationDisplayed()"> | 155 | <my-user-real-quota-info [videoQuota]="getUserVideoQuota()"></my-user-real-quota-info> |
156 | Transcoding is enabled. The video quota only takes into account <strong>original</strong> video size. <br /> | ||
157 | At most, this user could upload ~ {{ computeQuotaWithTranscoding() | bytes: 0 }}. | ||
158 | </div> | ||
159 | 156 | ||
160 | <div *ngIf="formErrors.videoQuota" class="form-error"> | 157 | <div *ngIf="formErrors.videoQuota" class="form-error"> |
161 | {{ formErrors.videoQuota }} | 158 | {{ formErrors.videoQuota }} |
diff --git a/client/src/app/+admin/overview/users/user-edit/user-edit.component.scss b/client/src/app/+admin/overview/users/user-edit/user-edit.component.scss index 254286ae3..68fa1215f 100644 --- a/client/src/app/+admin/overview/users/user-edit/user-edit.component.scss +++ b/client/src/app/+admin/overview/users/user-edit/user-edit.component.scss | |||
@@ -41,7 +41,8 @@ button { | |||
41 | margin-top: 10px; | 41 | margin-top: 10px; |
42 | } | 42 | } |
43 | 43 | ||
44 | .transcoding-information { | 44 | my-user-real-quota-info { |
45 | display: block; | ||
45 | margin-top: 5px; | 46 | margin-top: 5px; |
46 | font-size: 11px; | 47 | font-size: 11px; |
47 | } | 48 | } |
diff --git a/client/src/app/+admin/overview/users/user-edit/user-edit.ts b/client/src/app/+admin/overview/users/user-edit/user-edit.ts index 395d07423..0ba517edb 100644 --- a/client/src/app/+admin/overview/users/user-edit/user-edit.ts +++ b/client/src/app/+admin/overview/users/user-edit/user-edit.ts | |||
@@ -60,33 +60,14 @@ export abstract class UserEdit extends FormReactive implements OnInit { | |||
60 | ] | 60 | ] |
61 | } | 61 | } |
62 | 62 | ||
63 | isTranscodingInformationDisplayed () { | ||
64 | const formVideoQuota = parseInt(this.form.value['videoQuota'], 10) | ||
65 | |||
66 | return this.serverConfig.transcoding.enabledResolutions.length !== 0 && | ||
67 | formVideoQuota > 0 | ||
68 | } | ||
69 | |||
70 | computeQuotaWithTranscoding () { | ||
71 | const transcodingConfig = this.serverConfig.transcoding | ||
72 | |||
73 | const resolutions = transcodingConfig.enabledResolutions | ||
74 | const higherResolution = VideoResolution.H_4K | ||
75 | let multiplier = 0 | ||
76 | |||
77 | for (const resolution of resolutions) { | ||
78 | multiplier += resolution / higherResolution | ||
79 | } | ||
80 | |||
81 | if (transcodingConfig.hls.enabled) multiplier *= 2 | ||
82 | |||
83 | return multiplier * parseInt(this.form.value['videoQuota'], 10) | ||
84 | } | ||
85 | |||
86 | resetPassword () { | 63 | resetPassword () { |
87 | return | 64 | return |
88 | } | 65 | } |
89 | 66 | ||
67 | getUserVideoQuota () { | ||
68 | return this.form.value['videoQuota'] | ||
69 | } | ||
70 | |||
90 | protected buildAdminFlags (formValue: any) { | 71 | protected buildAdminFlags (formValue: any) { |
91 | return formValue.byPassAutoBlock ? UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE | 72 | return formValue.byPassAutoBlock ? UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE |
92 | } | 73 | } |
diff --git a/client/src/app/+admin/shared/index.ts b/client/src/app/+admin/shared/index.ts new file mode 100644 index 000000000..9e3834aae --- /dev/null +++ b/client/src/app/+admin/shared/index.ts | |||
@@ -0,0 +1,3 @@ | |||
1 | export * from './user-real-quota-info.component' | ||
2 | |||
3 | export * from './shared-admin.module' | ||
diff --git a/client/src/app/+admin/shared/shared-admin.module.ts b/client/src/app/+admin/shared/shared-admin.module.ts new file mode 100644 index 000000000..bef7d54ef --- /dev/null +++ b/client/src/app/+admin/shared/shared-admin.module.ts | |||
@@ -0,0 +1,20 @@ | |||
1 | import { NgModule } from '@angular/core' | ||
2 | import { SharedMainModule } from '../../shared/shared-main/shared-main.module' | ||
3 | import { UserRealQuotaInfoComponent } from './user-real-quota-info.component' | ||
4 | |||
5 | @NgModule({ | ||
6 | imports: [ | ||
7 | SharedMainModule | ||
8 | ], | ||
9 | |||
10 | declarations: [ | ||
11 | UserRealQuotaInfoComponent | ||
12 | ], | ||
13 | |||
14 | exports: [ | ||
15 | UserRealQuotaInfoComponent | ||
16 | ], | ||
17 | |||
18 | providers: [] | ||
19 | }) | ||
20 | export class SharedAdminModule { } | ||
diff --git a/client/src/app/+admin/shared/user-real-quota-info.component.html b/client/src/app/+admin/shared/user-real-quota-info.component.html new file mode 100644 index 000000000..b975ab17f --- /dev/null +++ b/client/src/app/+admin/shared/user-real-quota-info.component.html | |||
@@ -0,0 +1,4 @@ | |||
1 | <div i18n class="transcoding-information" *ngIf="isTranscodingInformationDisplayed()"> | ||
2 | The video quota only takes into account <strong>original</strong> video size. <br /> | ||
3 | Since transcoding is enabled, videos size can be at most ~ {{ computeQuotaWithTranscoding() | bytes: 0 }}. | ||
4 | </div> | ||
diff --git a/client/src/app/+admin/shared/user-real-quota-info.component.scss b/client/src/app/+admin/shared/user-real-quota-info.component.scss new file mode 100644 index 000000000..40083bed3 --- /dev/null +++ b/client/src/app/+admin/shared/user-real-quota-info.component.scss | |||
@@ -0,0 +1,2 @@ | |||
1 | @use '_variables' as *; | ||
2 | @use '_mixins' as *; | ||
diff --git a/client/src/app/+admin/shared/user-real-quota-info.component.ts b/client/src/app/+admin/shared/user-real-quota-info.component.ts new file mode 100644 index 000000000..069eeba12 --- /dev/null +++ b/client/src/app/+admin/shared/user-real-quota-info.component.ts | |||
@@ -0,0 +1,44 @@ | |||
1 | import { Component, Input, OnInit } from '@angular/core' | ||
2 | import { ServerService } from '@app/core' | ||
3 | import { HTMLServerConfig, VideoResolution } from '@shared/models/index' | ||
4 | |||
5 | @Component({ | ||
6 | selector: 'my-user-real-quota-info', | ||
7 | templateUrl: './user-real-quota-info.component.html', | ||
8 | styleUrls: [ './user-real-quota-info.component.scss' ] | ||
9 | }) | ||
10 | export class UserRealQuotaInfoComponent implements OnInit { | ||
11 | @Input() videoQuota: number | string | ||
12 | |||
13 | private serverConfig: HTMLServerConfig | ||
14 | |||
15 | constructor (private server: ServerService) { } | ||
16 | |||
17 | ngOnInit () { | ||
18 | this.serverConfig = this.server.getHTMLConfig() | ||
19 | } | ||
20 | |||
21 | isTranscodingInformationDisplayed () { | ||
22 | return this.serverConfig.transcoding.enabledResolutions.length !== 0 && this.getQuotaAsNumber() > 0 | ||
23 | } | ||
24 | |||
25 | computeQuotaWithTranscoding () { | ||
26 | const transcodingConfig = this.serverConfig.transcoding | ||
27 | |||
28 | const resolutions = transcodingConfig.enabledResolutions | ||
29 | const higherResolution = VideoResolution.H_4K | ||
30 | let multiplier = 0 | ||
31 | |||
32 | for (const resolution of resolutions) { | ||
33 | multiplier += resolution / higherResolution | ||
34 | } | ||
35 | |||
36 | if (transcodingConfig.hls.enabled) multiplier *= 2 | ||
37 | |||
38 | return multiplier * this.getQuotaAsNumber() | ||
39 | } | ||
40 | |||
41 | private getQuotaAsNumber () { | ||
42 | return parseInt(this.videoQuota + '', 10) | ||
43 | } | ||
44 | } | ||