1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 02:39:33 +02:00

Add subscriptions endpoints to REST API

This commit is contained in:
Chocobozzz 2018-08-16 15:25:20 +02:00
parent 4bda2e47bb
commit 06a05d5f47
36 changed files with 1039 additions and 94 deletions

View file

@ -5,6 +5,7 @@ import * as validator from 'validator'
import { CONSTRAINTS_FIELDS } from '../../initializers'
import { VideoChannelModel } from '../../models/video/video-channel'
import { exists } from './misc'
import { Response } from 'express'
const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS
@ -20,6 +21,12 @@ function isVideoChannelSupportValid (value: string) {
return value === null || (exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.SUPPORT))
}
async function isLocalVideoChannelNameExist (name: string, res: Response) {
const videoChannel = await VideoChannelModel.loadLocalByName(name)
return processVideoChannelExist(videoChannel, res)
}
async function isVideoChannelExist (id: string, res: express.Response) {
let videoChannel: VideoChannelModel
if (validator.isInt(id)) {
@ -28,10 +35,24 @@ async function isVideoChannelExist (id: string, res: express.Response) {
videoChannel = await VideoChannelModel.loadByUUIDAndPopulateAccount(id)
}
return processVideoChannelExist(videoChannel, res)
}
// ---------------------------------------------------------------------------
export {
isLocalVideoChannelNameExist,
isVideoChannelDescriptionValid,
isVideoChannelNameValid,
isVideoChannelSupportValid,
isVideoChannelExist
}
function processVideoChannelExist (videoChannel: VideoChannelModel, res: express.Response) {
if (!videoChannel) {
res.status(404)
.json({ error: 'Video channel not found' })
.end()
.json({ error: 'Video channel not found' })
.end()
return false
}
@ -39,12 +60,3 @@ async function isVideoChannelExist (id: string, res: express.Response) {
res.locals.videoChannel = videoChannel
return true
}
// ---------------------------------------------------------------------------
export {
isVideoChannelDescriptionValid,
isVideoChannelNameValid,
isVideoChannelSupportValid,
isVideoChannelExist
}