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

Add ability to set a name to a channel

This commit is contained in:
Chocobozzz 2018-08-17 15:45:42 +02:00
parent 965c4b22d0
commit 8a19bee1a1
45 changed files with 321 additions and 184 deletions

View file

@ -42,7 +42,7 @@ function isAccountNameWithHostExist (nameWithDomain: string, res: Response, send
let promise: Bluebird<AccountModel>
if (!host || host === CONFIG.WEBSERVER.HOST) promise = AccountModel.loadLocalByName(accountName)
else promise = AccountModel.loadLocalByNameAndHost(accountName, host)
else promise = AccountModel.loadByNameAndHost(accountName, host)
return isAccountExist(promise, res, sendNotFound)
}

View file

@ -27,7 +27,7 @@ function isActorPublicKeyValid (publicKey: string) {
validator.isLength(publicKey, CONSTRAINTS_FIELDS.ACTORS.PUBLIC_KEY)
}
const actorNameRegExp = new RegExp('[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_]+')
const actorNameRegExp = new RegExp('^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\\-_]+$')
function isActorPreferredUsernameValid (preferredUsername: string) {
return exists(preferredUsername) && validator.matches(preferredUsername, actorNameRegExp)
}

View file

@ -2,10 +2,9 @@ import * as express from 'express'
import 'express-validator'
import 'multer'
import * as validator from 'validator'
import { CONSTRAINTS_FIELDS } from '../../initializers'
import { CONFIG, 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
@ -21,13 +20,13 @@ 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)
async function isLocalVideoChannelNameExist (name: string, res: express.Response) {
const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
return processVideoChannelExist(videoChannel, res)
}
async function isVideoChannelExist (id: string, res: express.Response) {
async function isVideoChannelIdExist (id: string, res: express.Response) {
let videoChannel: VideoChannelModel
if (validator.isInt(id)) {
videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
@ -38,14 +37,25 @@ async function isVideoChannelExist (id: string, res: express.Response) {
return processVideoChannelExist(videoChannel, res)
}
async function isVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) {
const [ name, host ] = nameWithDomain.split('@')
let videoChannel: VideoChannelModel
if (!host || host === CONFIG.WEBSERVER.HOST) videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
else videoChannel = await VideoChannelModel.loadByNameAndHostAndPopulateAccount(name, host)
return processVideoChannelExist(videoChannel, res)
}
// ---------------------------------------------------------------------------
export {
isVideoChannelNameWithHostExist,
isLocalVideoChannelNameExist,
isVideoChannelDescriptionValid,
isVideoChannelNameValid,
isVideoChannelSupportValid,
isVideoChannelExist
isVideoChannelIdExist
}
function processVideoChannelExist (videoChannel: VideoChannelModel, res: express.Response) {