aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
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
parent84b6dbcc6e8654f39ec798905e1151ba915cd1aa (diff)
downloadPeerTube-62689b942b71cd1dd0d050c6ed05f884a0b325c2.tar.gz
PeerTube-62689b942b71cd1dd0d050c6ed05f884a0b325c2.tar.zst
PeerTube-62689b942b71cd1dd0d050c6ed05f884a0b325c2.zip
Correctly migrate to fs-extra
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/config.ts6
-rw-r--r--server/controllers/api/videos/import.ts6
-rw-r--r--server/controllers/api/videos/index.ts4
-rw-r--r--server/helpers/captions-utils.ts7
-rw-r--r--server/helpers/core-utils.ts22
-rw-r--r--server/helpers/ffmpeg-utils.ts6
-rw-r--r--server/helpers/image-utils.ts4
-rw-r--r--server/helpers/utils.ts5
-rw-r--r--server/helpers/webtorrent.ts7
-rw-r--r--server/initializers/installer.ts10
-rw-r--r--server/initializers/migrations/0075-video-resolutions.ts9
-rw-r--r--server/initializers/migrator.ts4
-rw-r--r--server/lib/cache/abstract-video-static-file-cache.ts5
-rw-r--r--server/lib/client-html.ts7
-rw-r--r--server/lib/job-queue/handlers/video-import.ts6
-rw-r--r--server/lib/schedulers/youtube-dl-update-scheduler.ts6
-rw-r--r--server/models/avatar/avatar.ts4
-rw-r--r--server/models/video/video-caption.ts4
-rw-r--r--server/models/video/video.ts33
-rw-r--r--server/tests/feeds/feeds.ts1
-rw-r--r--server/tests/utils/feeds/feeds.ts1
-rw-r--r--server/tests/utils/miscs/miscs.ts4
-rw-r--r--server/tests/utils/users/accounts.ts5
-rw-r--r--server/tests/utils/videos/videos.ts8
-rw-r--r--server/tools/import-videos.ts8
-rw-r--r--server/tools/upload.ts5
26 files changed, 75 insertions, 112 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts
index e0539c414..b25f739bb 100644
--- a/server/controllers/api/config.ts
+++ b/server/controllers/api/config.ts
@@ -3,13 +3,13 @@ import { omit } from 'lodash'
3import { ServerConfig, UserRight } from '../../../shared' 3import { ServerConfig, UserRight } from '../../../shared'
4import { About } from '../../../shared/models/server/about.model' 4import { About } from '../../../shared/models/server/about.model'
5import { CustomConfig } from '../../../shared/models/server/custom-config.model' 5import { CustomConfig } from '../../../shared/models/server/custom-config.model'
6import { unlinkPromise, writeFilePromise } from '../../helpers/core-utils'
7import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' 6import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup'
8import { CONFIG, CONSTRAINTS_FIELDS, reloadConfig } from '../../initializers' 7import { CONFIG, CONSTRAINTS_FIELDS, reloadConfig } from '../../initializers'
9import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' 8import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares'
10import { customConfigUpdateValidator } from '../../middlewares/validators/config' 9import { customConfigUpdateValidator } from '../../middlewares/validators/config'
11import { ClientHtml } from '../../lib/client-html' 10import { ClientHtml } from '../../lib/client-html'
12import { auditLoggerFactory, CustomConfigAuditView } from '../../helpers/audit-logger' 11import { auditLoggerFactory, CustomConfigAuditView } from '../../helpers/audit-logger'
12import { remove, writeJSON } from 'fs-extra'
13 13
14const packageJSON = require('../../../../package.json') 14const packageJSON = require('../../../../package.json')
15const configRouter = express.Router() 15const configRouter = express.Router()
@@ -130,7 +130,7 @@ async function getCustomConfig (req: express.Request, res: express.Response, nex
130} 130}
131 131
132async function deleteCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { 132async function deleteCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) {
133 await unlinkPromise(CONFIG.CUSTOM_FILE) 133 await remove(CONFIG.CUSTOM_FILE)
134 134
135 auditLogger.delete( 135 auditLogger.delete(
136 res.locals.oauth.token.User.Account.Actor.getIdentifier(), 136 res.locals.oauth.token.User.Account.Actor.getIdentifier(),
@@ -163,7 +163,7 @@ async function updateCustomConfig (req: express.Request, res: express.Response,
163 toUpdateJSON.instance['short_description'] = toUpdate.instance.shortDescription 163 toUpdateJSON.instance['short_description'] = toUpdate.instance.shortDescription
164 toUpdateJSON.instance['default_nsfw_policy'] = toUpdate.instance.defaultNSFWPolicy 164 toUpdateJSON.instance['default_nsfw_policy'] = toUpdate.instance.defaultNSFWPolicy
165 165
166 await writeFilePromise(CONFIG.CUSTOM_FILE, JSON.stringify(toUpdateJSON, undefined, 2)) 166 await writeJSON(CONFIG.CUSTOM_FILE, toUpdateJSON, { spaces: 2 })
167 167
168 reloadConfig() 168 reloadConfig()
169 ClientHtml.invalidCache() 169 ClientHtml.invalidCache()
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index b2f73fa48..44f15ef74 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -27,8 +27,8 @@ import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model'
27import { VideoChannelModel } from '../../../models/video/video-channel' 27import { VideoChannelModel } from '../../../models/video/video-channel'
28import * as Bluebird from 'bluebird' 28import * as Bluebird from 'bluebird'
29import * as parseTorrent from 'parse-torrent' 29import * as parseTorrent from 'parse-torrent'
30import { readFileBufferPromise, renamePromise } from '../../../helpers/core-utils'
31import { getSecureTorrentName } from '../../../helpers/utils' 30import { getSecureTorrentName } from '../../../helpers/utils'
31import { readFile, rename } from 'fs-extra'
32 32
33const auditLogger = auditLoggerFactory('video-imports') 33const auditLogger = auditLoggerFactory('video-imports')
34const videoImportsRouter = express.Router() 34const videoImportsRouter = express.Router()
@@ -78,10 +78,10 @@ async function addTorrentImport (req: express.Request, res: express.Response, to
78 78
79 // Rename the torrent to a secured name 79 // Rename the torrent to a secured name
80 const newTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, getSecureTorrentName(torrentName)) 80 const newTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, getSecureTorrentName(torrentName))
81 await renamePromise(torrentfile.path, newTorrentPath) 81 await rename(torrentfile.path, newTorrentPath)
82 torrentfile.path = newTorrentPath 82 torrentfile.path = newTorrentPath
83 83
84 const buf = await readFileBufferPromise(torrentfile.path) 84 const buf = await readFile(torrentfile.path)
85 const parsedTorrent = parseTorrent(buf) 85 const parsedTorrent = parseTorrent(buf)
86 86
87 videoName = isArray(parsedTorrent.name) ? parsedTorrent.name[ 0 ] : parsedTorrent.name as string 87 videoName = isArray(parsedTorrent.name) ? parsedTorrent.name[ 0 ] : parsedTorrent.name as string
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index e973aa43f..a86cf4f99 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -1,7 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { extname, join } from 'path' 2import { extname, join } from 'path'
3import { VideoCreate, VideoPrivacy, VideoState, VideoUpdate } from '../../../../shared' 3import { VideoCreate, VideoPrivacy, VideoState, VideoUpdate } from '../../../../shared'
4import { renamePromise } from '../../../helpers/core-utils'
5import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' 4import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils'
6import { processImage } from '../../../helpers/image-utils' 5import { processImage } from '../../../helpers/image-utils'
7import { logger } from '../../../helpers/logger' 6import { logger } from '../../../helpers/logger'
@@ -56,6 +55,7 @@ import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-u
56import { videoCaptionsRouter } from './captions' 55import { videoCaptionsRouter } from './captions'
57import { videoImportsRouter } from './import' 56import { videoImportsRouter } from './import'
58import { resetSequelizeInstance } from '../../../helpers/database-utils' 57import { resetSequelizeInstance } from '../../../helpers/database-utils'
58import { rename } from 'fs-extra'
59 59
60const auditLogger = auditLoggerFactory('videos') 60const auditLogger = auditLoggerFactory('videos')
61const videosRouter = express.Router() 61const videosRouter = express.Router()
@@ -194,7 +194,7 @@ async function addVideo (req: express.Request, res: express.Response) {
194 // Move physical file 194 // Move physical file
195 const videoDir = CONFIG.STORAGE.VIDEOS_DIR 195 const videoDir = CONFIG.STORAGE.VIDEOS_DIR
196 const destination = join(videoDir, video.getVideoFilename(videoFile)) 196 const destination = join(videoDir, video.getVideoFilename(videoFile))
197 await renamePromise(videoPhysicalFile.path, destination) 197 await rename(videoPhysicalFile.path, destination)
198 // This is important in case if there is another attempt in the retry process 198 // This is important in case if there is another attempt in the retry process
199 videoPhysicalFile.filename = video.getVideoFilename(videoFile) 199 videoPhysicalFile.filename = video.getVideoFilename(videoFile)
200 videoPhysicalFile.path = destination 200 videoPhysicalFile.path = destination
diff --git a/server/helpers/captions-utils.ts b/server/helpers/captions-utils.ts
index 20c9fe5aa..660dce65c 100644
--- a/server/helpers/captions-utils.ts
+++ b/server/helpers/captions-utils.ts
@@ -1,9 +1,8 @@
1import { renamePromise, unlinkPromise } from './core-utils'
2import { join } from 'path' 1import { join } from 'path'
3import { CONFIG } from '../initializers' 2import { CONFIG } from '../initializers'
4import { VideoCaptionModel } from '../models/video/video-caption' 3import { VideoCaptionModel } from '../models/video/video-caption'
5import * as srt2vtt from 'srt-to-vtt' 4import * as srt2vtt from 'srt-to-vtt'
6import { createReadStream, createWriteStream } from 'fs-extra' 5import { createReadStream, createWriteStream, remove, rename } from 'fs-extra'
7 6
8async function moveAndProcessCaptionFile (physicalFile: { filename: string, path: string }, videoCaption: VideoCaptionModel) { 7async function moveAndProcessCaptionFile (physicalFile: { filename: string, path: string }, videoCaption: VideoCaptionModel) {
9 const videoCaptionsDir = CONFIG.STORAGE.CAPTIONS_DIR 8 const videoCaptionsDir = CONFIG.STORAGE.CAPTIONS_DIR
@@ -12,9 +11,9 @@ async function moveAndProcessCaptionFile (physicalFile: { filename: string, path
12 // Convert this srt file to vtt 11 // Convert this srt file to vtt
13 if (physicalFile.path.endsWith('.srt')) { 12 if (physicalFile.path.endsWith('.srt')) {
14 await convertSrtToVtt(physicalFile.path, destination) 13 await convertSrtToVtt(physicalFile.path, destination)
15 await unlinkPromise(physicalFile.path) 14 await remove(physicalFile.path)
16 } else { // Just move the vtt file 15 } else { // Just move the vtt file
17 await renamePromise(physicalFile.path, destination) 16 await rename(physicalFile.path, destination)
18 } 17 }
19 18
20 // This is important in case if there is another attempt in the retry process 19 // This is important in case if there is another attempt in the retry process
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts
index 9830d41a8..f5ef187fe 100644
--- a/server/helpers/core-utils.ts
+++ b/server/helpers/core-utils.ts
@@ -6,7 +6,6 @@
6import * as bcrypt from 'bcrypt' 6import * as bcrypt from 'bcrypt'
7import * as createTorrent from 'create-torrent' 7import * as createTorrent from 'create-torrent'
8import { createHash, pseudoRandomBytes } from 'crypto' 8import { createHash, pseudoRandomBytes } from 'crypto'
9import { copyFile, readdir, readFile, rename, stat, Stats, unlink, writeFile, mkdirp } from 'fs-extra'
10import { isAbsolute, join } from 'path' 9import { isAbsolute, join } from 'path'
11import * as pem from 'pem' 10import * as pem from 'pem'
12import * as rimraf from 'rimraf' 11import * as rimraf from 'rimraf'
@@ -168,14 +167,6 @@ function promisify2WithVoid<T, U> (func: (arg1: T, arg2: U, cb: (err: any) => vo
168 } 167 }
169} 168}
170 169
171const copyFilePromise = promisify2WithVoid<string, string>(copyFile)
172const readFileBufferPromise = promisify1<string, Buffer>(readFile)
173const unlinkPromise = promisify1WithVoid<string>(unlink)
174const renamePromise = promisify2WithVoid<string, string>(rename)
175const writeFilePromise = promisify2WithVoid<string, any>(writeFile)
176const readdirPromise = promisify1<string, string[]>(readdir)
177const mkdirpPromise = promisify1<string, string>(mkdirp)
178// we cannot modify the Promise types, so we should make the promisify instance check mkdirp
179const pseudoRandomBytesPromise = promisify1<number, Buffer>(pseudoRandomBytes) 170const pseudoRandomBytesPromise = promisify1<number, Buffer>(pseudoRandomBytes)
180const createPrivateKey = promisify1<number, { key: string }>(pem.createPrivateKey) 171const createPrivateKey = promisify1<number, { key: string }>(pem.createPrivateKey)
181const getPublicKey = promisify1<string, { publicKey: string }>(pem.getPublicKey) 172const getPublicKey = promisify1<string, { publicKey: string }>(pem.getPublicKey)
@@ -183,8 +174,6 @@ const bcryptComparePromise = promisify2<any, string, boolean>(bcrypt.compare)
183const bcryptGenSaltPromise = promisify1<number, string>(bcrypt.genSalt) 174const bcryptGenSaltPromise = promisify1<number, string>(bcrypt.genSalt)
184const bcryptHashPromise = promisify2<any, string | number, string>(bcrypt.hash) 175const bcryptHashPromise = promisify2<any, string | number, string>(bcrypt.hash)
185const createTorrentPromise = promisify2<string, any, any>(createTorrent) 176const createTorrentPromise = promisify2<string, any, any>(createTorrent)
186const rimrafPromise = promisify1WithVoid<string>(rimraf)
187const statPromise = promisify1<string, Stats>(stat)
188 177
189// --------------------------------------------------------------------------- 178// ---------------------------------------------------------------------------
190 179
@@ -202,20 +191,11 @@ export {
202 promisify0, 191 promisify0,
203 promisify1, 192 promisify1,
204 193
205 copyFilePromise,
206 readdirPromise,
207 readFileBufferPromise,
208 unlinkPromise,
209 renamePromise,
210 writeFilePromise,
211 mkdirpPromise,
212 pseudoRandomBytesPromise, 194 pseudoRandomBytesPromise,
213 createPrivateKey, 195 createPrivateKey,
214 getPublicKey, 196 getPublicKey,
215 bcryptComparePromise, 197 bcryptComparePromise,
216 bcryptGenSaltPromise, 198 bcryptGenSaltPromise,
217 bcryptHashPromise, 199 bcryptHashPromise,
218 createTorrentPromise, 200 createTorrentPromise
219 rimrafPromise,
220 statPromise
221} 201}
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts
index 8936005e0..7c45f3632 100644
--- a/server/helpers/ffmpeg-utils.ts
+++ b/server/helpers/ffmpeg-utils.ts
@@ -1,11 +1,11 @@
1import * as ffmpeg from 'fluent-ffmpeg' 1import * as ffmpeg from 'fluent-ffmpeg'
2import { join } from 'path' 2import { join } from 'path'
3import { VideoResolution } from '../../shared/models/videos' 3import { VideoResolution } from '../../shared/models/videos'
4import { CONFIG, VIDEO_TRANSCODING_FPS, FFMPEG_NICE } from '../initializers' 4import { CONFIG, FFMPEG_NICE, VIDEO_TRANSCODING_FPS } from '../initializers'
5import { unlinkPromise } from './core-utils'
6import { processImage } from './image-utils' 5import { processImage } from './image-utils'
7import { logger } from './logger' 6import { logger } from './logger'
8import { checkFFmpegEncoders } from '../initializers/checker' 7import { checkFFmpegEncoders } from '../initializers/checker'
8import { remove } from 'fs-extra'
9 9
10function computeResolutionsToTranscode (videoFileHeight: number) { 10function computeResolutionsToTranscode (videoFileHeight: number) {
11 const resolutionsEnabled: number[] = [] 11 const resolutionsEnabled: number[] = []
@@ -90,7 +90,7 @@ async function generateImageFromVideoFile (fromPath: string, folder: string, ima
90 logger.error('Cannot generate image from video %s.', fromPath, { err }) 90 logger.error('Cannot generate image from video %s.', fromPath, { err })
91 91
92 try { 92 try {
93 await unlinkPromise(pendingImagePath) 93 await remove(pendingImagePath)
94 } catch (err) { 94 } catch (err) {
95 logger.debug('Cannot remove pending image path after generation error.', { err }) 95 logger.debug('Cannot remove pending image path after generation error.', { err })
96 } 96 }
diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts
index 0065f4210..3eaa674ed 100644
--- a/server/helpers/image-utils.ts
+++ b/server/helpers/image-utils.ts
@@ -1,6 +1,6 @@
1import 'multer' 1import 'multer'
2import * as sharp from 'sharp' 2import * as sharp from 'sharp'
3import { unlinkPromise } from './core-utils' 3import { remove } from 'fs-extra'
4 4
5async function processImage ( 5async function processImage (
6 physicalFile: { path: string }, 6 physicalFile: { path: string },
@@ -11,7 +11,7 @@ async function processImage (
11 .resize(newSize.width, newSize.height) 11 .resize(newSize.width, newSize.height)
12 .toFile(destination) 12 .toFile(destination)
13 13
14 await unlinkPromise(physicalFile.path) 14 await remove(physicalFile.path)
15} 15}
16 16
17// --------------------------------------------------------------------------- 17// ---------------------------------------------------------------------------
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts
index 703e57887..a1ed8e72d 100644
--- a/server/helpers/utils.ts
+++ b/server/helpers/utils.ts
@@ -2,13 +2,14 @@ import { ResultList } from '../../shared'
2import { CONFIG } from '../initializers' 2import { CONFIG } from '../initializers'
3import { ActorModel } from '../models/activitypub/actor' 3import { ActorModel } from '../models/activitypub/actor'
4import { ApplicationModel } from '../models/application/application' 4import { ApplicationModel } from '../models/application/application'
5import { pseudoRandomBytesPromise, sha256, unlinkPromise } from './core-utils' 5import { pseudoRandomBytesPromise, sha256 } from './core-utils'
6import { logger } from './logger' 6import { logger } from './logger'
7import { join } from 'path' 7import { join } from 'path'
8import { Instance as ParseTorrent } from 'parse-torrent' 8import { Instance as ParseTorrent } from 'parse-torrent'
9import { remove } from 'fs-extra'
9 10
10function deleteFileAsync (path: string) { 11function deleteFileAsync (path: string) {
11 unlinkPromise(path) 12 remove(path)
12 .catch(err => logger.error('Cannot delete the file %s asynchronously.', path, { err })) 13 .catch(err => logger.error('Cannot delete the file %s asynchronously.', path, { err }))
13} 14}
14 15
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts
index 1c0d00d70..1c0cc7058 100644
--- a/server/helpers/webtorrent.ts
+++ b/server/helpers/webtorrent.ts
@@ -1,10 +1,9 @@
1import { logger } from './logger' 1import { logger } from './logger'
2import { generateVideoTmpPath } from './utils' 2import { generateVideoTmpPath } from './utils'
3import * as WebTorrent from 'webtorrent' 3import * as WebTorrent from 'webtorrent'
4import { createWriteStream } from 'fs-extra' 4import { createWriteStream, remove } from 'fs-extra'
5import { CONFIG } from '../initializers' 5import { CONFIG } from '../initializers'
6import { join } from 'path' 6import { join } from 'path'
7import { unlinkPromise } from './core-utils'
8 7
9function downloadWebTorrentVideo (target: { magnetUri: string, torrentName: string }) { 8function downloadWebTorrentVideo (target: { magnetUri: string, torrentName: string }) {
10 const id = target.magnetUri || target.torrentName 9 const id = target.magnetUri || target.torrentName
@@ -29,11 +28,11 @@ function downloadWebTorrentVideo (target: { magnetUri: string, torrentName: stri
29 if (err) return rej(err) 28 if (err) return rej(err)
30 29
31 if (target.torrentName) { 30 if (target.torrentName) {
32 unlinkPromise(torrentId) 31 remove(torrentId)
33 .catch(err => logger.error('Cannot remove torrent %s in webtorrent download.', torrentId, { err })) 32 .catch(err => logger.error('Cannot remove torrent %s in webtorrent download.', torrentId, { err }))
34 } 33 }
35 34
36 unlinkPromise(join(CONFIG.STORAGE.VIDEOS_DIR, file.name)) 35 remove(join(CONFIG.STORAGE.VIDEOS_DIR, file.name))
37 .catch(err => logger.error('Cannot remove torrent file %s in webtorrent download.', file.name, { err })) 36 .catch(err => logger.error('Cannot remove torrent file %s in webtorrent download.', file.name, { err }))
38 37
39 res(path) 38 res(path)
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
diff --git a/server/lib/cache/abstract-video-static-file-cache.ts b/server/lib/cache/abstract-video-static-file-cache.ts
index 3e20c5d2a..7512f2b9d 100644
--- a/server/lib/cache/abstract-video-static-file-cache.ts
+++ b/server/lib/cache/abstract-video-static-file-cache.ts
@@ -1,6 +1,5 @@
1import * as AsyncLRU from 'async-lru' 1import * as AsyncLRU from 'async-lru'
2import { createWriteStream } from 'fs-extra' 2import { createWriteStream, remove } from 'fs-extra'
3import { unlinkPromise } from '../../helpers/core-utils'
4import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
5import { VideoModel } from '../../models/video/video' 4import { VideoModel } from '../../models/video/video'
6import { fetchRemoteVideoStaticFile } from '../activitypub' 5import { fetchRemoteVideoStaticFile } from '../activitypub'
@@ -26,7 +25,7 @@ export abstract class AbstractVideoStaticFileCache <T> {
26 }) 25 })
27 26
28 this.lru.on('evict', (obj: { key: string, value: string }) => { 27 this.lru.on('evict', (obj: { key: string, value: string }) => {
29 unlinkPromise(obj.value) 28 remove(obj.value)
30 .then(() => logger.debug('%s evicted from %s', obj.value, this.constructor.name)) 29 .then(() => logger.debug('%s evicted from %s', obj.value, this.constructor.name))
31 }) 30 })
32 } 31 }
diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts
index 72984e778..a69e09c32 100644
--- a/server/lib/client-html.ts
+++ b/server/lib/client-html.ts
@@ -1,12 +1,13 @@
1import * as express from 'express' 1import * as express from 'express'
2import * as Bluebird from 'bluebird' 2import * as Bluebird from 'bluebird'
3import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/models/i18n/i18n' 3import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/models/i18n/i18n'
4import { CONFIG, EMBED_SIZE, CUSTOM_HTML_TAG_COMMENTS, STATIC_PATHS } from '../initializers' 4import { CONFIG, CUSTOM_HTML_TAG_COMMENTS, EMBED_SIZE, STATIC_PATHS } from '../initializers'
5import { join } from 'path' 5import { join } from 'path'
6import { escapeHTML, readFileBufferPromise } from '../helpers/core-utils' 6import { escapeHTML } from '../helpers/core-utils'
7import { VideoModel } from '../models/video/video' 7import { VideoModel } from '../models/video/video'
8import * as validator from 'validator' 8import * as validator from 'validator'
9import { VideoPrivacy } from '../../shared/models/videos' 9import { VideoPrivacy } from '../../shared/models/videos'
10import { readFile } from 'fs-extra'
10 11
11export class ClientHtml { 12export class ClientHtml {
12 13
@@ -20,7 +21,7 @@ export class ClientHtml {
20 const path = ClientHtml.getIndexPath(req, res, paramLang) 21 const path = ClientHtml.getIndexPath(req, res, paramLang)
21 if (ClientHtml.htmlCache[path]) return ClientHtml.htmlCache[path] 22 if (ClientHtml.htmlCache[path]) return ClientHtml.htmlCache[path]
22 23
23 const buffer = await readFileBufferPromise(path) 24 const buffer = await readFile(path)
24 25
25 let html = buffer.toString() 26 let html = buffer.toString()
26 27
diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts
index d6984ef92..ebcb2090c 100644
--- a/server/lib/job-queue/handlers/video-import.ts
+++ b/server/lib/job-queue/handlers/video-import.ts
@@ -6,7 +6,6 @@ import { VideoImportState } from '../../../../shared/models/videos'
6import { getDurationFromVideoFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' 6import { getDurationFromVideoFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils'
7import { extname, join } from 'path' 7import { extname, join } from 'path'
8import { VideoFileModel } from '../../../models/video/video-file' 8import { VideoFileModel } from '../../../models/video/video-file'
9import { renamePromise, statPromise, unlinkPromise } from '../../../helpers/core-utils'
10import { CONFIG, sequelizeTypescript } from '../../../initializers' 9import { CONFIG, sequelizeTypescript } from '../../../initializers'
11import { doRequestAndSaveToFile } from '../../../helpers/requests' 10import { doRequestAndSaveToFile } from '../../../helpers/requests'
12import { VideoState } from '../../../../shared' 11import { VideoState } from '../../../../shared'
@@ -15,6 +14,7 @@ import { federateVideoIfNeeded } from '../../activitypub'
15import { VideoModel } from '../../../models/video/video' 14import { VideoModel } from '../../../models/video/video'
16import { downloadWebTorrentVideo } from '../../../helpers/webtorrent' 15import { downloadWebTorrentVideo } from '../../../helpers/webtorrent'
17import { getSecureTorrentName } from '../../../helpers/utils' 16import { getSecureTorrentName } from '../../../helpers/utils'
17import { rename, stat } from 'fs-extra'
18 18
19type VideoImportYoutubeDLPayload = { 19type VideoImportYoutubeDLPayload = {
20 type: 'youtube-dl' 20 type: 'youtube-dl'
@@ -114,7 +114,7 @@ async function processFile (downloader: () => Promise<string>, videoImport: Vide
114 tempVideoPath = await downloader() 114 tempVideoPath = await downloader()
115 115
116 // Get information about this video 116 // Get information about this video
117 const stats = await statPromise(tempVideoPath) 117 const stats = await stat(tempVideoPath)
118 const isAble = await videoImport.User.isAbleToUploadVideo({ size: stats.size }) 118 const isAble = await videoImport.User.isAbleToUploadVideo({ size: stats.size })
119 if (isAble === false) { 119 if (isAble === false) {
120 throw new Error('The user video quota is exceeded with this video to import.') 120 throw new Error('The user video quota is exceeded with this video to import.')
@@ -138,7 +138,7 @@ async function processFile (downloader: () => Promise<string>, videoImport: Vide
138 138
139 // Move file 139 // Move file
140 videoDestFile = join(CONFIG.STORAGE.VIDEOS_DIR, videoImport.Video.getVideoFilename(videoFile)) 140 videoDestFile = join(CONFIG.STORAGE.VIDEOS_DIR, videoImport.Video.getVideoFilename(videoFile))
141 await renamePromise(tempVideoPath, videoDestFile) 141 await rename(tempVideoPath, videoDestFile)
142 tempVideoPath = null // This path is not used anymore 142 tempVideoPath = null // This path is not used anymore
143 143
144 // Process thumbnail 144 // Process thumbnail
diff --git a/server/lib/schedulers/youtube-dl-update-scheduler.ts b/server/lib/schedulers/youtube-dl-update-scheduler.ts
index da47378e8..faadb4334 100644
--- a/server/lib/schedulers/youtube-dl-update-scheduler.ts
+++ b/server/lib/schedulers/youtube-dl-update-scheduler.ts
@@ -5,9 +5,9 @@ import { AbstractScheduler } from './abstract-scheduler'
5import { SCHEDULER_INTERVALS_MS } from '../../initializers' 5import { SCHEDULER_INTERVALS_MS } from '../../initializers'
6import { logger } from '../../helpers/logger' 6import { logger } from '../../helpers/logger'
7import * as request from 'request' 7import * as request from 'request'
8import { createWriteStream, writeFile } from 'fs-extra' 8import { createWriteStream, ensureDir, writeFile } from 'fs-extra'
9import { join } from 'path' 9import { join } from 'path'
10import { mkdirpPromise, root } from '../../helpers/core-utils' 10import { root } from '../../helpers/core-utils'
11 11
12export class YoutubeDlUpdateScheduler extends AbstractScheduler { 12export class YoutubeDlUpdateScheduler extends AbstractScheduler {
13 13
@@ -27,7 +27,7 @@ export class YoutubeDlUpdateScheduler extends AbstractScheduler {
27 const detailsPath = join(binDirectory, 'details') 27 const detailsPath = join(binDirectory, 'details')
28 const url = 'https://yt-dl.org/downloads/latest/youtube-dl' 28 const url = 'https://yt-dl.org/downloads/latest/youtube-dl'
29 29
30 await mkdirpPromise(binDirectory) 30 await ensureDir(binDirectory)
31 31
32 return new Promise(res => { 32 return new Promise(res => {
33 request.get(url, { followRedirect: false }, (err, result) => { 33 request.get(url, { followRedirect: false }, (err, result) => {
diff --git a/server/models/avatar/avatar.ts b/server/models/avatar/avatar.ts
index 51e26c87b..5d73e24fa 100644
--- a/server/models/avatar/avatar.ts
+++ b/server/models/avatar/avatar.ts
@@ -1,9 +1,9 @@
1import { join } from 'path' 1import { join } from 'path'
2import { AfterDestroy, AllowNull, Column, CreatedAt, Model, Table, UpdatedAt } from 'sequelize-typescript' 2import { AfterDestroy, AllowNull, Column, CreatedAt, Model, Table, UpdatedAt } from 'sequelize-typescript'
3import { Avatar } from '../../../shared/models/avatars/avatar.model' 3import { Avatar } from '../../../shared/models/avatars/avatar.model'
4import { unlinkPromise } from '../../helpers/core-utils'
5import { CONFIG, STATIC_PATHS } from '../../initializers' 4import { CONFIG, STATIC_PATHS } from '../../initializers'
6import { logger } from '../../helpers/logger' 5import { logger } from '../../helpers/logger'
6import { remove } from 'fs-extra'
7 7
8@Table({ 8@Table({
9 tableName: 'avatar' 9 tableName: 'avatar'
@@ -40,6 +40,6 @@ export class AvatarModel extends Model<AvatarModel> {
40 40
41 removeAvatar () { 41 removeAvatar () {
42 const avatarPath = join(CONFIG.STORAGE.AVATARS_DIR, this.filename) 42 const avatarPath = join(CONFIG.STORAGE.AVATARS_DIR, this.filename)
43 return unlinkPromise(avatarPath) 43 return remove(avatarPath)
44 } 44 }
45} 45}
diff --git a/server/models/video/video-caption.ts b/server/models/video/video-caption.ts
index 3593646a2..10ef46c14 100644
--- a/server/models/video/video-caption.ts
+++ b/server/models/video/video-caption.ts
@@ -19,7 +19,7 @@ import { VideoCaption } from '../../../shared/models/videos/caption/video-captio
19import { CONFIG, STATIC_PATHS, VIDEO_LANGUAGES } from '../../initializers' 19import { CONFIG, STATIC_PATHS, VIDEO_LANGUAGES } from '../../initializers'
20import { join } from 'path' 20import { join } from 'path'
21import { logger } from '../../helpers/logger' 21import { logger } from '../../helpers/logger'
22import { unlinkPromise } from '../../helpers/core-utils' 22import { remove } from 'fs-extra'
23 23
24export enum ScopeNames { 24export enum ScopeNames {
25 WITH_VIDEO_UUID_AND_REMOTE = 'WITH_VIDEO_UUID_AND_REMOTE' 25 WITH_VIDEO_UUID_AND_REMOTE = 'WITH_VIDEO_UUID_AND_REMOTE'
@@ -172,6 +172,6 @@ export class VideoCaptionModel extends Model<VideoCaptionModel> {
172 } 172 }
173 173
174 removeCaptionFile () { 174 removeCaptionFile () {
175 return unlinkPromise(CONFIG.STORAGE.CAPTIONS_DIR + this.getCaptionName()) 175 return remove(CONFIG.STORAGE.CAPTIONS_DIR + this.getCaptionName())
176 } 176 }
177} 177}
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index a956da16e..6271db1b3 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -30,15 +30,7 @@ import { VideoPrivacy, VideoResolution, VideoState } from '../../../shared'
30import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' 30import { VideoTorrentObject } from '../../../shared/models/activitypub/objects'
31import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos' 31import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos'
32import { VideoFilter } from '../../../shared/models/videos/video-query.type' 32import { VideoFilter } from '../../../shared/models/videos/video-query.type'
33import { 33import { createTorrentPromise, peertubeTruncate } from '../../helpers/core-utils'
34 copyFilePromise,
35 createTorrentPromise,
36 peertubeTruncate,
37 renamePromise,
38 statPromise,
39 unlinkPromise,
40 writeFilePromise
41} from '../../helpers/core-utils'
42import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 34import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
43import { isBooleanValid } from '../../helpers/custom-validators/misc' 35import { isBooleanValid } from '../../helpers/custom-validators/misc'
44import { 36import {
@@ -95,6 +87,7 @@ import { VideoTagModel } from './video-tag'
95import { ScheduleVideoUpdateModel } from './schedule-video-update' 87import { ScheduleVideoUpdateModel } from './schedule-video-update'
96import { VideoCaptionModel } from './video-caption' 88import { VideoCaptionModel } from './video-caption'
97import { VideoBlacklistModel } from './video-blacklist' 89import { VideoBlacklistModel } from './video-blacklist'
90import { copy, remove, rename, stat, writeFile } from 'fs-extra'
98 91
99// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation 92// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation
100const indexes: Sequelize.DefineIndexesOptions[] = [ 93const indexes: Sequelize.DefineIndexesOptions[] = [
@@ -1187,7 +1180,7 @@ export class VideoModel extends Model<VideoModel> {
1187 const filePath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile)) 1180 const filePath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile))
1188 logger.info('Creating torrent %s.', filePath) 1181 logger.info('Creating torrent %s.', filePath)
1189 1182
1190 await writeFilePromise(filePath, torrent) 1183 await writeFile(filePath, torrent)
1191 1184
1192 const parsedTorrent = parseTorrent(torrent) 1185 const parsedTorrent = parseTorrent(torrent)
1193 videoFile.infoHash = parsedTorrent.infoHash 1186 videoFile.infoHash = parsedTorrent.infoHash
@@ -1497,14 +1490,14 @@ export class VideoModel extends Model<VideoModel> {
1497 await transcode(transcodeOptions) 1490 await transcode(transcodeOptions)
1498 1491
1499 try { 1492 try {
1500 await unlinkPromise(videoInputPath) 1493 await remove(videoInputPath)
1501 1494
1502 // Important to do this before getVideoFilename() to take in account the new file extension 1495 // Important to do this before getVideoFilename() to take in account the new file extension
1503 inputVideoFile.set('extname', newExtname) 1496 inputVideoFile.set('extname', newExtname)
1504 1497
1505 const videoOutputPath = this.getVideoFilePath(inputVideoFile) 1498 const videoOutputPath = this.getVideoFilePath(inputVideoFile)
1506 await renamePromise(videoTranscodedPath, videoOutputPath) 1499 await rename(videoTranscodedPath, videoOutputPath)
1507 const stats = await statPromise(videoOutputPath) 1500 const stats = await stat(videoOutputPath)
1508 const fps = await getVideoFileFPS(videoOutputPath) 1501 const fps = await getVideoFileFPS(videoOutputPath)
1509 1502
1510 inputVideoFile.set('size', stats.size) 1503 inputVideoFile.set('size', stats.size)
@@ -1545,7 +1538,7 @@ export class VideoModel extends Model<VideoModel> {
1545 1538
1546 await transcode(transcodeOptions) 1539 await transcode(transcodeOptions)
1547 1540
1548 const stats = await statPromise(videoOutputPath) 1541 const stats = await stat(videoOutputPath)
1549 const fps = await getVideoFileFPS(videoOutputPath) 1542 const fps = await getVideoFileFPS(videoOutputPath)
1550 1543
1551 newVideoFile.set('size', stats.size) 1544 newVideoFile.set('size', stats.size)
@@ -1560,7 +1553,7 @@ export class VideoModel extends Model<VideoModel> {
1560 1553
1561 async importVideoFile (inputFilePath: string) { 1554 async importVideoFile (inputFilePath: string) {
1562 const { videoFileResolution } = await getVideoFileResolution(inputFilePath) 1555 const { videoFileResolution } = await getVideoFileResolution(inputFilePath)
1563 const { size } = await statPromise(inputFilePath) 1556 const { size } = await stat(inputFilePath)
1564 const fps = await getVideoFileFPS(inputFilePath) 1557 const fps = await getVideoFileFPS(inputFilePath)
1565 1558
1566 let updatedVideoFile = new VideoFileModel({ 1559 let updatedVideoFile = new VideoFileModel({
@@ -1589,7 +1582,7 @@ export class VideoModel extends Model<VideoModel> {
1589 } 1582 }
1590 1583
1591 const outputPath = this.getVideoFilePath(updatedVideoFile) 1584 const outputPath = this.getVideoFilePath(updatedVideoFile)
1592 await copyFilePromise(inputFilePath, outputPath) 1585 await copy(inputFilePath, outputPath)
1593 1586
1594 await this.createTorrentAndSetInfoHash(updatedVideoFile) 1587 await this.createTorrentAndSetInfoHash(updatedVideoFile)
1595 1588
@@ -1610,25 +1603,25 @@ export class VideoModel extends Model<VideoModel> {
1610 1603
1611 removeThumbnail () { 1604 removeThumbnail () {
1612 const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName()) 1605 const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName())
1613 return unlinkPromise(thumbnailPath) 1606 return remove(thumbnailPath)
1614 .catch(err => logger.warn('Cannot delete thumbnail %s.', thumbnailPath, { err })) 1607 .catch(err => logger.warn('Cannot delete thumbnail %s.', thumbnailPath, { err }))
1615 } 1608 }
1616 1609
1617 removePreview () { 1610 removePreview () {
1618 const previewPath = join(CONFIG.STORAGE.PREVIEWS_DIR + this.getPreviewName()) 1611 const previewPath = join(CONFIG.STORAGE.PREVIEWS_DIR + this.getPreviewName())
1619 return unlinkPromise(previewPath) 1612 return remove(previewPath)
1620 .catch(err => logger.warn('Cannot delete preview %s.', previewPath, { err })) 1613 .catch(err => logger.warn('Cannot delete preview %s.', previewPath, { err }))
1621 } 1614 }
1622 1615
1623 removeFile (videoFile: VideoFileModel) { 1616 removeFile (videoFile: VideoFileModel) {
1624 const filePath = join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile)) 1617 const filePath = join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile))
1625 return unlinkPromise(filePath) 1618 return remove(filePath)
1626 .catch(err => logger.warn('Cannot delete file %s.', filePath, { err })) 1619 .catch(err => logger.warn('Cannot delete file %s.', filePath, { err }))
1627 } 1620 }
1628 1621
1629 removeTorrent (videoFile: VideoFileModel) { 1622 removeTorrent (videoFile: VideoFileModel) {
1630 const torrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile)) 1623 const torrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile))
1631 return unlinkPromise(torrentPath) 1624 return remove(torrentPath)
1632 .catch(err => logger.warn('Cannot delete torrent %s.', torrentPath, { err })) 1625 .catch(err => logger.warn('Cannot delete torrent %s.', torrentPath, { err }))
1633 } 1626 }
1634 1627
diff --git a/server/tests/feeds/feeds.ts b/server/tests/feeds/feeds.ts
index 90450a0bb..72c9bf9a0 100644
--- a/server/tests/feeds/feeds.ts
+++ b/server/tests/feeds/feeds.ts
@@ -13,7 +13,6 @@ import {
13 setAccessTokensToServers, 13 setAccessTokensToServers,
14 uploadVideo 14 uploadVideo
15} from '../utils' 15} from '../utils'
16import { join } from 'path'
17import * as libxmljs from 'libxmljs' 16import * as libxmljs from 'libxmljs'
18import { addVideoCommentThread } from '../utils/videos/video-comments' 17import { addVideoCommentThread } from '../utils/videos/video-comments'
19import { waitJobs } from '../utils/server/jobs' 18import { waitJobs } from '../utils/server/jobs'
diff --git a/server/tests/utils/feeds/feeds.ts b/server/tests/utils/feeds/feeds.ts
index ffd23a1ad..fb480b704 100644
--- a/server/tests/utils/feeds/feeds.ts
+++ b/server/tests/utils/feeds/feeds.ts
@@ -1,5 +1,4 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { readFileBufferPromise } from '../../../helpers/core-utils'
3 2
4type FeedType = 'videos' | 'video-comments' 3type FeedType = 'videos' | 'video-comments'
5 4
diff --git a/server/tests/utils/miscs/miscs.ts b/server/tests/utils/miscs/miscs.ts
index b0667491b..b2f80e9b1 100644
--- a/server/tests/utils/miscs/miscs.ts
+++ b/server/tests/utils/miscs/miscs.ts
@@ -4,7 +4,7 @@ import * as chai from 'chai'
4import { isAbsolute, join } from 'path' 4import { isAbsolute, join } from 'path'
5import * as request from 'supertest' 5import * as request from 'supertest'
6import * as WebTorrent from 'webtorrent' 6import * as WebTorrent from 'webtorrent'
7import { readFileBufferPromise } from '../../../helpers/core-utils' 7import { readFile } from 'fs-extra'
8 8
9const expect = chai.expect 9const expect = chai.expect
10let webtorrent = new WebTorrent() 10let webtorrent = new WebTorrent()
@@ -43,7 +43,7 @@ async function testImage (url: string, imageName: string, imagePath: string, ext
43 43
44 const body = res.body 44 const body = res.body
45 45
46 const data = await readFileBufferPromise(join(__dirname, '..', '..', 'fixtures', imageName + extension)) 46 const data = await readFile(join(__dirname, '..', '..', 'fixtures', imageName + extension))
47 const minLength = body.length - ((20 * body.length) / 100) 47 const minLength = body.length - ((20 * body.length) / 100)
48 const maxLength = body.length + ((20 * body.length) / 100) 48 const maxLength = body.length + ((20 * body.length) / 100)
49 49
diff --git a/server/tests/utils/users/accounts.ts b/server/tests/utils/users/accounts.ts
index 024a315c7..f82b8d906 100644
--- a/server/tests/utils/users/accounts.ts
+++ b/server/tests/utils/users/accounts.ts
@@ -1,10 +1,9 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { existsSync } from 'fs-extra' 4import { existsSync, readdir } from 'fs-extra'
5import { join } from 'path' 5import { join } from 'path'
6import { Account } from '../../../../shared/models/actors' 6import { Account } from '../../../../shared/models/actors'
7import { readdirPromise } from '../../../helpers/core-utils'
8import { root } from '../index' 7import { root } from '../index'
9import { makeGetRequest } from '../requests/requests' 8import { makeGetRequest } from '../requests/requests'
10 9
@@ -47,7 +46,7 @@ async function checkActorFilesWereRemoved (actorUUID: string, serverNumber: numb
47 const directoryExists = existsSync(directoryPath) 46 const directoryExists = existsSync(directoryPath)
48 expect(directoryExists).to.be.true 47 expect(directoryExists).to.be.true
49 48
50 const files = await readdirPromise(directoryPath) 49 const files = await readdir(directoryPath)
51 for (const file of files) { 50 for (const file of files) {
52 expect(file).to.not.contain(actorUUID) 51 expect(file).to.not.contain(actorUUID)
53 } 52 }
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts
index 973bbbe87..7eee25402 100644
--- a/server/tests/utils/videos/videos.ts
+++ b/server/tests/utils/videos/videos.ts
@@ -1,13 +1,14 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { existsSync, readFile } from 'fs-extra' 4import { existsSync, readdir, readFile } from 'fs-extra'
5import * as parseTorrent from 'parse-torrent' 5import * as parseTorrent from 'parse-torrent'
6import { extname, join } from 'path' 6import { extname, join } from 'path'
7import * as request from 'supertest' 7import * as request from 'supertest'
8import { 8import {
9 buildAbsoluteFixturePath, 9 buildAbsoluteFixturePath,
10 getMyUserInformation, immutableAssign, 10 getMyUserInformation,
11 immutableAssign,
11 makeGetRequest, 12 makeGetRequest,
12 makePutBodyRequest, 13 makePutBodyRequest,
13 makeUploadRequest, 14 makeUploadRequest,
@@ -16,7 +17,6 @@ import {
16 testImage 17 testImage
17} from '../' 18} from '../'
18import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos' 19import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos'
19import { readdirPromise } from '../../../helpers/core-utils'
20import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' 20import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers'
21import { dateIsValid, webtorrentAdd } from '../index' 21import { dateIsValid, webtorrentAdd } from '../index'
22 22
@@ -276,7 +276,7 @@ async function checkVideoFilesWereRemoved (videoUUID: string, serverNumber: numb
276 const directoryExists = existsSync(directoryPath) 276 const directoryExists = existsSync(directoryPath)
277 expect(directoryExists).to.be.true 277 expect(directoryExists).to.be.true
278 278
279 const files = await readdirPromise(directoryPath) 279 const files = await readdir(directoryPath)
280 for (const file of files) { 280 for (const file of files) {
281 expect(file).to.not.contain(videoUUID) 281 expect(file).to.not.contain(videoUUID)
282 } 282 }
diff --git a/server/tools/import-videos.ts b/server/tools/import-videos.ts
index e49fbb2f5..812600f8b 100644
--- a/server/tools/import-videos.ts
+++ b/server/tools/import-videos.ts
@@ -5,12 +5,12 @@ import * as program from 'commander'
5import { join } from 'path' 5import { join } from 'path'
6import * as youtubeDL from 'youtube-dl' 6import * as youtubeDL from 'youtube-dl'
7import { VideoPrivacy } from '../../shared/models/videos' 7import { VideoPrivacy } from '../../shared/models/videos'
8import { unlinkPromise } from '../helpers/core-utils'
9import { doRequestAndSaveToFile } from '../helpers/requests' 8import { doRequestAndSaveToFile } from '../helpers/requests'
10import { CONSTRAINTS_FIELDS } from '../initializers' 9import { CONSTRAINTS_FIELDS } from '../initializers'
11import { getClient, getVideoCategories, login, searchVideo, uploadVideo } from '../tests/utils' 10import { getClient, getVideoCategories, login, searchVideo, uploadVideo } from '../tests/utils'
12import { truncate } from 'lodash' 11import { truncate } from 'lodash'
13import * as prompt from 'prompt' 12import * as prompt from 'prompt'
13import { remove } from 'fs-extra'
14 14
15program 15program
16 .option('-u, --url <url>', 'Server url') 16 .option('-u, --url <url>', 'Server url')
@@ -204,10 +204,8 @@ async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string, languag
204 } 204 }
205 } 205 }
206 206
207 await unlinkPromise(videoPath) 207 await remove(videoPath)
208 if (thumbnailfile) { 208 if (thumbnailfile) await remove(thumbnailfile)
209 await unlinkPromise(thumbnailfile)
210 }
211 209
212 console.log('Uploaded video "%s"!\n', videoAttributes.name) 210 console.log('Uploaded video "%s"!\n', videoAttributes.name)
213} 211}
diff --git a/server/tools/upload.ts b/server/tools/upload.ts
index b5630bb9c..796a0f723 100644
--- a/server/tools/upload.ts
+++ b/server/tools/upload.ts
@@ -1,13 +1,10 @@
1import * as program from 'commander' 1import * as program from 'commander'
2import { access, constants } from 'fs-extra' 2import { access, constants } from 'fs-extra'
3import { isAbsolute } from 'path' 3import { isAbsolute } from 'path'
4import { promisify } from 'util'
5import { getClient, login } from '../tests/utils' 4import { getClient, login } from '../tests/utils'
6import { uploadVideo } from '../tests/utils/index' 5import { uploadVideo } from '../tests/utils/index'
7import { VideoPrivacy } from '../../shared/models/videos' 6import { VideoPrivacy } from '../../shared/models/videos'
8 7
9const accessPromise = promisify(access)
10
11program 8program
12 .option('-u, --url <url>', 'Server url') 9 .option('-u, --url <url>', 'Server url')
13 .option('-U, --username <username>', 'Username') 10 .option('-U, --username <username>', 'Username')
@@ -68,7 +65,7 @@ async function run () {
68 const res2 = await login(program[ 'url' ], client, user) 65 const res2 = await login(program[ 'url' ], client, user)
69 const accessToken = res2.body.access_token 66 const accessToken = res2.body.access_token
70 67
71 await accessPromise(program[ 'file' ], constants.F_OK) 68 await access(program[ 'file' ], constants.F_OK)
72 69
73 console.log('Uploading %s video...', program[ 'videoName' ]) 70 console.log('Uploading %s video...', program[ 'videoName' ])
74 71