X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Finitializers%2Finstaller.ts;h=676f88653359e700784bf15ae208b34799561819;hb=7d9ba5c08999c6482f0bc5e0c09c6f55b7724090;hp=818bb04a254ddbe5cc74e3191a9b17a1e7791265;hpb=d9eaee3939bf2e93e5d775d32bce77842201faba;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts index 818bb04a2..676f88653 100644 --- a/server/initializers/installer.ts +++ b/server/initializers/installer.ts @@ -1,23 +1,33 @@ import * as passwordGenerator from 'password-generator' import { UserRole } from '../../shared' import { logger } from '../helpers/logger' -import { createApplicationActor, createUserAccountAndChannel } from '../lib/user' -import { UserModel } from '../models/account/user' +import { createApplicationActor, createUserAccountAndChannelAndPlaylist } from '../lib/user' +import { UserModel } from '../models/user/user' import { ApplicationModel } from '../models/application/application' import { OAuthClientModel } from '../models/oauth/oauth-client' -import { applicationExist, clientsExist, usersExist } from './checker' -import { CACHE, CONFIG, LAST_MIGRATION_VERSION } from './constants' +import { applicationExist, clientsExist, usersExist } from './checker-after-init' +import { FILES_CACHE, HLS_STREAMING_PLAYLIST_DIRECTORY, LAST_MIGRATION_VERSION, RESUMABLE_UPLOAD_DIRECTORY } from './constants' import { sequelizeTypescript } from './database' -import { remove, ensureDir } from 'fs-extra' +import { ensureDir, remove } from 'fs-extra' +import { CONFIG } from './config' async function installApplication () { try { - await sequelizeTypescript.sync() - await removeCacheDirectories() - await createDirectoriesIfNotExist() - await createApplicationIfNotExist() - await createOAuthClientIfNotExist() - await createOAuthAdminIfNotExist() + await Promise.all([ + // Database related + sequelizeTypescript.sync() + .then(() => { + return Promise.all([ + createApplicationIfNotExist(), + createOAuthClientIfNotExist(), + createOAuthAdminIfNotExist() + ]) + }), + + // Directories + removeCacheAndTmpDirectories() + .then(() => createDirectoriesIfNotExist()) + ]) } catch (err) { logger.error('Cannot install application.', { err }) process.exit(-1) @@ -32,9 +42,9 @@ export { // --------------------------------------------------------------------------- -function removeCacheDirectories () { - const cacheDirectories = Object.keys(CACHE) - .map(k => CACHE[k].DIRECTORY) +function removeCacheAndTmpDirectories () { + const cacheDirectories = Object.keys(FILES_CACHE) + .map(k => FILES_CACHE[k].DIRECTORY) const tasks: Promise[] = [] @@ -44,13 +54,15 @@ function removeCacheDirectories () { tasks.push(remove(dir)) } + tasks.push(remove(CONFIG.STORAGE.TMP_DIR)) + return Promise.all(tasks) } function createDirectoriesIfNotExist () { const storage = CONFIG.STORAGE - const cacheDirectories = Object.keys(CACHE) - .map(k => CACHE[k].DIRECTORY) + const cacheDirectories = Object.keys(FILES_CACHE) + .map(k => FILES_CACHE[k].DIRECTORY) const tasks: Promise[] = [] for (const key of Object.keys(storage)) { @@ -64,6 +76,12 @@ function createDirectoriesIfNotExist () { tasks.push(ensureDir(dir)) } + // Playlist directories + tasks.push(ensureDir(HLS_STREAMING_PLAYLIST_DIRECTORY)) + + // Resumable upload directory + tasks.push(ensureDir(RESUMABLE_UPLOAD_DIRECTORY)) + return Promise.all(tasks) } @@ -113,6 +131,8 @@ async function createOAuthAdminIfNotExist () { // Our password is weak so do not validate it validatePassword = false + } else if (process.env.PT_INITIAL_ROOT_PASSWORD) { + password = process.env.PT_INITIAL_ROOT_PASSWORD } else { password = passwordGenerator(16, true) } @@ -129,7 +149,7 @@ async function createOAuthAdminIfNotExist () { } const user = new UserModel(userData) - await createUserAccountAndChannel(user, validatePassword) + await createUserAccountAndChannelAndPlaylist({ userToCreate: user, channelNames: undefined, validateUser: validatePassword }) logger.info('Username: ' + username) logger.info('User password: ' + password) }