From cda021079ff455cc0fd0eb95a5395fa808ab63d1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sat, 30 Jan 2016 17:05:22 +0100 Subject: New directory organization --- routes/api/v1/index.js | 12 ------ routes/api/v1/pods.js | 69 --------------------------------- routes/api/v1/remoteVideos.js | 33 ---------------- routes/api/v1/videos.js | 88 ------------------------------------------- 4 files changed, 202 deletions(-) delete mode 100644 routes/api/v1/index.js delete mode 100644 routes/api/v1/pods.js delete mode 100644 routes/api/v1/remoteVideos.js delete mode 100644 routes/api/v1/videos.js (limited to 'routes/api/v1') diff --git a/routes/api/v1/index.js b/routes/api/v1/index.js deleted file mode 100644 index f5504ad85..000000000 --- a/routes/api/v1/index.js +++ /dev/null @@ -1,12 +0,0 @@ -;(function () { - 'use strict' - - var express = require('express') - var router = express.Router() - - router.use('/videos', require('./videos')) - router.use('/remotevideos', require('./remoteVideos')) - router.use('/pods', require('./pods')) - - module.exports = router -})() diff --git a/routes/api/v1/pods.js b/routes/api/v1/pods.js deleted file mode 100644 index 2430b0d7e..000000000 --- a/routes/api/v1/pods.js +++ /dev/null @@ -1,69 +0,0 @@ -;(function () { - 'use strict' - - var express = require('express') - var router = express.Router() - var middleware = require('../../../middlewares') - var miscMiddleware = middleware.misc - var reqValidator = middleware.reqValidators.pods - var secureRequest = middleware.reqValidators.remote.secureRequest - var pods = require('../../../src/pods') - - function listPods (req, res, next) { - pods.list(function (err, pods_list) { - if (err) return next(err) - - res.json(pods_list) - }) - } - - function addPods (req, res, next) { - pods.add(req.body.data, function (err, json) { - if (err) return next(err) - - res.json(json) - }) - } - - function removePods (req, res, next) { - pods.remove(req.body.signature.url, function (err) { - if (err) return next(err) - - res.sendStatus(204) - }) - } - - function makeFriends (req, res, next) { - pods.hasFriends(function (err, has_friends) { - if (err) return next(err) - - if (has_friends === true) { - // We need to quit our friends before make new ones - res.sendStatus(409) - } else { - pods.makeFriends(function (err) { - if (err) return next(err) - - res.sendStatus(204) - }) - } - }) - } - - function quitFriends (req, res, next) { - pods.quitFriends(function (err) { - if (err) return next(err) - - res.sendStatus(204) - }) - } - - router.get('/', miscMiddleware.cache(false), listPods) - router.get('/makefriends', miscMiddleware.cache(false), makeFriends) - router.get('/quitfriends', miscMiddleware.cache(false), quitFriends) - router.post('/', reqValidator.podsAdd, miscMiddleware.cache(false), addPods) - // Post because this is a secured request - router.post('/remove', secureRequest, miscMiddleware.decryptBody, removePods) - - module.exports = router -})() diff --git a/routes/api/v1/remoteVideos.js b/routes/api/v1/remoteVideos.js deleted file mode 100644 index 6ba6ce17b..000000000 --- a/routes/api/v1/remoteVideos.js +++ /dev/null @@ -1,33 +0,0 @@ -;(function () { - 'use strict' - - var express = require('express') - var router = express.Router() - var pluck = require('lodash-node/compat/collection/pluck') - - var middleware = require('../../../middlewares') - var miscMiddleware = middleware.misc - var reqValidator = middleware.reqValidators.remote - var videos = require('../../../src/videos') - - function addRemoteVideos (req, res, next) { - videos.addRemotes(req.body.data, function (err, videos) { - if (err) return next(err) - - res.json(videos) - }) - } - - function removeRemoteVideo (req, res, next) { - videos.removeRemotes(req.body.signature.url, pluck(req.body.data, 'magnetUri'), function (err) { - if (err) return next(err) - - res.sendStatus(204) - }) - } - - router.post('/add', reqValidator.secureRequest, miscMiddleware.decryptBody, reqValidator.remoteVideosAdd, miscMiddleware.cache(false), addRemoteVideos) - router.post('/remove', reqValidator.secureRequest, miscMiddleware.decryptBody, reqValidator.remoteVideosRemove, miscMiddleware.cache(false), removeRemoteVideo) - - module.exports = router -})() diff --git a/routes/api/v1/videos.js b/routes/api/v1/videos.js deleted file mode 100644 index 95c1dffc7..000000000 --- a/routes/api/v1/videos.js +++ /dev/null @@ -1,88 +0,0 @@ -;(function () { - 'use strict' - - var express = require('express') - var config = require('config') - var crypto = require('crypto') - var multer = require('multer') - var router = express.Router() - - var middleware = require('../../../middlewares') - var miscMiddleware = middleware.misc - var reqValidator = middleware.reqValidators.videos - var videos = require('../../../src/videos') - - var uploads = config.get('storage.uploads') - - function listVideos (req, res, next) { - videos.list(function (err, videos_list) { - if (err) return next(err) - - res.json(videos_list) - }) - } - - function searchVideos (req, res, next) { - videos.search(req.params.name, function (err, videos_list) { - if (err) return next(err) - - res.json(videos_list) - }) - } - - function addVideos (req, res, next) { - videos.add({ video: req.files.input_video[0], data: req.body }, function (err) { - if (err) return next(err) - - // TODO : include Location of the new video - res.sendStatus(201) - }) - } - - function getVideos (req, res, next) { - videos.get(req.params.id, function (err, video) { - if (err) return next(err) - - if (video === null) { - return res.sendStatus(404) - } - - res.json(video) - }) - } - - function removeVideo (req, res, next) { - videos.remove(req.params.id, function (err) { - if (err) return next(err) - - res.sendStatus(204) - }) - } - - // multer configuration - var storage = multer.diskStorage({ - destination: function (req, file, cb) { - cb(null, uploads) - }, - - filename: function (req, file, cb) { - var extension = '' - if (file.mimetype === 'video/webm') extension = 'webm' - else if (file.mimetype === 'video/mp4') extension = 'mp4' - else if (file.mimetype === 'video/ogg') extension = 'ogv' - crypto.pseudoRandomBytes(16, function (err, raw) { - var fieldname = err ? undefined : raw.toString('hex') - cb(null, fieldname + '.' + extension) - }) - } - }) - var reqFiles = multer({ storage: storage }).fields([{ name: 'input_video', maxCount: 1 }]) - - router.get('/', miscMiddleware.cache(false), listVideos) - router.post('/', reqFiles, 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) - - module.exports = router -})() -- cgit v1.2.3