import { ensureDir, readdir, remove } from 'fs-extra'
import passwordGenerator from 'password-generator'
+import { join } from 'path'
+import { isTestOrDevInstance } from '@server/helpers/core-utils'
+import { getNodeABIVersion } from '@server/helpers/version'
import { UserRole } from '@shared/models'
import { logger } from '../helpers/logger'
import { buildUser, createApplicationActor, createUserAccountAndChannelAndPlaylist } from '../lib/user'
import { OAuthClientModel } from '../models/oauth/oauth-client'
import { applicationExist, clientsExist, usersExist } from './checker-after-init'
import { CONFIG } from './config'
-import { FILES_CACHE, HLS_STREAMING_PLAYLIST_DIRECTORY, LAST_MIGRATION_VERSION, RESUMABLE_UPLOAD_DIRECTORY } from './constants'
+import { DIRECTORIES, FILES_CACHE, LAST_MIGRATION_VERSION } from './constants'
import { sequelizeTypescript } from './database'
async function installApplication () {
const tasks: Promise<any>[] = []
// Cache directories
- for (const key of Object.keys(cacheDirectories)) {
- const dir = cacheDirectories[key]
+ for (const dir of cacheDirectories) {
tasks.push(removeDirectoryOrContent(dir))
}
const files = await readdir(dir)
for (const file of files) {
- await remove(file)
+ await remove(join(dir, file))
}
}
}
}
// Cache directories
- for (const key of Object.keys(cacheDirectories)) {
- const dir = cacheDirectories[key]
+ for (const dir of cacheDirectories) {
tasks.push(ensureDir(dir))
}
- // Playlist directories
- tasks.push(ensureDir(HLS_STREAMING_PLAYLIST_DIRECTORY))
+ tasks.push(ensureDir(DIRECTORIES.HLS_STREAMING_PLAYLIST.PRIVATE))
+ tasks.push(ensureDir(DIRECTORIES.HLS_STREAMING_PLAYLIST.PUBLIC))
+ tasks.push(ensureDir(DIRECTORIES.VIDEOS.PUBLIC))
+ tasks.push(ensureDir(DIRECTORIES.VIDEOS.PRIVATE))
// Resumable upload directory
- tasks.push(ensureDir(RESUMABLE_UPLOAD_DIRECTORY))
+ tasks.push(ensureDir(DIRECTORIES.RESUMABLE_UPLOAD))
return Promise.all(tasks)
}
let validatePassword = true
let password = ''
- // Do not generate a random password for tests
- if (process.env.NODE_ENV === 'test') {
+ // Do not generate a random password for test and dev environments
+ if (isTestOrDevInstance()) {
password = 'test'
if (process.env.NODE_APP_INSTANCE) {
logger.info('Creating application account.')
const application = await ApplicationModel.create({
- migrationVersion: LAST_MIGRATION_VERSION
+ migrationVersion: LAST_MIGRATION_VERSION,
+ nodeVersion: process.version,
+ nodeABIVersion: getNodeABIVersion()
})
return createApplicationActor(application.id)