aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers
diff options
context:
space:
mode:
Diffstat (limited to 'server/initializers')
-rw-r--r--server/initializers/constants.ts16
-rw-r--r--server/initializers/installer.ts30
2 files changed, 41 insertions, 5 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index f087b7476..928a3f570 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -61,7 +61,8 @@ const CONFIG = {
61 VIDEOS_DIR: join(root(), config.get<string>('storage.videos')), 61 VIDEOS_DIR: join(root(), config.get<string>('storage.videos')),
62 THUMBNAILS_DIR: join(root(), config.get<string>('storage.thumbnails')), 62 THUMBNAILS_DIR: join(root(), config.get<string>('storage.thumbnails')),
63 PREVIEWS_DIR: join(root(), config.get<string>('storage.previews')), 63 PREVIEWS_DIR: join(root(), config.get<string>('storage.previews')),
64 TORRENTS_DIR: join(root(), config.get<string>('storage.torrents')) 64 TORRENTS_DIR: join(root(), config.get<string>('storage.torrents')),
65 CACHE_DIR: join(root(), config.get<string>('storage.cache'))
65 }, 66 },
66 WEBSERVER: { 67 WEBSERVER: {
67 SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http', 68 SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
@@ -80,6 +81,11 @@ const CONFIG = {
80 TRANSCODING: { 81 TRANSCODING: {
81 ENABLED: config.get<boolean>('transcoding.enabled'), 82 ENABLED: config.get<boolean>('transcoding.enabled'),
82 THREADS: config.get<number>('transcoding.threads') 83 THREADS: config.get<number>('transcoding.threads')
84 },
85 CACHE: {
86 PREVIEWS: {
87 SIZE: config.get<number>('cache.previews.size')
88 }
83 } 89 }
84} 90}
85CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT 91CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
@@ -278,6 +284,13 @@ let STATIC_MAX_AGE = '30d'
278const THUMBNAILS_SIZE = '200x110' 284const THUMBNAILS_SIZE = '200x110'
279const PREVIEWS_SIZE = '640x480' 285const PREVIEWS_SIZE = '640x480'
280 286
287// Subfolders of cache directory
288const CACHE = {
289 DIRECTORIES: {
290 PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
291 }
292}
293
281// --------------------------------------------------------------------------- 294// ---------------------------------------------------------------------------
282 295
283const USER_ROLES: { [ id: string ]: UserRole } = { 296const USER_ROLES: { [ id: string ]: UserRole } = {
@@ -307,6 +320,7 @@ if (isTestInstance() === true) {
307export { 320export {
308 API_VERSION, 321 API_VERSION,
309 BCRYPT_SALT_SIZE, 322 BCRYPT_SALT_SIZE,
323 CACHE,
310 CONFIG, 324 CONFIG,
311 CONSTRAINTS_FIELDS, 325 CONSTRAINTS_FIELDS,
312 FRIEND_SCORE, 326 FRIEND_SCORE,
diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts
index 1ec24c4ad..3c5a77df9 100644
--- a/server/initializers/installer.ts
+++ b/server/initializers/installer.ts
@@ -4,12 +4,13 @@ import * as passwordGenerator from 'password-generator'
4import * as Promise from 'bluebird' 4import * as Promise from 'bluebird'
5 5
6import { database as db } from './database' 6import { database as db } from './database'
7import { USER_ROLES, CONFIG, LAST_MIGRATION_VERSION } from './constants' 7import { USER_ROLES, CONFIG, LAST_MIGRATION_VERSION, CACHE } from './constants'
8import { clientsExist, usersExist } from './checker' 8import { clientsExist, usersExist } from './checker'
9import { logger, createCertsIfNotExist, root, mkdirpPromise } from '../helpers' 9import { logger, createCertsIfNotExist, root, mkdirpPromise, rimrafPromise } from '../helpers'
10 10
11function installApplication () { 11function installApplication () {
12 return db.sequelize.sync() 12 return db.sequelize.sync()
13 .then(() => removeCacheDirectories())
13 .then(() => createDirectoriesIfNotExist()) 14 .then(() => createDirectoriesIfNotExist())
14 .then(() => createCertsIfNotExist()) 15 .then(() => createCertsIfNotExist())
15 .then(() => createOAuthClientIfNotExist()) 16 .then(() => createOAuthClientIfNotExist())
@@ -24,13 +25,34 @@ export {
24 25
25// --------------------------------------------------------------------------- 26// ---------------------------------------------------------------------------
26 27
28function removeCacheDirectories () {
29 const cacheDirectories = CACHE.DIRECTORIES
30
31 const tasks = []
32
33 // Cache directories
34 Object.keys(cacheDirectories).forEach(key => {
35 const dir = cacheDirectories[key]
36 tasks.push(rimrafPromise(dir))
37 })
38
39 return Promise.all(tasks)
40}
41
27function createDirectoriesIfNotExist () { 42function createDirectoriesIfNotExist () {
28 const storages = config.get('storage') 43 const storages = CONFIG.STORAGE
44 const cacheDirectories = CACHE.DIRECTORIES
29 45
30 const tasks = [] 46 const tasks = []
31 Object.keys(storages).forEach(key => { 47 Object.keys(storages).forEach(key => {
32 const dir = storages[key] 48 const dir = storages[key]
33 tasks.push(mkdirpPromise(join(root(), dir))) 49 tasks.push(mkdirpPromise(dir))
50 })
51
52 // Cache directories
53 Object.keys(cacheDirectories).forEach(key => {
54 const dir = cacheDirectories[key]
55 tasks.push(mkdirpPromise(dir))
34 }) 56 })
35 57
36 return Promise.all(tasks) 58 return Promise.all(tasks)