]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-library/+my-video-channels/my-video-channel-create.component.ts
emit more specific status codes on video upload (#3423)
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-library / +my-video-channels / my-video-channel-create.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { Router } from '@angular/router'
3 import { AuthService, Notifier } from '@app/core'
4 import {
5 VIDEO_CHANNEL_DESCRIPTION_VALIDATOR,
6 VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
7 VIDEO_CHANNEL_NAME_VALIDATOR,
8 VIDEO_CHANNEL_SUPPORT_VALIDATOR
9 } from '@app/shared/form-validators/video-channel-validators'
10 import { FormValidatorService } from '@app/shared/shared-forms'
11 import { VideoChannelService } from '@app/shared/shared-main'
12 import { VideoChannelCreate } from '@shared/models'
13 import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
14 import { MyVideoChannelEdit } from './my-video-channel-edit'
15
16 @Component({
17 templateUrl: './my-video-channel-edit.component.html',
18 styleUrls: [ './my-video-channel-edit.component.scss' ]
19 })
20 export class MyVideoChannelCreateComponent extends MyVideoChannelEdit implements OnInit {
21 error: string
22
23 constructor (
24 protected formValidatorService: FormValidatorService,
25 private authService: AuthService,
26 private notifier: Notifier,
27 private router: Router,
28 private videoChannelService: VideoChannelService
29 ) {
30 super()
31 }
32
33 ngOnInit () {
34 this.buildForm({
35 name: VIDEO_CHANNEL_NAME_VALIDATOR,
36 'display-name': VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
37 description: VIDEO_CHANNEL_DESCRIPTION_VALIDATOR,
38 support: VIDEO_CHANNEL_SUPPORT_VALIDATOR
39 })
40 }
41
42 formValidated () {
43 this.error = undefined
44
45 const body = this.form.value
46 const videoChannelCreate: VideoChannelCreate = {
47 name: body.name,
48 displayName: body['display-name'],
49 description: body.description || null,
50 support: body.support || null
51 }
52
53 this.videoChannelService.createVideoChannel(videoChannelCreate).subscribe(
54 () => {
55 this.authService.refreshUserInformation()
56
57 this.notifier.success($localize`Video channel ${videoChannelCreate.displayName} created.`)
58 this.router.navigate([ '/my-library', 'video-channels' ])
59 },
60
61 err => {
62 if (err.status === HttpStatusCode.CONFLICT_409) {
63 this.error = $localize`This name already exists on this instance.`
64 return
65 }
66
67 this.error = err.message
68 }
69 )
70 }
71
72 isCreation () {
73 return true
74 }
75
76 getFormButtonTitle () {
77 return $localize`Create`
78 }
79 }