From 72c7248b6fdcdb2175e726ff51b42e7555f2bd84 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 24 Oct 2017 19:41:09 +0200 Subject: Add video channels --- server/initializers/constants.ts | 23 +++++++++++++++++++---- server/initializers/database.ts | 2 ++ server/initializers/installer.ts | 19 +++++++++++-------- 3 files changed, 32 insertions(+), 12 deletions(-) (limited to 'server/initializers') diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 132164746..54dce980f 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -10,6 +10,7 @@ import { RequestEndpoint, RequestVideoEventType, RequestVideoQaduType, + RemoteVideoRequestType, JobState } from '../../shared/models' @@ -35,6 +36,7 @@ const SORTABLE_COLUMNS = { PODS: [ 'id', 'host', 'score', 'createdAt' ], USERS: [ 'id', 'username', 'createdAt' ], VIDEO_ABUSES: [ 'id', 'createdAt' ], + VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ], VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ], BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ] } @@ -115,6 +117,10 @@ const CONSTRAINTS_FIELDS = { VIDEO_ABUSES: { REASON: { min: 2, max: 300 } // Length }, + VIDEO_CHANNELS: { + NAME: { min: 3, max: 50 }, // Length + DESCRIPTION: { min: 3, max: 250 } // Length + }, VIDEOS: { NAME: { min: 3, max: 50 }, // Length DESCRIPTION: { min: 3, max: 250 }, // Length @@ -232,11 +238,20 @@ const REQUEST_ENDPOINTS: { [ id: string ]: RequestEndpoint } = { VIDEOS: 'videos' } -const REQUEST_ENDPOINT_ACTIONS: { [ id: string ]: any } = {} +const REQUEST_ENDPOINT_ACTIONS: { + [ id: string ]: { + [ id: string ]: RemoteVideoRequestType + } +} = {} REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] = { - ADD: 'add', - UPDATE: 'update', - REMOVE: 'remove', + ADD_VIDEO: 'add-video', + UPDATE_VIDEO: 'update-video', + REMOVE_VIDEO: 'remove-video', + ADD_CHANNEL: 'add-channel', + UPDATE_CHANNEL: 'update-channel', + REMOVE_CHANNEL: 'remove-channel', + ADD_AUTHOR: 'add-author', + REMOVE_AUTHOR: 'remove-author', REPORT_ABUSE: 'report-abuse' } diff --git a/server/initializers/database.ts b/server/initializers/database.ts index c5a385361..d461cb440 100644 --- a/server/initializers/database.ts +++ b/server/initializers/database.ts @@ -14,6 +14,7 @@ import { VideoTagModel } from './../models/video/video-tag-interface' import { BlacklistedVideoModel } from './../models/video/video-blacklist-interface' import { VideoFileModel } from './../models/video/video-file-interface' import { VideoAbuseModel } from './../models/video/video-abuse-interface' +import { VideoChannelModel } from './../models/video/video-channel-interface' import { UserModel } from './../models/user/user-interface' import { UserVideoRateModel } from './../models/user/user-video-rate-interface' import { TagModel } from './../models/video/tag-interface' @@ -50,6 +51,7 @@ const database: { UserVideoRate?: UserVideoRateModel, User?: UserModel, VideoAbuse?: VideoAbuseModel, + VideoChannel?: VideoChannelModel, VideoFile?: VideoFileModel, BlacklistedVideo?: BlacklistedVideoModel, VideoTag?: VideoTagModel, diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts index 10b74b85f..b997de07f 100644 --- a/server/initializers/installer.ts +++ b/server/initializers/installer.ts @@ -5,6 +5,7 @@ import { database as db } from './database' import { USER_ROLES, CONFIG, LAST_MIGRATION_VERSION, CACHE } from './constants' import { clientsExist, usersExist } from './checker' import { logger, createCertsIfNotExist, mkdirpPromise, rimrafPromise } from '../helpers' +import { createUserAuthorAndChannel } from '../lib' function installApplication () { return db.sequelize.sync() @@ -91,7 +92,7 @@ function createOAuthAdminIfNotExist () { const username = 'root' const role = USER_ROLES.ADMIN const email = CONFIG.ADMIN.EMAIL - const createOptions: { validate?: boolean } = {} + let validatePassword = true let password = '' // Do not generate a random password for tests @@ -103,7 +104,7 @@ function createOAuthAdminIfNotExist () { } // Our password is weak so do not validate it - createOptions.validate = false + validatePassword = false } else { password = passwordGenerator(8, true) } @@ -115,13 +116,15 @@ function createOAuthAdminIfNotExist () { role, videoQuota: -1 } + const user = db.User.build(userData) - return db.User.create(userData, createOptions).then(createdUser => { - logger.info('Username: ' + username) - logger.info('User password: ' + password) + return createUserAuthorAndChannel(user, validatePassword) + .then(({ user }) => { + logger.info('Username: ' + username) + logger.info('User password: ' + password) - logger.info('Creating Application table.') - return db.Application.create({ migrationVersion: LAST_MIGRATION_VERSION }) - }) + logger.info('Creating Application table.') + return db.Application.create({ migrationVersion: LAST_MIGRATION_VERSION }) + }) }) } -- cgit v1.2.3