1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 02:09:37 +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

@ -3,6 +3,7 @@ import { CONSTRAINTS_FIELDS } from '../../../initializers'
import { exists } from '../misc'
import { truncate } from 'lodash'
import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc'
import { isHostValid } from '../servers'
function isActorEndpointsObjectValid (endpointObject: any) {
return isActivityPubUrlValid(endpointObject.sharedInbox)
@ -109,6 +110,15 @@ function normalizeActor (actor: any) {
return
}
function isValidActorHandle (handle: string) {
if (!exists(handle)) return false
const parts = handle.split('@')
if (parts.length !== 2) return false
return isHostValid(parts[1])
}
// ---------------------------------------------------------------------------
export {
@ -126,5 +136,6 @@ export {
isActorAcceptActivityValid,
isActorRejectActivityValid,
isActorDeleteActivityValid,
isActorUpdateActivityValid
isActorUpdateActivityValid,
isValidActorHandle
}

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
}

View file

@ -2,7 +2,7 @@ import { CONFIG, REMOTE_SCHEME } from '../../initializers'
import { sanitizeHost } from '../core-utils'
import { exists } from './misc'
function isWebfingerResourceValid (value: string) {
function isWebfingerLocalResourceValid (value: string) {
if (!exists(value)) return false
if (value.startsWith('acct:') === false) return false
@ -17,5 +17,5 @@ function isWebfingerResourceValid (value: string) {
// ---------------------------------------------------------------------------
export {
isWebfingerResourceValid
isWebfingerLocalResourceValid
}