import * as passwordGenerator from 'password-generator'
import { UserRole } from '../../shared'
-import { createPrivateAndPublicKeys, logger, mkdirpPromise, rimrafPromise } from '../helpers'
-import { createLocalAccountWithoutKeys, createUserAccountAndChannel } from '../lib'
+import { mkdirpPromise, rimrafPromise } from '../helpers/core-utils'
+import { logger } from '../helpers/logger'
+import { createApplicationActor, createUserAccountAndChannel } from '../lib/user'
import { UserModel } from '../models/account/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, SERVER_ACCOUNT_NAME } from './constants'
+import { CACHE, CONFIG, LAST_MIGRATION_VERSION } from './constants'
import { sequelizeTypescript } from './database'
async function installApplication () {
await createOAuthClientIfNotExist()
await createOAuthAdminIfNotExist()
} catch (err) {
- logger.error('Cannot install application.', err)
- throw err
+ logger.error('Cannot install application.', { err })
+ process.exit(-1)
}
}
// Our password is weak so do not validate it
validatePassword = false
} else {
- password = passwordGenerator(8, true)
+ password = passwordGenerator(16, true)
}
const userData = {
email,
password,
role,
+ nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
videoQuota: -1
}
const user = new UserModel(userData)
// Nothing to do, application already exist
if (exist === true) return undefined
- logger.info('Creating Application table.')
- const applicationInstance = await ApplicationModel.create({ migrationVersion: LAST_MIGRATION_VERSION })
-
logger.info('Creating application account.')
- const accountCreated = await createLocalAccountWithoutKeys(SERVER_ACCOUNT_NAME, null, applicationInstance.id, undefined)
-
- const { publicKey, privateKey } = await createPrivateAndPublicKeys()
- accountCreated.set('publicKey', publicKey)
- accountCreated.set('privateKey', privateKey)
+ const application = await ApplicationModel.create({
+ migrationVersion: LAST_MIGRATION_VERSION
+ })
- return accountCreated.save()
+ return createApplicationActor(application.id)
}