PeerTube/routes/api/v1/videos.js

64 lines
1.7 KiB
JavaScript
Raw Normal View History

2015-06-09 10:41:40 -05:00
;(function () {
'use strict'
var express = require('express')
var router = express.Router()
2015-11-06 10:34:15 -06:00
var middleware = require('../../../middlewares')
2015-11-07 11:40:13 -06:00
var miscMiddleware = middleware.misc
var reqValidator = middleware.reqValidators.videos
2015-11-06 10:34:15 -06:00
var videos = require('../../../src/videos')
2015-06-09 10:41:40 -05:00
function listVideos (req, res, next) {
videos.list(function (err, videos_list) {
2015-10-30 11:51:40 -05:00
if (err) return next(err)
2015-06-09 10:41:40 -05:00
res.json(videos_list)
})
}
function searchVideos (req, res, next) {
videos.search(req.params.name, function (err, videos_list) {
2015-10-30 11:51:40 -05:00
if (err) return next(err)
2015-06-09 10:41:40 -05:00
res.json(videos_list)
})
}
function addVideos (req, res, next) {
videos.add({ video: req.files.input_video, data: req.body }, function (err) {
2015-10-30 11:51:40 -05:00
if (err) return next(err)
2015-06-09 10:41:40 -05:00
// TODO : include Location of the new video
res.sendStatus(201)
})
}
function getVideos (req, res, next) {
videos.get(req.params.id, function (err, video) {
2015-10-30 11:51:40 -05:00
if (err) return next(err)
2015-06-09 10:41:40 -05:00
if (video === null) {
return res.sendStatus(404)
}
res.json(video)
})
}
function removeVideo (req, res, next) {
videos.remove(req.params.id, function (err) {
2015-10-30 11:51:40 -05:00
if (err) return next(err)
2015-06-09 10:41:40 -05:00
res.sendStatus(204)
})
}
2015-11-07 11:40:13 -06:00
router.get('/', miscMiddleware.cache(false), listVideos)
router.post('/', reqValidator.videosAdd, miscMiddleware.cache(false), addVideos)
router.get('/search/:name', reqValidator.videosSearch, miscMiddleware.cache(false), searchVideos)
router.get('/:id', reqValidator.videosGet, miscMiddleware.cache(false), getVideos)
router.delete('/:id', reqValidator.videosRemove, miscMiddleware.cache(false), removeVideo)
2015-06-09 10:41:40 -05:00
module.exports = router
})()