import { Router } from '@angular/router';
import { AuthService } from './core';
+import { VideoService } from './videos';
import { UserService } from './shared';
@Component({
private router: Router,
private authService: AuthService,
private userService: UserService,
+ private videoService: VideoService,
viewContainerRef: ViewContainerRef
) {}
// The service will automatically redirect to the login page if the token is not valid anymore
this.userService.checkTokenValidity();
}
+
+ this.videoService.loadVideoCategories();
}
isInAdmin() {
'maxlength': 'Video name cannot be more than 50 characters long.'
}
};
+export const VIDEO_CATEGORY = {
+ VALIDATORS: [ Validators.required ],
+ MESSAGES: {
+ 'required': 'Video category is required.'
+ }
+};
export const VIDEO_DESCRIPTION = {
VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(250) ],
MESSAGES: {
author: string;
by: string;
createdAt: Date;
+ categoryLabel: string;
description: string;
duration: string;
id: string;
constructor(hash: {
author: string,
createdAt: string,
+ categoryLabel: string,
description: string,
duration: number;
id: string,
}) {
this.author = hash.author;
this.createdAt = new Date(hash.createdAt);
+ this.categoryLabel = hash.categoryLabel;
this.description = hash.description;
this.duration = Video.createDurationString(hash.duration);
this.id = hash.id;
export class VideoService {
private static BASE_VIDEO_URL = '/api/v1/videos/';
+ videoCategories: Array<{ id: number, label: string }> = [];
+
constructor(
private authService: AuthService,
private authHttp: AuthHttp,
private restService: RestService
) {}
+ loadVideoCategories() {
+ return this.http.get(VideoService.BASE_VIDEO_URL + 'categories')
+ .map(this.restExtractor.extractDataGet)
+ .subscribe(data => {
+ Object.keys(data).forEach(categoryKey => {
+ this.videoCategories.push({
+ id: parseInt(categoryKey),
+ label: data[categoryKey]
+ });
+ });
+ });
+ }
+
getVideo(id: string): Observable<Video> {
return this.http.get(VideoService.BASE_VIDEO_URL + id)
.map(this.restExtractor.extractDataGet)
</div>
</div>
+ <div class="form-group">
+ <label for="category">Category</label>
+ <select class="form-control" id="category" formControlName="category">
+ <option></option>
+ <option *ngFor="let category of videoCategories" [value]="category.id">{{ category.label }}</option>
+ </select>
+
+ <div *ngIf="formErrors.category" class="alert alert-danger">
+ {{ formErrors.category }}
+ </div>
+ </div>
+
<div class="form-group">
<label for="tags">Tags</label> <span class="little-information">(press enter to add the tag)</span>
<input
import { NotificationsService } from 'angular2-notifications';
import { AuthService } from '../../core';
-import { FormReactive, VIDEO_NAME, VIDEO_DESCRIPTION, VIDEO_TAGS } from '../../shared';
+import {
+ FormReactive,
+ VIDEO_NAME,
+ VIDEO_CATEGORY,
+ VIDEO_DESCRIPTION,
+ VIDEO_TAGS
+} from '../../shared';
+import { VideoService } from '../shared';
@Component({
selector: 'my-videos-add',
export class VideoAddComponent extends FormReactive implements OnInit {
tags: string[] = [];
uploader: FileUploader;
+ videoCategories = [];
error: string = null;
form: FormGroup;
formErrors = {
name: '',
+ category: '',
description: '',
currentTag: ''
};
validationMessages = {
name: VIDEO_NAME.MESSAGES,
+ category: VIDEO_CATEGORY.MESSAGES,
description: VIDEO_DESCRIPTION.MESSAGES,
currentTag: VIDEO_TAGS.MESSAGES
};
private elementRef: ElementRef,
private formBuilder: FormBuilder,
private router: Router,
- private notificationsService: NotificationsService
+ private notificationsService: NotificationsService,
+ private videoService: VideoService
) {
super();
}
buildForm() {
this.form = this.formBuilder.group({
name: [ '', VIDEO_NAME.VALIDATORS ],
+ category: [ '', VIDEO_CATEGORY.VALIDATORS ],
description: [ '', VIDEO_DESCRIPTION.VALIDATORS ],
currentTag: [ '', VIDEO_TAGS.VALIDATORS ]
});
}
ngOnInit() {
+ this.videoCategories = this.videoService.videoCategories;
+
this.uploader = new FileUploader({
authToken: this.authService.getRequestHeaderValue(),
queueLimit: 1,
this.uploader.onBuildItemForm = (item, form) => {
const name = this.form.value['name'];
+ const category = this.form.value['category'];
const description = this.form.value['description'];
form.append('name', name);
+ form.append('category', category);
form.append('description', description);
for (let i = 0; i < this.tags.length; i++) {
</div>
</div>
+ <div id="video-category" class="row">
+ <div class="col-md-12">
+ <span id="category-label">Category:</span>
+ {{ video.categoryLabel }}
+ </div>
+ </div>
+
<div id="video-description" class="row">
<div class="col-md-12">
<div id="description-label">Description</div>
}
}
+ #video-category {
+ margin-top: 10px;
+
+ #category-label {
+ font-weight: bold;
+ }
+ }
+
#video-description {
- margin-top: 15px;
+ margin-top: 10px;
#description-label {
font-weight: bold;
remoteId: videoToCreateData.remoteId,
extname: videoToCreateData.extname,
infoHash: videoToCreateData.infoHash,
+ category: videoToCreateData.category,
description: videoToCreateData.description,
authorId: author.id,
duration: videoToCreateData.duration,
const options = { transaction: t }
videoInstance.set('name', videoAttributesToUpdate.name)
+ videoInstance.set('category', videoAttributesToUpdate.category)
videoInstance.set('description', videoAttributesToUpdate.description)
videoInstance.set('infoHash', videoAttributesToUpdate.infoHash)
videoInstance.set('duration', videoAttributesToUpdate.duration)
const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }])
+router.get('/categories', listVideoCategories)
+
router.get('/abuse',
oAuth.authenticate,
admin.ensureIsAdmin,
// ---------------------------------------------------------------------------
+function listVideoCategories (req, res, next) {
+ res.json(constants.VIDEO_CATEGORIES)
+}
+
function rateVideoRetryWrapper (req, res, next) {
const options = {
arguments: [ req, res ],
name: videoInfos.name,
remoteId: null,
extname: path.extname(videoFile.filename),
+ category: videoInfos.category,
description: videoInfos.description,
duration: videoFile.duration,
authorId: author.id
}
if (videoInfosToUpdate.name) videoInstance.set('name', videoInfosToUpdate.name)
+ if (videoInfosToUpdate.category) videoInstance.set('category', videoInfosToUpdate.category)
if (videoInfosToUpdate.description) videoInstance.set('description', videoInfosToUpdate.description)
videoInstance.save(options).asCallback(function (err) {
function isCommonVideoAttributesValid (video) {
return videosValidators.isVideoDateValid(video.createdAt) &&
videosValidators.isVideoDateValid(video.updatedAt) &&
+ videosValidators.isVideoCategoryValid(video.category) &&
videosValidators.isVideoDescriptionValid(video.description) &&
videosValidators.isVideoDurationValid(video.duration) &&
videosValidators.isVideoInfoHashValid(video.infoHash) &&
const videosValidators = {
isVideoAuthorValid,
isVideoDateValid,
+ isVideoCategoryValid,
isVideoDescriptionValid,
isVideoDurationValid,
isVideoInfoHashValid,
return validator.isDate(value)
}
+function isVideoCategoryValid (value) {
+ return constants.VIDEO_CATEGORIES[value] !== undefined
+}
+
function isVideoDescriptionValid (value) {
return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION)
}
// ---------------------------------------------------------------------------
-const LAST_MIGRATION_VERSION = 25
+const LAST_MIGRATION_VERSION = 30
// ---------------------------------------------------------------------------
DISLIKE: 'dislike'
}
+const VIDEO_CATEGORIES = {
+ 1: 'Music',
+ 2: 'Films',
+ 3: 'Vehicles',
+ 4: 'Art',
+ 5: 'Sports',
+ 6: 'Travels',
+ 7: 'Gaming',
+ 8: 'People',
+ 9: 'Comedy',
+ 10: 'Entertainment',
+ 11: 'News',
+ 12: 'Howto',
+ 13: 'Education',
+ 14: 'Activism',
+ 15: 'Science & Technology',
+ 16: 'Animals',
+ 17: 'Kids',
+ 18: 'Food'
+}
+
// ---------------------------------------------------------------------------
// Score a pod has when we create it as a friend
STATIC_PATHS,
THUMBNAILS_SIZE,
USER_ROLES,
+ VIDEO_CATEGORIES,
VIDEO_RATE_TYPES
}
--- /dev/null
+'use strict'
+
+const waterfall = require('async/waterfall')
+
+// utils = { transaction, queryInterface, sequelize, Sequelize }
+exports.up = function (utils, finalCallback) {
+ const q = utils.queryInterface
+ const Sequelize = utils.Sequelize
+
+ const data = {
+ type: Sequelize.INTEGER,
+ allowNull: false,
+ defaultValue: 0
+ }
+
+ waterfall([
+
+ function addCategoryColumn (callback) {
+ q.addColumn('Videos', 'category', data, { transaction: utils.transaction }).asCallback(function (err) {
+ return callback(err)
+ })
+ },
+
+ function nullOnDefault (callback) {
+ data.defaultValue = null
+
+ q.changeColumn('Videos', 'category', data, { transaction: utils.transaction }).asCallback(callback)
+ }
+ ], finalCallback)
+}
+
+exports.down = function (options, callback) {
+ throw new Error('Not implemented.')
+}
function videosAdd (req, res, next) {
req.checkBody('videofile', 'Should have a valid file').isVideoFile(req.files)
req.checkBody('name', 'Should have a valid name').isVideoNameValid()
+ req.checkBody('category', 'Should have a valid category').isVideoCategoryValid()
req.checkBody('description', 'Should have a valid description').isVideoDescriptionValid()
req.checkBody('tags', 'Should have correct tags').isVideoTagsValid()
function videosUpdate (req, res, next) {
req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4)
req.checkBody('name', 'Should have a valid name').optional().isVideoNameValid()
+ req.checkBody('category', 'Should have a valid category').optional().isVideoCategoryValid()
req.checkBody('description', 'Should have a valid description').optional().isVideoDescriptionValid()
req.checkBody('tags', 'Should have correct tags').optional().isVideoTagsValid()
isUUID: 4
}
},
+ category: {
+ type: DataTypes.INTEGER,
+ allowNull: false,
+ validate: {
+ categoryValid: function (value) {
+ const res = customVideosValidators.isVideoCategoryValid(value)
+ if (res === false) throw new Error('Video category is not valid.')
+ }
+ }
+ },
description: {
type: DataTypes.STRING,
allowNull: false,
podHost = constants.CONFIG.WEBSERVER.HOST
}
+ // Maybe our pod is not up to date and there are new categories since our version
+ let categoryLabel = constants.VIDEO_CATEGORIES[this.category]
+ if (!categoryLabel) categoryLabel = 'Misc'
+
const json = {
id: this.id,
name: this.name,
+ category: this.category,
+ categoryLabel,
description: this.description,
podHost,
isLocal: this.isOwned(),
const remoteVideo = {
name: self.name,
+ category: self.category,
description: self.description,
infoHash: self.infoHash,
remoteId: self.id,
function toUpdateRemoteJSON (callback) {
const json = {
name: this.name,
+ category: this.category,
description: this.description,
infoHash: this.infoHash,
remoteId: this.id,
},
function (next) {
const name = 'my super name for pod'
+ const category = 5
const description = 'my super description for pod'
const tags = [ 'tag' ]
const file = 'video_short2.webm'
- videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, file, next)
+ videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, file, next)
},
function (next) {
videosUtils.getVideosList(server.url, function (err, res) {
// Upload some videos on each pods
function (next) {
const name = 'my super name for pod'
+ const category = 2
const description = 'my super description for pod'
const tags = [ 'tag' ]
const file = 'video_short2.webm'
- videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, file, next)
+ videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, file, next)
},
function (next) {
videosUtils.getVideosList(server.url, function (err, res) {
it('Should fail without name', function (done) {
const data = {
+ category: 5,
description: 'my super description',
tags: [ 'tag1', 'tag2' ]
}
it('Should fail with a long name', function (done) {
const data = {
name: 'My very very very very very very very very very very very very very very very very long name',
+ category: 5,
+ description: 'my super description',
+ tags: [ 'tag1', 'tag2' ]
+ }
+ const attach = {
+ 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
+ }
+ requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
+ })
+
+ it('Should fail without a category', function (done) {
+ const data = {
+ name: 'my super name',
+ description: 'my super description',
+ tags: [ 'tag1', 'tag2' ]
+ }
+ const attach = {
+ 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
+ }
+ requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
+ })
+
+ it('Should fail with a bad category', function (done) {
+ const data = {
+ name: 'my super name',
+ category: 125,
description: 'my super description',
tags: [ 'tag1', 'tag2' ]
}
it('Should fail without description', function (done) {
const data = {
name: 'my super name',
+ category: 5,
tags: [ 'tag1', 'tag2' ]
}
const attach = {
it('Should fail with a long description', function (done) {
const data = {
name: 'my super name',
+ category: 5,
description: 'my super description which is very very very very very very very very very very very very very very' +
'very very very very very very very very very very very very very very very very very very very very very' +
'very very very very very very very very very very very very very very very long',
it('Should fail without tags', function (done) {
const data = {
name: 'my super name',
+ category: 5,
description: 'my super description'
}
const attach = {
it('Should fail with too many tags', function (done) {
const data = {
name: 'my super name',
+ category: 5,
description: 'my super description',
tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
}
it('Should fail with not enough tags', function (done) {
const data = {
name: 'my super name',
+ category: 5,
description: 'my super description',
tags: [ ]
}
it('Should fail with a tag length too low', function (done) {
const data = {
name: 'my super name',
+ category: 5,
description: 'my super description',
tags: [ 'tag1', 't' ]
}
it('Should fail with a tag length too big', function (done) {
const data = {
name: 'my super name',
+ category: 5,
description: 'my super description',
tags: [ 'mysupertagtoolong', 'tag1' ]
}
it('Should fail with malformed tags', function (done) {
const data = {
name: 'my super name',
+ category: 5,
description: 'my super description',
tags: [ 'my tag' ]
}
it('Should fail without an input file', function (done) {
const data = {
name: 'my super name',
+ category: 5,
description: 'my super description',
tags: [ 'tag1', 'tag2' ]
}
it('Should fail without an incorrect input file', function (done) {
const data = {
name: 'my super name',
+ category: 5,
description: 'my super description',
tags: [ 'tag1', 'tag2' ]
}
it('Should fail with a too big duration', function (done) {
const data = {
name: 'my super name',
+ category: 5,
description: 'my super description',
tags: [ 'tag1', 'tag2' ]
}
it('Should succeed with the correct parameters', function (done) {
const data = {
name: 'my super name',
+ category: 5,
description: 'my super description',
tags: [ 'tag1', 'tag2' ]
}
it('Should fail without a valid uuid', function (done) {
const data = {
+ category: 5,
description: 'my super description',
tags: [ 'tag1', 'tag2' ]
}
it('Should fail with an unknown id', function (done) {
const data = {
+ category: 5,
description: 'my super description',
tags: [ 'tag1', 'tag2' ]
}
it('Should fail with a long name', function (done) {
const data = {
name: 'My very very very very very very very very very very very very very very very very long name',
+ category: 5,
+ description: 'my super description',
+ tags: [ 'tag1', 'tag2' ]
+ }
+ requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
+ })
+
+ it('Should fail with a bad category', function (done) {
+ const data = {
+ name: 'my super name',
+ category: 128,
description: 'my super description',
tags: [ 'tag1', 'tag2' ]
}
it('Should fail with a long description', function (done) {
const data = {
name: 'my super name',
+ category: 5,
description: 'my super description which is very very very very very very very very very very very very very very' +
'very very very very very very very very very very very very very very very very very very very very very' +
'very very very very very very very very very very very very very very very long',
it('Should fail with too many tags', function (done) {
const data = {
name: 'my super name',
+ category: 5,
description: 'my super description',
tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
}
it('Should fail with not enough tags', function (done) {
const data = {
name: 'my super name',
+ category: 5,
description: 'my super description',
tags: [ ]
}
it('Should fail with a tag length too low', function (done) {
const data = {
name: 'my super name',
+ category: 5,
description: 'my super description',
tags: [ 'tag1', 't' ]
}
it('Should fail with a tag length too big', function (done) {
const data = {
name: 'my super name',
+ category: 5,
description: 'my super description',
tags: [ 'mysupertagtoolong', 'tag1' ]
}
it('Should fail with malformed tags', function (done) {
const data = {
name: 'my super name',
+ category: 5,
description: 'my super description',
tags: [ 'my tag' ]
}
function uploadVideo (podNumber, callback) {
const name = 'my super video'
+ const category = 5
const description = 'my super description'
const tags = [ 'tag1', 'tag2' ]
const fixture = 'video_short.webm'
const server = servers[podNumber - 1]
- return videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, fixture, callback)
+ return videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, fixture, callback)
}
function getVideos (podNumber, callback) {
series([
function (next) {
const name = 'my super name for pod 1'
+ const category = 5
const description = 'my super description for pod 1'
const tags = [ 'tag1p1', 'tag2p1' ]
const file = 'video_short1.webm'
- videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, description, tags, file, next)
+ videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, category, description, tags, file, next)
},
function (next) {
setTimeout(next, 11000)
expect(videos.length).to.equal(1)
const video = videos[0]
expect(video.name).to.equal('my super name for pod 1')
+ expect(video.category).to.equal(5)
+ expect(video.categoryLabel).to.equal('Sports')
expect(video.description).to.equal('my super description for pod 1')
expect(video.podHost).to.equal('localhost:9001')
expect(video.magnetUri).to.exist
series([
function (next) {
const name = 'my super name for pod 2'
+ const category = 4
const description = 'my super description for pod 2'
const tags = [ 'tag1p2', 'tag2p2', 'tag3p2' ]
const file = 'video_short2.webm'
- videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, description, tags, file, next)
+ videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, category, description, tags, file, next)
},
function (next) {
setTimeout(next, 11000)
expect(videos.length).to.equal(2)
const video = videos[1]
expect(video.name).to.equal('my super name for pod 2')
+ expect(video.category).to.equal(4)
+ expect(video.categoryLabel).to.equal('Art')
expect(video.description).to.equal('my super description for pod 2')
expect(video.podHost).to.equal('localhost:9002')
expect(video.magnetUri).to.exist
series([
function (next) {
const name = 'my super name for pod 3'
+ const category = 6
const description = 'my super description for pod 3'
const tags = [ 'tag1p3' ]
const file = 'video_short3.webm'
- videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next)
+ videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, category, description, tags, file, next)
},
function (next) {
const name = 'my super name for pod 3-2'
+ const category = 7
const description = 'my super description for pod 3-2'
const tags = [ 'tag2p3', 'tag3p3', 'tag4p3' ]
const file = 'video_short.webm'
- videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next)
+ videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, category, description, tags, file, next)
},
function (next) {
setTimeout(next, 22000)
}
expect(video1.name).to.equal('my super name for pod 3')
+ expect(video1.category).to.equal(6)
+ expect(video1.categoryLabel).to.equal('Travels')
expect(video1.description).to.equal('my super description for pod 3')
expect(video1.podHost).to.equal('localhost:9003')
expect(video1.magnetUri).to.exist
expect(miscsUtils.dateIsValid(video1.updatedAt)).to.be.true
expect(video2.name).to.equal('my super name for pod 3-2')
+ expect(video2.category).to.equal(7)
+ expect(video2.categoryLabel).to.equal('Gaming')
expect(video2.description).to.equal('my super description for pod 3-2')
expect(video2.podHost).to.equal('localhost:9003')
expect(video2.magnetUri).to.exist
this.timeout(15000)
const name = 'my super video updated'
+ const category = 10
const description = 'my super description updated'
const tags = [ 'tagup1', 'tagup2' ]
- videosUtils.updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, name, description, tags, function (err) {
+ videosUtils.updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, name, category, description, tags, function (err) {
if (err) throw err
setTimeout(done, 11000)
})
expect(!!videoUpdated).to.be.true
+ expect(videoUpdated.category).to.equal(10)
+ expect(videoUpdated.categoryLabel).to.equal('Entertainment')
expect(videoUpdated.description).to.equal('my super description updated')
expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true
function uploadVideo (server, callback) {
const name = 'my super video'
+ const category = 5
const description = 'my super description'
const tags = [ 'tag1', 'tag2' ]
const fixture = 'video_short.webm'
- videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, fixture, callback)
+ videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, fixture, callback)
}
function getRequestsStats (server, callback) {
], done)
})
+ it('Should list video categories', function (done) {
+ videosUtils.getVideoCategories(server.url, function (err, res) {
+ if (err) throw err
+
+ const categories = res.body
+ expect(Object.keys(categories)).to.have.length.above(10)
+
+ expect(categories[11]).to.equal('News')
+
+ done()
+ })
+ })
+
it('Should not have videos', function (done) {
videosUtils.getVideosList(server.url, function (err, res) {
if (err) throw err
this.timeout(5000)
const name = 'my super name'
const description = 'my super description'
+ const category = 2
const tags = [ 'tag1', 'tag2', 'tag3' ]
const file = 'video_short.webm'
- videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, file, done)
+ videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, file, done)
})
it('Should seed the uploaded video', function (done) {
const video = res.body.data[0]
expect(video.name).to.equal('my super name')
+ expect(video.category).to.equal(2)
+ expect(video.categoryLabel).to.equal('Films')
expect(video.description).to.equal('my super description')
expect(video.podHost).to.equal('localhost:9001')
expect(video.magnetUri).to.exist
const video = res.body
expect(video.name).to.equal('my super name')
+ expect(video.category).to.equal(2)
+ expect(video.categoryLabel).to.equal('Films')
expect(video.description).to.equal('my super description')
expect(video.podHost).to.equal('localhost:9001')
expect(video.magnetUri).to.exist
const video = res.body.data[0]
expect(video.name).to.equal('my super name')
+ expect(video.category).to.equal(2)
+ expect(video.categoryLabel).to.equal('Films')
expect(video.description).to.equal('my super description')
expect(video.podHost).to.equal('localhost:9001')
expect(video.author).to.equal('root')
const video = res.body.data[0]
expect(video.name).to.equal('my super name')
+ expect(video.category).to.equal(2)
+ expect(video.categoryLabel).to.equal('Films')
expect(video.description).to.equal('my super description')
expect(video.podHost).to.equal('localhost:9001')
expect(video.author).to.equal('root')
each(videos, function (video, callbackEach) {
const name = video + ' name'
const description = video + ' description'
+ const category = 2
const tags = [ 'tag1', 'tag2', 'tag3' ]
- videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, video, callbackEach)
+ videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, video, callbackEach)
}, done)
})
// })
// })
- it('Should search the good magnetUri video', function (done) {
+ it('Should search the right magnetUri video', function (done) {
const video = videosListBase[0]
videosUtils.searchVideoWithPagination(server.url, encodeURIComponent(video.magnetUri), 'magnetUri', 0, 15, function (err, res) {
if (err) throw err
it('Should update a video', function (done) {
const name = 'my super video updated'
+ const category = 4
const description = 'my super description updated'
const tags = [ 'tagup1', 'tagup2' ]
- videosUtils.updateVideo(server.url, server.accessToken, videoId, name, description, tags, done)
+ videosUtils.updateVideo(server.url, server.accessToken, videoId, name, category, description, tags, done)
})
it('Should have the video updated', function (done) {
const video = res.body
expect(video.name).to.equal('my super video updated')
+ expect(video.category).to.equal(4)
+ expect(video.categoryLabel).to.equal('Art')
expect(video.description).to.equal('my super description updated')
expect(video.podHost).to.equal('localhost:9001')
expect(video.author).to.equal('root')
it('Should update only the tags of a video', function (done) {
const tags = [ 'tag1', 'tag2', 'supertag' ]
- videosUtils.updateVideo(server.url, server.accessToken, videoId, null, null, tags, function (err) {
+ videosUtils.updateVideo(server.url, server.accessToken, videoId, null, null, null, tags, function (err) {
if (err) throw err
videosUtils.getVideo(server.url, videoId, function (err, res) {
const video = res.body
expect(video.name).to.equal('my super video updated')
+ expect(video.category).to.equal(4)
+ expect(video.categoryLabel).to.equal('Art')
expect(video.description).to.equal('my super description updated')
expect(video.podHost).to.equal('localhost:9001')
expect(video.author).to.equal('root')
it('Should update only the description of a video', function (done) {
const description = 'hello everybody'
- videosUtils.updateVideo(server.url, server.accessToken, videoId, null, description, null, function (err) {
+ videosUtils.updateVideo(server.url, server.accessToken, videoId, null, null, description, null, function (err) {
if (err) throw err
videosUtils.getVideo(server.url, videoId, function (err, res) {
const video = res.body
expect(video.name).to.equal('my super video updated')
+ expect(video.category).to.equal(4)
+ expect(video.categoryLabel).to.equal('Art')
expect(video.description).to.equal('hello everybody')
expect(video.podHost).to.equal('localhost:9001')
expect(video.author).to.equal('root')
const name = 'my super name'
const description = 'my super description'
+ const category = 5
const tags = [ 'tag1', 'tag2' ]
const video = 'video_short.webm'
- videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 401, done)
+ videosUtils.uploadVideo(server.url, accessToken, name, category, description, tags, video, 401, done)
})
it('Should not be able to make friends', function (done) {
it('Should upload the video with the correct token', function (done) {
const name = 'my super name'
+ const category = 5
const description = 'my super description'
const tags = [ 'tag1', 'tag2' ]
const video = 'video_short.webm'
- videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, function (err, res) {
+ videosUtils.uploadVideo(server.url, accessToken, name, category, description, tags, video, 204, function (err, res) {
if (err) throw err
videosUtils.getVideosList(server.url, function (err, res) {
it('Should upload the video again with the correct token', function (done) {
const name = 'my super name 2'
+ const category = 5
const description = 'my super description 2'
const tags = [ 'tag1' ]
const video = 'video_short.webm'
- videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, done)
+ videosUtils.uploadVideo(server.url, accessToken, name, category, description, tags, video, 204, done)
})
it('Should retrieve a video rating', function (done) {
this.timeout(5000)
const name = 'my super name'
+ const category = 5
const description = 'my super description'
const tags = [ 'tag1', 'tag2', 'tag3' ]
const file = 'video_short.webm'
- videosUtils.uploadVideo(server.url, accessTokenUser, name, description, tags, file, done)
+ videosUtils.uploadVideo(server.url, accessTokenUser, name, category, description, tags, file, done)
})
it('Should list all the users', function (done) {
// Upload some videos on each pods
function (next) {
const name = 'my super name for pod 1'
+ const category = 5
const description = 'my super description for pod 1'
const tags = [ 'tag' ]
const file = 'video_short2.webm'
- videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, description, tags, file, next)
+ videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, category, description, tags, file, next)
},
function (next) {
const name = 'my super name for pod 2'
+ const category = 5
const description = 'my super description for pod 2'
const tags = [ 'tag' ]
const file = 'video_short2.webm'
- videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, description, tags, file, next)
+ videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, category, description, tags, file, next)
},
// Wait videos propagation
function (next) {
if (!callback) callback = function () {}
const name = Date.now() + ' name'
+ const category = 4
const description = Date.now() + ' description'
const tags = [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ]
const file = 'video_short1.webm'
console.log('Uploading video to server ' + numServer)
- videosUtils.uploadVideo(servers[numServer].url, servers[numServer].accessToken, name, description, tags, file, callback)
+ videosUtils.uploadVideo(servers[numServer].url, servers[numServer].accessToken, name, category, description, tags, file, callback)
}
function update (servers, numServer, callback) {
.option('-u, --url <url>', 'Server url')
.option('-a, --access-token <token>', 'Access token')
.option('-n, --name <name>', 'Video name')
+ .option('-d, --category <category number>', 'Category number')
.option('-d, --description <description>', 'Video description')
.option('-t, --tags <tags>', 'Video tags', list)
.option('-f, --file <file>', 'Video absolute file path')
!program.url ||
!program.accessToken ||
!program.name ||
+ !program.category ||
!program.description ||
!program.tags ||
!Array.isArray(program.tags) ||
program.url,
program.accessToken,
program.name,
+ program.category,
program.description,
program.tags,
program.file
return val.split(',')
}
-function upload (url, accessToken, name, description, tags, file) {
+function upload (url, accessToken, name, category, description, tags, file) {
console.log('Uploading %s video...', program.name)
- utils.uploadVideo(url, accessToken, name, description, tags, file, function (err) {
+ utils.uploadVideo(url, accessToken, name, category, description, tags, file, function (err) {
if (err) throw err
console.log('Video uploaded.')
const request = require('supertest')
const videosUtils = {
+ getVideoCategories,
getAllVideosListBy,
getVideo,
getVideosList,
// ---------------------- Export functions --------------------
+function getVideoCategories (url, end) {
+ const path = '/api/v1/videos/categories'
+
+ request(url)
+ .get(path)
+ .set('Accept', 'application/json')
+ .expect(200)
+ .expect('Content-Type', /json/)
+ .end(end)
+}
+
function getAllVideosListBy (url, end) {
const path = '/api/v1/videos'
}
}
-function uploadVideo (url, accessToken, name, description, tags, fixture, specialStatus, end) {
+function uploadVideo (url, accessToken, name, category, description, tags, fixture, specialStatus, end) {
if (!end) {
end = specialStatus
specialStatus = 204
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken)
.field('name', name)
+ .field('category', category)
.field('description', description)
for (let i = 0; i < tags.length; i++) {
.end(end)
}
-function updateVideo (url, accessToken, id, name, description, tags, specialStatus, end) {
+function updateVideo (url, accessToken, id, name, category, description, tags, specialStatus, end) {
if (!end) {
end = specialStatus
specialStatus = 204
.set('Authorization', 'Bearer ' + accessToken)
if (name) req.field('name', name)
+ if (category) req.field('category', category)
if (description) req.field('description', description)
if (tags) {