aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-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
6 files changed, 15 insertions, 36 deletions
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)