Take in account transcoding for video quota
authorChocobozzz <florian.bigard@gmail.com>
Thu, 19 Oct 2017 15:33:32 +0000 (17:33 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Thu, 19 Oct 2017 15:35:41 +0000 (17:35 +0200)
client/src/app/+admin/users/user-edit/user-add.component.ts
client/src/app/+admin/users/user-edit/user-edit.component.html
client/src/app/+admin/users/user-edit/user-edit.component.scss [new file with mode: 0644]
client/src/app/+admin/users/user-edit/user-edit.ts
client/src/app/+admin/users/user-edit/user-update.component.ts
client/src/app/core/server/server.service.ts
server/controllers/api/config.ts
shared/models/server-config.model.ts

index 5dc069104d6b1c102569113308561cd13c97886b..6d8151b42b1d9a6adeb5617408d58d4093d6a0c4 100644 (file)
@@ -11,12 +11,14 @@ import {
   USER_PASSWORD,
   USER_VIDEO_QUOTA
 } from '../../../shared'
+import { ServerService } from '../../../core'
 import { UserCreate } from '../../../../../../shared'
 import { UserEdit } from './user-edit'
 
 @Component({
   selector: 'my-user-add',
-  templateUrl: './user-edit.component.html'
+  templateUrl: './user-edit.component.html',
+  styleUrls: [ './user-edit.component.scss' ]
 })
 export class UserAddComponent extends UserEdit implements OnInit {
   error: string
@@ -36,6 +38,7 @@ export class UserAddComponent extends UserEdit implements OnInit {
   }
 
   constructor (
+    protected serverService: ServerService,
     private formBuilder: FormBuilder,
     private router: Router,
     private notificationsService: NotificationsService,
index 0e23cb7310dc70b9f40234539721f3e03516672d..6988071ced09354525bf3a24fcdd029f7bf06e48 100644 (file)
             {{ videoQuotaOption.label }}
           </option>
         </select>
+
+        <div class="transcoding-information" *ngIf="isTranscodingInformationDisplayed()">
+          Transcoding is enabled on server. The video quota only take in account <strong>original</strong> video. <br />
+          In maximum, this user could use ~ {{ computeQuotaWithTranscoding() | bytes }}.
+        </div>
       </div>
 
       <input type="submit" value="{{ getFormButtonTitle() }}" class="btn btn-default" [disabled]="!form.valid">
diff --git a/client/src/app/+admin/users/user-edit/user-edit.component.scss b/client/src/app/+admin/users/user-edit/user-edit.component.scss
new file mode 100644 (file)
index 0000000..401caa0
--- /dev/null
@@ -0,0 +1,4 @@
+.transcoding-information {
+  margin-top: 5px;
+  font-size: 11px;
+}
index 657c0f1c022482d83ca719da4702c7a959ddbc59..76497c9b652894a36e74cfcadd579f27b9febe8b 100644 (file)
@@ -1,17 +1,39 @@
+import { ServerService } from '../../../core'
 import { FormReactive } from '../../../shared'
+import { VideoResolution } from '../../../../../../shared/models/videos/video-resolution.enum'
 
 export abstract class UserEdit extends FormReactive {
   videoQuotaOptions = [
     { value: -1, label: 'Unlimited' },
     { value: 0, label: '0'},
     { value: 100 * 1024 * 1024, label: '100MB' },
-    { value: 5 * 1024 * 1024, label: '500MB' },
+    { value: 500 * 1024 * 1024, label: '500MB' },
     { value: 1024 * 1024 * 1024, label: '1GB' },
     { value: 5 * 1024 * 1024 * 1024, label: '5GB' },
     { value: 20 * 1024 * 1024 * 1024, label: '20GB' },
     { value: 50 * 1024 * 1024 * 1024, label: '50GB' }
   ]
 
+  protected abstract serverService: ServerService
   abstract isCreation (): boolean
   abstract getFormButtonTitle (): string
+
+  isTranscodingInformationDisplayed () {
+    const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
+
+    return this.serverService.getConfig().transcoding.enabledResolutions.length !== 0 &&
+           formVideoQuota > 0
+  }
+
+  computeQuotaWithTranscoding () {
+    const resolutions = this.serverService.getConfig().transcoding.enabledResolutions
+    const higherResolution = VideoResolution.H_1080P
+    let multiplier = 0
+
+    for (const resolution of resolutions) {
+      multiplier += resolution / higherResolution
+    }
+
+    return multiplier * parseInt(this.form.value['videoQuota'], 10)
+  }
 }
index 0966981c06ce7deb766e3762fa890c4a5ceb0817..bd901e655ae2a8d17c4d7e6bca8b8d2b082f8de0 100644 (file)
@@ -7,13 +7,15 @@ import { NotificationsService } from 'angular2-notifications'
 
 import { UserService } from '../shared'
 import { USER_EMAIL, USER_VIDEO_QUOTA } from '../../../shared'
+import { ServerService } from '../../../core'
 import { UserUpdate } from '../../../../../../shared/models/users/user-update.model'
 import { User } from '../../../shared/users/user.model'
 import { UserEdit } from './user-edit'
 
 @Component({
   selector: 'my-user-update',
-  templateUrl: './user-edit.component.html'
+  templateUrl: './user-edit.component.html',
+  styleUrls: [ './user-edit.component.scss' ]
 })
 export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy {
   error: string
@@ -33,10 +35,11 @@ export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy {
   private paramsSub: Subscription
 
   constructor (
-    private formBuilder: FormBuilder,
+    protected serverService: ServerService,
     private route: ActivatedRoute,
     private router: Router,
     private notificationsService: NotificationsService,
+    private formBuilder: FormBuilder,
     private userService: UserService
   ) {
     super()
index f24df5a89cd670d5d4aaae8bdf17706f1149ec8e..ae507afce3949be6076639fe77fb5afb20df722e 100644 (file)
@@ -11,6 +11,9 @@ export class ServerService {
   private config: ServerConfig = {
     signup: {
       allowed: false
+    },
+    transcoding: {
+      enabledResolutions: []
     }
   }
   private videoCategories: Array<{ id: number, label: string }> = []
index f02a2bc58efb2c71a677d2fb07fc1a238f98792e..c9a051bdc1839f19bd019532e43513ca1921af31 100644 (file)
@@ -1,21 +1,29 @@
 import * as express from 'express'
 
 import { isSignupAllowed } from '../../helpers'
+import { CONFIG } from '../../initializers'
 import { ServerConfig } from '../../../shared'
 
 const configRouter = express.Router()
 
 configRouter.get('/', getConfig)
 
-// Get the client credentials for the PeerTube front end
 function getConfig (req: express.Request, res: express.Response, next: express.NextFunction) {
 
   isSignupAllowed().then(allowed => {
+    const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS)
+                                     .filter(key => CONFIG.TRANSCODING.RESOLUTIONS[key] === true)
+                                     .map(r => parseInt(r, 10))
+
     const json: ServerConfig = {
       signup: {
         allowed
+      },
+      transcoding: {
+        enabledResolutions
       }
     }
+
     res.json(json)
   })
 }
index aab842905ffc79428f0a012997bfcb74024a6020..8de808e60b2d8651a124d0f518a15525f3698555 100644 (file)
@@ -2,4 +2,7 @@ export interface ServerConfig {
   signup: {
     allowed: boolean
   }
+  transcoding: {
+    enabledResolutions: number[]
+  }
 }