const videosUtils = {
getVideoCategories,
+ getVideoLicences,
+ getVideoLanguages,
getAllVideosListBy,
getVideo,
getVideosList,
.end(end)
}
+function getVideoLicences (url, end) {
+ const path = '/api/v1/videos/licences'
+
+ request(url)
+ .get(path)
+ .set('Accept', 'application/json')
+ .expect(200)
+ .expect('Content-Type', /json/)
+ .end(end)
+}
+
+function getVideoLanguages (url, end) {
+ const path = '/api/v1/videos/languages'
+
+ 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'
.end(end)
}
-function testVideoImage (url, videoName, imagePath, callback) {
+function testVideoImage (url, imageName, imagePath, callback) {
// Don't test images if the node env is not set
// Because we need a special ffmpeg version for this test
if (process.env.NODE_TEST_IMAGE) {
.end(function (err, res) {
if (err) return callback(err)
- fs.readFile(pathUtils.join(__dirname, '..', 'api', 'fixtures', videoName + '.jpg'), function (err, data) {
+ fs.readFile(pathUtils.join(__dirname, '..', 'api', 'fixtures', imageName + '.jpg'), function (err, data) {
if (err) return callback(err)
callback(null, data.equals(res.body))
}
}
-function uploadVideo (url, accessToken, name, category, description, tags, fixture, specialStatus, end) {
+function uploadVideo (url, accessToken, videoAttributesArg, specialStatus, end) {
if (!end) {
end = specialStatus
specialStatus = 204
const path = '/api/v1/videos'
+ // Default attributes
+ let attributes = {
+ name: 'my super video',
+ category: 5,
+ licence: 4,
+ language: 3,
+ nsfw: true,
+ description: 'my super description',
+ tags: [ 'tag' ],
+ fixture: 'video_short.webm'
+ }
+ attributes = Object.assign(attributes, videoAttributesArg)
+
const req = request(url)
.post(path)
.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++) {
- req.field('tags[' + i + ']', tags[i])
+ .field('name', attributes.name)
+ .field('category', attributes.category)
+ .field('licence', attributes.licence)
+ .field('language', attributes.language)
+ .field('nsfw', attributes.nsfw)
+ .field('description', attributes.description)
+
+ for (let i = 0; i < attributes.tags.length; i++) {
+ req.field('tags[' + i + ']', attributes.tags[i])
}
let filepath = ''
- if (pathUtils.isAbsolute(fixture)) {
- filepath = fixture
+ if (pathUtils.isAbsolute(attributes.fixture)) {
+ filepath = attributes.fixture
} else {
- filepath = pathUtils.join(__dirname, '..', 'api', 'fixtures', fixture)
+ filepath = pathUtils.join(__dirname, '..', 'api', 'fixtures', attributes.fixture)
}
req.attach('videofile', filepath)
.end(end)
}
-function updateVideo (url, accessToken, id, name, category, description, tags, specialStatus, end) {
+function updateVideo (url, accessToken, id, attributes, specialStatus, end) {
if (!end) {
end = specialStatus
specialStatus = 204
}
const path = '/api/v1/videos/' + id
+ const body = {}
- const req = request(url)
- .put(path)
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + accessToken)
-
- if (name) req.field('name', name)
- if (category) req.field('category', category)
- if (description) req.field('description', description)
+ if (attributes.name) body.name = attributes.name
+ if (attributes.category) body.category = attributes.category
+ if (attributes.licence) body.licence = attributes.licence
+ if (attributes.language) body.language = attributes.language
+ if (attributes.nsfw) body.nsfw = attributes.nsfw
+ if (attributes.description) body.description = attributes.description
+ if (attributes.tags) body.tags = attributes.tags
- if (tags) {
- for (let i = 0; i < tags.length; i++) {
- req.field('tags[' + i + ']', tags[i])
- }
- }
-
- req.expect(specialStatus).end(end)
+ request(url)
+ .put(path)
+ .send(body)
+ .set('Accept', 'application/json')
+ .set('Authorization', 'Bearer ' + accessToken)
+ .expect(specialStatus)
+ .end(end)
}
function rateVideo (url, accessToken, id, rating, specialStatus, end) {