mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00
First version with PostgreSQL
This commit is contained in:
parent
108626609e
commit
feb4bdfd9b
68 changed files with 1171 additions and 730 deletions
|
@ -1,12 +1,9 @@
|
|||
'use strict'
|
||||
|
||||
const mongoose = require('mongoose')
|
||||
|
||||
const checkErrors = require('./utils').checkErrors
|
||||
const db = require('../../initializers/database')
|
||||
const logger = require('../../helpers/logger')
|
||||
|
||||
const User = mongoose.model('User')
|
||||
|
||||
const validatorsUsers = {
|
||||
usersAdd,
|
||||
usersRemove,
|
||||
|
@ -20,7 +17,7 @@ function usersAdd (req, res, next) {
|
|||
logger.debug('Checking usersAdd parameters', { parameters: req.body })
|
||||
|
||||
checkErrors(req, res, function () {
|
||||
User.loadByUsername(req.body.username, function (err, user) {
|
||||
db.User.loadByUsername(req.body.username, function (err, user) {
|
||||
if (err) {
|
||||
logger.error('Error in usersAdd request validator.', { error: err })
|
||||
return res.sendStatus(500)
|
||||
|
@ -34,12 +31,12 @@ function usersAdd (req, res, next) {
|
|||
}
|
||||
|
||||
function usersRemove (req, res, next) {
|
||||
req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
|
||||
req.checkParams('id', 'Should have a valid id').notEmpty().isInt()
|
||||
|
||||
logger.debug('Checking usersRemove parameters', { parameters: req.params })
|
||||
|
||||
checkErrors(req, res, function () {
|
||||
User.loadById(req.params.id, function (err, user) {
|
||||
db.User.loadById(req.params.id, function (err, user) {
|
||||
if (err) {
|
||||
logger.error('Error in usersRemove request validator.', { error: err })
|
||||
return res.sendStatus(500)
|
||||
|
@ -55,7 +52,7 @@ function usersRemove (req, res, next) {
|
|||
}
|
||||
|
||||
function usersUpdate (req, res, next) {
|
||||
req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
|
||||
req.checkParams('id', 'Should have a valid id').notEmpty().isInt()
|
||||
// Add old password verification
|
||||
req.checkBody('password', 'Should have a valid password').isUserPasswordValid()
|
||||
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
'use strict'
|
||||
|
||||
const mongoose = require('mongoose')
|
||||
|
||||
const checkErrors = require('./utils').checkErrors
|
||||
const constants = require('../../initializers/constants')
|
||||
const customVideosValidators = require('../../helpers/custom-validators').videos
|
||||
const db = require('../../initializers/database')
|
||||
const logger = require('../../helpers/logger')
|
||||
|
||||
const Video = mongoose.model('Video')
|
||||
|
||||
const validatorsVideos = {
|
||||
videosAdd,
|
||||
videosGet,
|
||||
|
@ -29,7 +26,7 @@ function videosAdd (req, res, next) {
|
|||
checkErrors(req, res, function () {
|
||||
const videoFile = req.files.videofile[0]
|
||||
|
||||
Video.getDurationFromFile(videoFile.path, function (err, duration) {
|
||||
db.Video.getDurationFromFile(videoFile.path, function (err, duration) {
|
||||
if (err) {
|
||||
return res.status(400).send('Cannot retrieve metadata of the file.')
|
||||
}
|
||||
|
@ -45,12 +42,12 @@ function videosAdd (req, res, next) {
|
|||
}
|
||||
|
||||
function videosGet (req, res, next) {
|
||||
req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
|
||||
req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4)
|
||||
|
||||
logger.debug('Checking videosGet parameters', { parameters: req.params })
|
||||
|
||||
checkErrors(req, res, function () {
|
||||
Video.load(req.params.id, function (err, video) {
|
||||
db.Video.load(req.params.id, function (err, video) {
|
||||
if (err) {
|
||||
logger.error('Error in videosGet request validator.', { error: err })
|
||||
return res.sendStatus(500)
|
||||
|
@ -64,12 +61,12 @@ function videosGet (req, res, next) {
|
|||
}
|
||||
|
||||
function videosRemove (req, res, next) {
|
||||
req.checkParams('id', 'Should have a valid id').notEmpty().isMongoId()
|
||||
req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4)
|
||||
|
||||
logger.debug('Checking videosRemove parameters', { parameters: req.params })
|
||||
|
||||
checkErrors(req, res, function () {
|
||||
Video.load(req.params.id, function (err, video) {
|
||||
db.Video.loadAndPopulateAuthor(req.params.id, function (err, video) {
|
||||
if (err) {
|
||||
logger.error('Error in videosRemove request validator.', { error: err })
|
||||
return res.sendStatus(500)
|
||||
|
@ -77,7 +74,7 @@ function videosRemove (req, res, next) {
|
|||
|
||||
if (!video) return res.status(404).send('Video not found')
|
||||
else if (video.isOwned() === false) return res.status(403).send('Cannot remove video of another pod')
|
||||
else if (video.author !== res.locals.oauth.token.user.username) return res.status(403).send('Cannot remove video of another user')
|
||||
else if (video.Author.name !== res.locals.oauth.token.user.username) return res.status(403).send('Cannot remove video of another user')
|
||||
|
||||
next()
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue