-import { join } from 'path'
-import * as config from 'config'
import * as passwordGenerator from 'password-generator'
import * as Promise from 'bluebird'
import { database as db } from './database'
-import { USER_ROLES, CONFIG, LAST_MIGRATION_VERSION } from './constants'
+import { USER_ROLES, CONFIG, LAST_MIGRATION_VERSION, CACHE } from './constants'
import { clientsExist, usersExist } from './checker'
-import { logger, createCertsIfNotExist, root, mkdirpPromise } from '../helpers'
+import { logger, createCertsIfNotExist, mkdirpPromise, rimrafPromise } from '../helpers'
function installApplication () {
return db.sequelize.sync()
+ .then(() => removeCacheDirectories())
.then(() => createDirectoriesIfNotExist())
.then(() => createCertsIfNotExist())
.then(() => createOAuthClientIfNotExist())
// ---------------------------------------------------------------------------
+function removeCacheDirectories () {
+ const cacheDirectories = CACHE.DIRECTORIES
+
+ const tasks = []
+
+ // Cache directories
+ Object.keys(cacheDirectories).forEach(key => {
+ const dir = cacheDirectories[key]
+ tasks.push(rimrafPromise(dir))
+ })
+
+ return Promise.all(tasks)
+}
+
function createDirectoriesIfNotExist () {
- const storages = config.get('storage')
+ const storage = CONFIG.STORAGE
+ const cacheDirectories = CACHE.DIRECTORIES
const tasks = []
- Object.keys(storages).forEach(key => {
- const dir = storages[key]
- tasks.push(mkdirpPromise(join(root(), dir)))
+ Object.keys(storage).forEach(key => {
+ const dir = storage[key]
+ tasks.push(mkdirpPromise(dir))
+ })
+
+ // Cache directories
+ Object.keys(cacheDirectories).forEach(key => {
+ const dir = cacheDirectories[key]
+ tasks.push(mkdirpPromise(dir))
})
return Promise.all(tasks)
}
function createOAuthClientIfNotExist () {
- return clientsExist().then(exist => {
+ return clientsExist(db.OAuthClient).then(exist => {
// Nothing to do, clients already exist
if (exist === true) return undefined
}
function createOAuthAdminIfNotExist () {
- return usersExist().then(exist => {
+ return usersExist(db.User).then(exist => {
// Nothing to do, users already exist
if (exist === true) return undefined
username,
email,
password,
- role
+ role,
+ videoQuota: -1
}
return db.User.create(userData, createOptions).then(createdUser => {