From 350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 14 Nov 2017 17:31:26 +0100 Subject: Follow works --- server/initializers/checker.ts | 14 +++++++++++--- server/initializers/constants.ts | 5 +++++ server/initializers/installer.ts | 10 +++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) (limited to 'server/initializers') diff --git a/server/initializers/checker.ts b/server/initializers/checker.ts index b69188f7e..317d59423 100644 --- a/server/initializers/checker.ts +++ b/server/initializers/checker.ts @@ -1,8 +1,8 @@ import * as config from 'config' - import { promisify0 } from '../helpers/core-utils' -import { OAuthClientModel } from '../models/oauth/oauth-client-interface' import { UserModel } from '../models/account/user-interface' +import { ApplicationModel } from '../models/application/application-interface' +import { OAuthClientModel } from '../models/oauth/oauth-client-interface' // Some checks on configuration files function checkConfig () { @@ -70,6 +70,13 @@ async function usersExist (User: UserModel) { return totalUsers !== 0 } +// We get db by param to not import it in this file (import orders) +async function applicationExist (Application: ApplicationModel) { + const totalApplication = await Application.countTotal() + + return totalApplication !== 0 +} + // --------------------------------------------------------------------------- export { @@ -77,5 +84,6 @@ export { checkFFmpeg, checkMissedConfig, clientsExist, - usersExist + usersExist, + applicationExist } diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index e27d011fa..4a49c1ab3 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -226,6 +226,9 @@ const FRIEND_SCORE = { MAX: 1000 } +const SERVER_ACCOUNT_NAME = 'peertube' +const ACTIVITY_PUB_ACCEPT_HEADER = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' + const ACTIVITY_PUB = { COLLECTION_ITEMS_PER_PAGE: 10, VIDEO_URL_MIME_TYPES: [ @@ -352,8 +355,10 @@ export { PODS_SCORE, PREVIEWS_SIZE, REMOTE_SCHEME, + ACTIVITY_PUB_ACCEPT_HEADER, FOLLOW_STATES, SEARCHABLE_COLUMNS, + SERVER_ACCOUNT_NAME, PRIVATE_RSA_KEY_SIZE, SORTABLE_COLUMNS, STATIC_MAX_AGE, diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts index 5221b81a5..c3521a9e4 100644 --- a/server/initializers/installer.ts +++ b/server/initializers/installer.ts @@ -3,8 +3,8 @@ import { UserRole } from '../../shared' import { logger, mkdirpPromise, rimrafPromise } from '../helpers' import { createUserAccountAndChannel } from '../lib' import { createLocalAccount } from '../lib/user' -import { clientsExist, usersExist } from './checker' -import { CACHE, CONFIG, LAST_MIGRATION_VERSION } from './constants' +import { applicationExist, clientsExist, usersExist } from './checker' +import { CACHE, CONFIG, LAST_MIGRATION_VERSION, SERVER_ACCOUNT_NAME } from './constants' import { database as db } from './database' @@ -128,9 +128,13 @@ async function createOAuthAdminIfNotExist () { } async function createApplicationIfNotExist () { + const exist = await applicationExist(db.Application) + // Nothing to do, application already exist + if (exist === true) return undefined + logger.info('Creating Application table.') const applicationInstance = await db.Application.create({ migrationVersion: LAST_MIGRATION_VERSION }) logger.info('Creating application account.') - return createLocalAccount('peertube', null, applicationInstance.id, undefined) + return createLocalAccount(SERVER_ACCOUNT_NAME, null, applicationInstance.id, undefined) } -- cgit v1.2.3