First upload step is ok
This commit is contained in:
parent
8e7f08b5a5
commit
baeefe22ca
|
@ -1,5 +1,7 @@
|
||||||
import { Injectable } from '@angular/core'
|
|
||||||
import { HttpClient } from '@angular/common/http'
|
import { HttpClient } from '@angular/common/http'
|
||||||
|
import { Injectable } from '@angular/core'
|
||||||
|
import 'rxjs/add/operator/do'
|
||||||
|
import { ReplaySubject } from 'rxjs/ReplaySubject'
|
||||||
|
|
||||||
import { ServerConfig } from '../../../../../shared'
|
import { ServerConfig } from '../../../../../shared'
|
||||||
|
|
||||||
|
@ -8,6 +10,11 @@ export class ServerService {
|
||||||
private static BASE_CONFIG_URL = API_URL + '/api/v1/config/'
|
private static BASE_CONFIG_URL = API_URL + '/api/v1/config/'
|
||||||
private static BASE_VIDEO_URL = API_URL + '/api/v1/videos/'
|
private static BASE_VIDEO_URL = API_URL + '/api/v1/videos/'
|
||||||
|
|
||||||
|
videoPrivaciesLoaded = new ReplaySubject<boolean>(1)
|
||||||
|
videoCategoriesLoaded = new ReplaySubject<boolean>(1)
|
||||||
|
videoLicencesLoaded = new ReplaySubject<boolean>(1)
|
||||||
|
videoLanguagesLoaded = new ReplaySubject<boolean>(1)
|
||||||
|
|
||||||
private config: ServerConfig = {
|
private config: ServerConfig = {
|
||||||
signup: {
|
signup: {
|
||||||
allowed: false
|
allowed: false
|
||||||
|
@ -29,19 +36,19 @@ export class ServerService {
|
||||||
}
|
}
|
||||||
|
|
||||||
loadVideoCategories () {
|
loadVideoCategories () {
|
||||||
return this.loadVideoAttributeEnum('categories', this.videoCategories)
|
return this.loadVideoAttributeEnum('categories', this.videoCategories, this.videoCategoriesLoaded)
|
||||||
}
|
}
|
||||||
|
|
||||||
loadVideoLicences () {
|
loadVideoLicences () {
|
||||||
return this.loadVideoAttributeEnum('licences', this.videoLicences)
|
return this.loadVideoAttributeEnum('licences', this.videoLicences, this.videoLicencesLoaded)
|
||||||
}
|
}
|
||||||
|
|
||||||
loadVideoLanguages () {
|
loadVideoLanguages () {
|
||||||
return this.loadVideoAttributeEnum('languages', this.videoLanguages)
|
return this.loadVideoAttributeEnum('languages', this.videoLanguages, this.videoLanguagesLoaded)
|
||||||
}
|
}
|
||||||
|
|
||||||
loadVideoPrivacies () {
|
loadVideoPrivacies () {
|
||||||
return this.loadVideoAttributeEnum('privacies', this.videoPrivacies)
|
return this.loadVideoAttributeEnum('privacies', this.videoPrivacies, this.videoPrivaciesLoaded)
|
||||||
}
|
}
|
||||||
|
|
||||||
getConfig () {
|
getConfig () {
|
||||||
|
@ -66,17 +73,19 @@ export class ServerService {
|
||||||
|
|
||||||
private loadVideoAttributeEnum (
|
private loadVideoAttributeEnum (
|
||||||
attributeName: 'categories' | 'licences' | 'languages' | 'privacies',
|
attributeName: 'categories' | 'licences' | 'languages' | 'privacies',
|
||||||
hashToPopulate: { id: number, label: string }[]
|
hashToPopulate: { id: number, label: string }[],
|
||||||
|
notifier: ReplaySubject<boolean>
|
||||||
) {
|
) {
|
||||||
return this.http.get(ServerService.BASE_VIDEO_URL + attributeName)
|
return this.http.get(ServerService.BASE_VIDEO_URL + attributeName)
|
||||||
.subscribe(data => {
|
.do(() => notifier.next(true))
|
||||||
Object.keys(data)
|
.subscribe(data => {
|
||||||
.forEach(dataKey => {
|
Object.keys(data)
|
||||||
hashToPopulate.push({
|
.forEach(dataKey => {
|
||||||
id: parseInt(dataKey, 10),
|
hashToPopulate.push({
|
||||||
label: data[dataKey]
|
id: parseInt(dataKey, 10),
|
||||||
})
|
label: data[dataKey]
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,13 @@
|
||||||
|
|
||||||
<div *ngIf="error" class="alert alert-danger">{{ error }}</div>
|
<div *ngIf="error" class="alert alert-danger">{{ error }}</div>
|
||||||
|
|
||||||
<div class="upload-video-container">
|
<div *ngIf="!isUploadingVideo" class="upload-video-container">
|
||||||
<div class="upload-video">
|
<div class="upload-video">
|
||||||
<div class="icon icon-upload"></div>
|
<div class="icon icon-upload"></div>
|
||||||
|
|
||||||
<div class="button-file">
|
<div class="button-file">
|
||||||
<span>Select the file to upload</span>
|
<span>Select the file to upload</span>
|
||||||
<input #videofileInput type="file" name="videofile" id="videofile" (change)="fileChange($event)" />
|
<input #videofileInput type="file" name="videofile" id="videofile" (change)="fileChange()" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
@ -26,20 +26,20 @@
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<form *ngIf="isUploadingVideo" novalidate [formGroup]="form">
|
|
||||||
<my-video-edit
|
|
||||||
[form]="form" [formErrors]="formErrors"
|
|
||||||
[validationMessages]="validationMessages" [videoPrivacies]="videoPrivacies"
|
|
||||||
></my-video-edit>
|
|
||||||
|
|
||||||
<div class="submit-container">
|
|
||||||
<div class="submit-button" [ngClass]="{ disabled: !form.valid }">
|
|
||||||
<span class="icon icon-validate"></span>
|
|
||||||
<input type="button" value="Publish" (click)="upload()" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Hidden because we need to load the component -->
|
||||||
|
<form [hidden]="!isUploadingVideo" novalidate [formGroup]="form">
|
||||||
|
<my-video-edit
|
||||||
|
[form]="form" [formErrors]="formErrors"
|
||||||
|
[validationMessages]="validationMessages" [videoPrivacies]="videoPrivacies"
|
||||||
|
></my-video-edit>
|
||||||
|
|
||||||
|
<div class="submit-container">
|
||||||
|
<div class="submit-button" [ngClass]="{ disabled: !form.valid }">
|
||||||
|
<span class="icon icon-validate"></span>
|
||||||
|
<input type="button" value="Publish" (click)="upload()" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -23,12 +23,14 @@ export class VideoAddComponent extends FormReactive implements OnInit {
|
||||||
@ViewChild('videofileInput') videofileInput
|
@ViewChild('videofileInput') videofileInput
|
||||||
|
|
||||||
isUploadingVideo = false
|
isUploadingVideo = false
|
||||||
|
videoUploaded = false
|
||||||
progressPercent = 0
|
progressPercent = 0
|
||||||
|
|
||||||
error: string = null
|
error: string = null
|
||||||
form: FormGroup
|
form: FormGroup
|
||||||
formErrors: { [ id: string ]: string } = {}
|
formErrors: { [ id: string ]: string } = {}
|
||||||
validationMessages: ValidatorMessage = {}
|
validationMessages: ValidatorMessage = {}
|
||||||
|
|
||||||
userVideoChannels = []
|
userVideoChannels = []
|
||||||
videoPrivacies = []
|
videoPrivacies = []
|
||||||
firstStepPrivacy = 0
|
firstStepPrivacy = 0
|
||||||
|
@ -53,8 +55,12 @@ export class VideoAddComponent extends FormReactive implements OnInit {
|
||||||
ngOnInit () {
|
ngOnInit () {
|
||||||
this.buildForm()
|
this.buildForm()
|
||||||
|
|
||||||
this.videoPrivacies = this.serverService.getVideoPrivacies()
|
this.serverService.videoCategoriesLoaded
|
||||||
this.firstStepPrivacy = this.videoPrivacies[0].id
|
.subscribe(
|
||||||
|
() => {
|
||||||
|
this.videoPrivacies = this.serverService.getVideoPrivacies()
|
||||||
|
this.firstStepPrivacy = this.videoPrivacies[0].id
|
||||||
|
})
|
||||||
|
|
||||||
this.authService.userInformationLoaded
|
this.authService.userInformationLoaded
|
||||||
.subscribe(
|
.subscribe(
|
||||||
|
@ -71,8 +77,8 @@ export class VideoAddComponent extends FormReactive implements OnInit {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fileChange ($event) {
|
fileChange () {
|
||||||
console.log('uploading file ?')
|
this.uploadFirstStep()
|
||||||
}
|
}
|
||||||
|
|
||||||
checkForm () {
|
checkForm () {
|
||||||
|
@ -82,38 +88,26 @@ export class VideoAddComponent extends FormReactive implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadFirstStep () {
|
uploadFirstStep () {
|
||||||
const formValue: VideoCreate = this.form.value
|
|
||||||
|
|
||||||
const name = formValue.name
|
|
||||||
const privacy = formValue.privacy
|
|
||||||
const nsfw = formValue.nsfw
|
|
||||||
const category = formValue.category
|
|
||||||
const licence = formValue.licence
|
|
||||||
const language = formValue.language
|
|
||||||
const channelId = formValue.channelId
|
|
||||||
const description = formValue.description
|
|
||||||
const tags = formValue.tags
|
|
||||||
const videofile = this.videofileInput.nativeElement.files[0]
|
const videofile = this.videofileInput.nativeElement.files[0]
|
||||||
|
const name = videofile.name
|
||||||
|
const privacy = this.firstStepPrivacy.toString()
|
||||||
|
const nsfw = false
|
||||||
|
const channelId = this.firstStepChannel.toString()
|
||||||
|
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
formData.append('name', name)
|
formData.append('name', name)
|
||||||
formData.append('privacy', privacy.toString())
|
formData.append('privacy', privacy.toString())
|
||||||
formData.append('category', '' + category)
|
|
||||||
formData.append('nsfw', '' + nsfw)
|
formData.append('nsfw', '' + nsfw)
|
||||||
formData.append('licence', '' + licence)
|
|
||||||
formData.append('channelId', '' + channelId)
|
formData.append('channelId', '' + channelId)
|
||||||
formData.append('videofile', videofile)
|
formData.append('videofile', videofile)
|
||||||
|
|
||||||
// Language is optional
|
this.isUploadingVideo = true
|
||||||
if (language) {
|
this.form.patchValue({
|
||||||
formData.append('language', '' + language)
|
name,
|
||||||
}
|
privacy,
|
||||||
|
nsfw,
|
||||||
formData.append('description', description)
|
channelId
|
||||||
|
})
|
||||||
for (let i = 0; i < tags.length; i++) {
|
|
||||||
formData.append(`tags[${i}]`, tags[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
this.videoService.uploadVideo(formData).subscribe(
|
this.videoService.uploadVideo(formData).subscribe(
|
||||||
event => {
|
event => {
|
||||||
|
@ -121,10 +115,8 @@ export class VideoAddComponent extends FormReactive implements OnInit {
|
||||||
this.progressPercent = Math.round(100 * event.loaded / event.total)
|
this.progressPercent = Math.round(100 * event.loaded / event.total)
|
||||||
} else if (event instanceof HttpResponse) {
|
} else if (event instanceof HttpResponse) {
|
||||||
console.log('Video uploaded.')
|
console.log('Video uploaded.')
|
||||||
this.notificationsService.success('Success', 'Video uploaded.')
|
|
||||||
|
|
||||||
// Display all the videos once it's finished
|
this.videoUploaded = true
|
||||||
this.router.navigate([ '/videos/trending' ])
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import { FollowState } from '../../shared/models/accounts/follow.model'
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
const LAST_MIGRATION_VERSION = 115
|
const LAST_MIGRATION_VERSION = 120
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import * as Sequelize from 'sequelize'
|
import * as Sequelize from 'sequelize'
|
||||||
|
import { CONSTRAINTS_FIELDS } from '../constants'
|
||||||
import { PeerTubeDatabase } from '../database'
|
import { PeerTubeDatabase } from '../database'
|
||||||
|
|
||||||
async function up (utils: {
|
async function up (utils: {
|
||||||
|
@ -28,7 +29,7 @@ async function up (utils: {
|
||||||
|
|
||||||
{
|
{
|
||||||
const data = {
|
const data = {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.STRING(CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.max),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
defaultValue: null
|
defaultValue: null
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import { VideoPrivacy } from './video-privacy.enum'
|
import { VideoPrivacy } from './video-privacy.enum'
|
||||||
|
|
||||||
export interface VideoCreate {
|
export interface VideoCreate {
|
||||||
category: number
|
category?: number
|
||||||
licence: number
|
licence?: number
|
||||||
language: number
|
language?: number
|
||||||
description: string
|
description?: string
|
||||||
channelId: number
|
channelId: number
|
||||||
nsfw: boolean
|
nsfw: boolean
|
||||||
name: string
|
name: string
|
||||||
tags: string[]
|
tags?: string[]
|
||||||
privacy: VideoPrivacy
|
privacy: VideoPrivacy
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue