Relax on tags (accept any characters and not required anymore)
This commit is contained in:
parent
6e07c3de88
commit
e54163c2d5
|
@ -24,8 +24,8 @@ export const VIDEO_DESCRIPTION = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const VIDEO_TAGS = {
|
export const VIDEO_TAGS = {
|
||||||
VALIDATORS: [ Validators.pattern('^[a-zA-Z0-9]{0,10}$') ],
|
VALIDATORS: [ Validators.maxLength(10) ],
|
||||||
MESSAGES: {
|
MESSAGES: {
|
||||||
'pattern': 'A tag should be between 2 and 10 alphanumeric characters long.'
|
'maxlength': 'A tag should be less than 10 characters long.'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -105,10 +105,6 @@ export class VideoAddComponent extends FormReactive implements OnInit {
|
||||||
checkForm() {
|
checkForm() {
|
||||||
this.forceCheck();
|
this.forceCheck();
|
||||||
|
|
||||||
if (this.tags.length === 0) {
|
|
||||||
this.tagsError = 'You have 0 tags';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.filename === null) {
|
if (this.filename === null) {
|
||||||
this.fileError = 'You did not add a file.';
|
this.fileError = 'You did not add a file.';
|
||||||
}
|
}
|
||||||
|
@ -121,25 +117,9 @@ export class VideoAddComponent extends FormReactive implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
onTagKeyPress(event: KeyboardEvent) {
|
onTagKeyPress(event: KeyboardEvent) {
|
||||||
const currentTag = this.form.value['currentTag'];
|
|
||||||
|
|
||||||
// Enter press
|
// Enter press
|
||||||
if (event.keyCode === 13) {
|
if (event.keyCode === 13) {
|
||||||
// Check if the tag is valid and does not already exist
|
this.addTagIfPossible();
|
||||||
if (
|
|
||||||
currentTag.length >= 2 &&
|
|
||||||
this.form.controls['currentTag'].valid &&
|
|
||||||
this.tags.indexOf(currentTag) === -1
|
|
||||||
) {
|
|
||||||
this.tags.push(currentTag);
|
|
||||||
this.form.patchValue({ currentTag: '' });
|
|
||||||
|
|
||||||
if (this.tags.length >= 3) {
|
|
||||||
this.form.get('currentTag').disable();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.tagsError = '';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,6 +133,9 @@ export class VideoAddComponent extends FormReactive implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
upload() {
|
upload() {
|
||||||
|
// Maybe the user forgot to press "enter" when he filled the field
|
||||||
|
this.addTagIfPossible();
|
||||||
|
|
||||||
if (this.checkForm() === false) {
|
if (this.checkForm() === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -199,4 +182,25 @@ export class VideoAddComponent extends FormReactive implements OnInit {
|
||||||
|
|
||||||
this.uploader.uploadAll();
|
this.uploader.uploadAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private addTagIfPossible() {
|
||||||
|
const currentTag = this.form.value['currentTag'];
|
||||||
|
if (currentTag === undefined) return;
|
||||||
|
|
||||||
|
// Check if the tag is valid and does not already exist
|
||||||
|
if (
|
||||||
|
currentTag.length >= 2 &&
|
||||||
|
this.form.controls['currentTag'].valid &&
|
||||||
|
this.tags.indexOf(currentTag) === -1
|
||||||
|
) {
|
||||||
|
this.tags.push(currentTag);
|
||||||
|
this.form.patchValue({ currentTag: '' });
|
||||||
|
|
||||||
|
if (this.tags.length >= 3) {
|
||||||
|
this.form.get('currentTag').disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.tagsError = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
position: relative;
|
position: relative;
|
||||||
min-width: 220px;
|
min-width: 220px;
|
||||||
|
height: 190px;
|
||||||
|
|
||||||
.video-miniature-thumbnail {
|
.video-miniature-thumbnail {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
|
|
@ -69,8 +69,7 @@ function isVideoTagsValid (tags) {
|
||||||
return miscValidators.isArray(tags) &&
|
return miscValidators.isArray(tags) &&
|
||||||
validator.isInt(tags.length, VIDEOS_CONSTRAINTS_FIELDS.TAGS) &&
|
validator.isInt(tags.length, VIDEOS_CONSTRAINTS_FIELDS.TAGS) &&
|
||||||
tags.every(function (tag) {
|
tags.every(function (tag) {
|
||||||
return validator.isAlphanumeric(tag) &&
|
return validator.isLength(tag, VIDEOS_CONSTRAINTS_FIELDS.TAG)
|
||||||
validator.isLength(tag, VIDEOS_CONSTRAINTS_FIELDS.TAG)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ const CONSTRAINTS_FIELDS = {
|
||||||
EXTNAME: [ '.mp4', '.ogv', '.webm' ],
|
EXTNAME: [ '.mp4', '.ogv', '.webm' ],
|
||||||
INFO_HASH: { min: 40, max: 40 }, // Length, infohash is 20 bytes length but we represent it in hexa so 20 * 2
|
INFO_HASH: { min: 40, max: 40 }, // Length, infohash is 20 bytes length but we represent it in hexa so 20 * 2
|
||||||
DURATION: { min: 1, max: 7200 }, // Number
|
DURATION: { min: 1, max: 7200 }, // Number
|
||||||
TAGS: { min: 1, max: 3 }, // Number of total tags
|
TAGS: { min: 0, max: 3 }, // Number of total tags
|
||||||
TAG: { min: 2, max: 10 }, // Length
|
TAG: { min: 2, max: 10 }, // Length
|
||||||
THUMBNAIL: { min: 2, max: 30 },
|
THUMBNAIL: { min: 2, max: 30 },
|
||||||
THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
|
THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
|
||||||
|
|
|
@ -23,7 +23,7 @@ function videosAdd (req, res, next) {
|
||||||
req.checkBody('name', 'Should have a valid name').isVideoNameValid()
|
req.checkBody('name', 'Should have a valid name').isVideoNameValid()
|
||||||
req.checkBody('category', 'Should have a valid category').isVideoCategoryValid()
|
req.checkBody('category', 'Should have a valid category').isVideoCategoryValid()
|
||||||
req.checkBody('description', 'Should have a valid description').isVideoDescriptionValid()
|
req.checkBody('description', 'Should have a valid description').isVideoDescriptionValid()
|
||||||
req.checkBody('tags', 'Should have correct tags').isVideoTagsValid()
|
req.checkBody('tags', 'Should have correct tags').optional().isVideoTagsValid()
|
||||||
|
|
||||||
logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files })
|
logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files })
|
||||||
|
|
||||||
|
|
|
@ -251,19 +251,6 @@ describe('Test videos API validator', function () {
|
||||||
requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
|
requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with malformed tags', function (done) {
|
|
||||||
const data = {
|
|
||||||
name: 'my super name',
|
|
||||||
category: 5,
|
|
||||||
description: 'my super description',
|
|
||||||
tags: [ 'my tag' ]
|
|
||||||
}
|
|
||||||
const attach = {
|
|
||||||
'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
|
|
||||||
}
|
|
||||||
requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Should fail without an input file', function (done) {
|
it('Should fail without an input file', function (done) {
|
||||||
const data = {
|
const data = {
|
||||||
name: 'my super name',
|
name: 'my super name',
|
||||||
|
|
Loading…
Reference in New Issue