aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-27 16:23:34 +0200
committerChocobozzz <me@florianbigard.com>2018-08-27 16:23:34 +0200
commit62689b942b71cd1dd0d050c6ed05f884a0b325c2 (patch)
treec45c35d35d7a3e32621fba06edc63646930c8efd /server/initializers
parent84b6dbcc6e8654f39ec798905e1151ba915cd1aa (diff)
downloadPeerTube-62689b942b71cd1dd0d050c6ed05f884a0b325c2.tar.gz
PeerTube-62689b942b71cd1dd0d050c6ed05f884a0b325c2.tar.zst
PeerTube-62689b942b71cd1dd0d050c6ed05f884a0b325c2.zip
Correctly migrate to fs-extra
Diffstat (limited to 'server/initializers')
-rw-r--r--server/initializers/installer.ts10
-rw-r--r--server/initializers/migrations/0075-video-resolutions.ts9
-rw-r--r--server/initializers/migrator.ts4
3 files changed, 11 insertions, 12 deletions
diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts
index 1926c40dd..e319164e4 100644
--- a/server/initializers/installer.ts
+++ b/server/initializers/installer.ts
@@ -1,6 +1,5 @@
1import * as passwordGenerator from 'password-generator' 1import * as passwordGenerator from 'password-generator'
2import { UserRole } from '../../shared' 2import { UserRole } from '../../shared'
3import { mkdirpPromise, rimrafPromise } from '../helpers/core-utils'
4import { logger } from '../helpers/logger' 3import { logger } from '../helpers/logger'
5import { createApplicationActor, createUserAccountAndChannel } from '../lib/user' 4import { createApplicationActor, createUserAccountAndChannel } from '../lib/user'
6import { UserModel } from '../models/account/user' 5import { UserModel } from '../models/account/user'
@@ -9,6 +8,7 @@ import { OAuthClientModel } from '../models/oauth/oauth-client'
9import { applicationExist, clientsExist, usersExist } from './checker' 8import { applicationExist, clientsExist, usersExist } from './checker'
10import { CACHE, CONFIG, LAST_MIGRATION_VERSION } from './constants' 9import { CACHE, CONFIG, LAST_MIGRATION_VERSION } from './constants'
11import { sequelizeTypescript } from './database' 10import { sequelizeTypescript } from './database'
11import { remove, ensureDir } from 'fs-extra'
12 12
13async function installApplication () { 13async function installApplication () {
14 try { 14 try {
@@ -41,7 +41,7 @@ function removeCacheDirectories () {
41 // Cache directories 41 // Cache directories
42 for (const key of Object.keys(cacheDirectories)) { 42 for (const key of Object.keys(cacheDirectories)) {
43 const dir = cacheDirectories[key] 43 const dir = cacheDirectories[key]
44 tasks.push(rimrafPromise(dir)) 44 tasks.push(remove(dir))
45 } 45 }
46 46
47 return Promise.all(tasks) 47 return Promise.all(tasks)
@@ -52,16 +52,16 @@ function createDirectoriesIfNotExist () {
52 const cacheDirectories = Object.keys(CACHE) 52 const cacheDirectories = Object.keys(CACHE)
53 .map(k => CACHE[k].DIRECTORY) 53 .map(k => CACHE[k].DIRECTORY)
54 54
55 const tasks: Promise<string>[] = [] 55 const tasks: Promise<void>[] = []
56 for (const key of Object.keys(storage)) { 56 for (const key of Object.keys(storage)) {
57 const dir = storage[key] 57 const dir = storage[key]
58 tasks.push(mkdirpPromise(dir)) 58 tasks.push(ensureDir(dir))
59 } 59 }
60 60
61 // Cache directories 61 // Cache directories
62 for (const key of Object.keys(cacheDirectories)) { 62 for (const key of Object.keys(cacheDirectories)) {
63 const dir = cacheDirectories[key] 63 const dir = cacheDirectories[key]
64 tasks.push(mkdirpPromise(dir)) 64 tasks.push(ensureDir(dir))
65 } 65 }
66 66
67 return Promise.all(tasks) 67 return Promise.all(tasks)
diff --git a/server/initializers/migrations/0075-video-resolutions.ts b/server/initializers/migrations/0075-video-resolutions.ts
index 54ea852b1..26a188e5e 100644
--- a/server/initializers/migrations/0075-video-resolutions.ts
+++ b/server/initializers/migrations/0075-video-resolutions.ts
@@ -1,9 +1,8 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import { join } from 'path' 2import { join } from 'path'
3
4import { readdirPromise, renamePromise } from '../../helpers/core-utils'
5import { CONFIG } from '../../initializers/constants' 3import { CONFIG } from '../../initializers/constants'
6import { getVideoFileResolution } from '../../helpers/ffmpeg-utils' 4import { getVideoFileResolution } from '../../helpers/ffmpeg-utils'
5import { readdir, rename } from 'fs-extra'
7 6
8function up (utils: { 7function up (utils: {
9 transaction: Sequelize.Transaction, 8 transaction: Sequelize.Transaction,
@@ -14,7 +13,7 @@ function up (utils: {
14 const torrentDir = CONFIG.STORAGE.TORRENTS_DIR 13 const torrentDir = CONFIG.STORAGE.TORRENTS_DIR
15 const videoFileDir = CONFIG.STORAGE.VIDEOS_DIR 14 const videoFileDir = CONFIG.STORAGE.VIDEOS_DIR
16 15
17 return readdirPromise(videoFileDir) 16 return readdir(videoFileDir)
18 .then(videoFiles => { 17 .then(videoFiles => {
19 const tasks: Promise<any>[] = [] 18 const tasks: Promise<any>[] = []
20 for (const videoFile of videoFiles) { 19 for (const videoFile of videoFiles) {
@@ -31,11 +30,11 @@ function up (utils: {
31 .then(height => { 30 .then(height => {
32 const oldTorrentName = uuid + '.torrent' 31 const oldTorrentName = uuid + '.torrent'
33 const newTorrentName = uuid + '-' + height + '.torrent' 32 const newTorrentName = uuid + '-' + height + '.torrent'
34 return renamePromise(join(torrentDir, oldTorrentName), join(torrentDir, newTorrentName)).then(() => height) 33 return rename(join(torrentDir, oldTorrentName), join(torrentDir, newTorrentName)).then(() => height)
35 }) 34 })
36 .then(height => { 35 .then(height => {
37 const newVideoFileName = uuid + '-' + height + '.' + ext 36 const newVideoFileName = uuid + '-' + height + '.' + ext
38 return renamePromise(join(videoFileDir, videoFile), join(videoFileDir, newVideoFileName)).then(() => height) 37 return rename(join(videoFileDir, videoFile), join(videoFileDir, newVideoFileName)).then(() => height)
39 }) 38 })
40 .then(height => { 39 .then(height => {
41 const query = 'UPDATE "VideoFiles" SET "resolution" = ' + height + 40 const query = 'UPDATE "VideoFiles" SET "resolution" = ' + height +
diff --git a/server/initializers/migrator.ts b/server/initializers/migrator.ts
index 539e2bc8f..adc2f9fb3 100644
--- a/server/initializers/migrator.ts
+++ b/server/initializers/migrator.ts
@@ -1,8 +1,8 @@
1import * as path from 'path' 1import * as path from 'path'
2import { readdirPromise } from '../helpers/core-utils'
3import { logger } from '../helpers/logger' 2import { logger } from '../helpers/logger'
4import { LAST_MIGRATION_VERSION } from './constants' 3import { LAST_MIGRATION_VERSION } from './constants'
5import { sequelizeTypescript } from './database' 4import { sequelizeTypescript } from './database'
5import { readdir } from 'fs-extra'
6 6
7async function migrate () { 7async function migrate () {
8 const tables = await sequelizeTypescript.getQueryInterface().showAllTables() 8 const tables = await sequelizeTypescript.getQueryInterface().showAllTables()
@@ -52,7 +52,7 @@ export {
52// --------------------------------------------------------------------------- 52// ---------------------------------------------------------------------------
53 53
54async function getMigrationScripts () { 54async function getMigrationScripts () {
55 const files = await readdirPromise(path.join(__dirname, 'migrations')) 55 const files = await readdir(path.join(__dirname, 'migrations'))
56 const filesToMigrate: { 56 const filesToMigrate: {
57 version: string, 57 version: string,
58 script: string 58 script: string