diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-27 16:23:34 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-27 16:23:34 +0200 |
commit | 62689b942b71cd1dd0d050c6ed05f884a0b325c2 (patch) | |
tree | c45c35d35d7a3e32621fba06edc63646930c8efd /server/helpers | |
parent | 84b6dbcc6e8654f39ec798905e1151ba915cd1aa (diff) | |
download | PeerTube-62689b942b71cd1dd0d050c6ed05f884a0b325c2.tar.gz PeerTube-62689b942b71cd1dd0d050c6ed05f884a0b325c2.tar.zst PeerTube-62689b942b71cd1dd0d050c6ed05f884a0b325c2.zip |
Correctly migrate to fs-extra
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/captions-utils.ts | 7 | ||||
-rw-r--r-- | server/helpers/core-utils.ts | 22 | ||||
-rw-r--r-- | server/helpers/ffmpeg-utils.ts | 6 | ||||
-rw-r--r-- | server/helpers/image-utils.ts | 4 | ||||
-rw-r--r-- | server/helpers/utils.ts | 5 | ||||
-rw-r--r-- | server/helpers/webtorrent.ts | 7 |
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 @@ | |||
1 | import { renamePromise, unlinkPromise } from './core-utils' | ||
2 | import { join } from 'path' | 1 | import { join } from 'path' |
3 | import { CONFIG } from '../initializers' | 2 | import { CONFIG } from '../initializers' |
4 | import { VideoCaptionModel } from '../models/video/video-caption' | 3 | import { VideoCaptionModel } from '../models/video/video-caption' |
5 | import * as srt2vtt from 'srt-to-vtt' | 4 | import * as srt2vtt from 'srt-to-vtt' |
6 | import { createReadStream, createWriteStream } from 'fs-extra' | 5 | import { createReadStream, createWriteStream, remove, rename } from 'fs-extra' |
7 | 6 | ||
8 | async function moveAndProcessCaptionFile (physicalFile: { filename: string, path: string }, videoCaption: VideoCaptionModel) { | 7 | async 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 @@ | |||
6 | import * as bcrypt from 'bcrypt' | 6 | import * as bcrypt from 'bcrypt' |
7 | import * as createTorrent from 'create-torrent' | 7 | import * as createTorrent from 'create-torrent' |
8 | import { createHash, pseudoRandomBytes } from 'crypto' | 8 | import { createHash, pseudoRandomBytes } from 'crypto' |
9 | import { copyFile, readdir, readFile, rename, stat, Stats, unlink, writeFile, mkdirp } from 'fs-extra' | ||
10 | import { isAbsolute, join } from 'path' | 9 | import { isAbsolute, join } from 'path' |
11 | import * as pem from 'pem' | 10 | import * as pem from 'pem' |
12 | import * as rimraf from 'rimraf' | 11 | import * 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 | ||
171 | const copyFilePromise = promisify2WithVoid<string, string>(copyFile) | ||
172 | const readFileBufferPromise = promisify1<string, Buffer>(readFile) | ||
173 | const unlinkPromise = promisify1WithVoid<string>(unlink) | ||
174 | const renamePromise = promisify2WithVoid<string, string>(rename) | ||
175 | const writeFilePromise = promisify2WithVoid<string, any>(writeFile) | ||
176 | const readdirPromise = promisify1<string, string[]>(readdir) | ||
177 | const mkdirpPromise = promisify1<string, string>(mkdirp) | ||
178 | // we cannot modify the Promise types, so we should make the promisify instance check mkdirp | ||
179 | const pseudoRandomBytesPromise = promisify1<number, Buffer>(pseudoRandomBytes) | 170 | const pseudoRandomBytesPromise = promisify1<number, Buffer>(pseudoRandomBytes) |
180 | const createPrivateKey = promisify1<number, { key: string }>(pem.createPrivateKey) | 171 | const createPrivateKey = promisify1<number, { key: string }>(pem.createPrivateKey) |
181 | const getPublicKey = promisify1<string, { publicKey: string }>(pem.getPublicKey) | 172 | const getPublicKey = promisify1<string, { publicKey: string }>(pem.getPublicKey) |
@@ -183,8 +174,6 @@ const bcryptComparePromise = promisify2<any, string, boolean>(bcrypt.compare) | |||
183 | const bcryptGenSaltPromise = promisify1<number, string>(bcrypt.genSalt) | 174 | const bcryptGenSaltPromise = promisify1<number, string>(bcrypt.genSalt) |
184 | const bcryptHashPromise = promisify2<any, string | number, string>(bcrypt.hash) | 175 | const bcryptHashPromise = promisify2<any, string | number, string>(bcrypt.hash) |
185 | const createTorrentPromise = promisify2<string, any, any>(createTorrent) | 176 | const createTorrentPromise = promisify2<string, any, any>(createTorrent) |
186 | const rimrafPromise = promisify1WithVoid<string>(rimraf) | ||
187 | const 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 @@ | |||
1 | import * as ffmpeg from 'fluent-ffmpeg' | 1 | import * as ffmpeg from 'fluent-ffmpeg' |
2 | import { join } from 'path' | 2 | import { join } from 'path' |
3 | import { VideoResolution } from '../../shared/models/videos' | 3 | import { VideoResolution } from '../../shared/models/videos' |
4 | import { CONFIG, VIDEO_TRANSCODING_FPS, FFMPEG_NICE } from '../initializers' | 4 | import { CONFIG, FFMPEG_NICE, VIDEO_TRANSCODING_FPS } from '../initializers' |
5 | import { unlinkPromise } from './core-utils' | ||
6 | import { processImage } from './image-utils' | 5 | import { processImage } from './image-utils' |
7 | import { logger } from './logger' | 6 | import { logger } from './logger' |
8 | import { checkFFmpegEncoders } from '../initializers/checker' | 7 | import { checkFFmpegEncoders } from '../initializers/checker' |
8 | import { remove } from 'fs-extra' | ||
9 | 9 | ||
10 | function computeResolutionsToTranscode (videoFileHeight: number) { | 10 | function 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 @@ | |||
1 | import 'multer' | 1 | import 'multer' |
2 | import * as sharp from 'sharp' | 2 | import * as sharp from 'sharp' |
3 | import { unlinkPromise } from './core-utils' | 3 | import { remove } from 'fs-extra' |
4 | 4 | ||
5 | async function processImage ( | 5 | async 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' | |||
2 | import { CONFIG } from '../initializers' | 2 | import { CONFIG } from '../initializers' |
3 | import { ActorModel } from '../models/activitypub/actor' | 3 | import { ActorModel } from '../models/activitypub/actor' |
4 | import { ApplicationModel } from '../models/application/application' | 4 | import { ApplicationModel } from '../models/application/application' |
5 | import { pseudoRandomBytesPromise, sha256, unlinkPromise } from './core-utils' | 5 | import { pseudoRandomBytesPromise, sha256 } from './core-utils' |
6 | import { logger } from './logger' | 6 | import { logger } from './logger' |
7 | import { join } from 'path' | 7 | import { join } from 'path' |
8 | import { Instance as ParseTorrent } from 'parse-torrent' | 8 | import { Instance as ParseTorrent } from 'parse-torrent' |
9 | import { remove } from 'fs-extra' | ||
9 | 10 | ||
10 | function deleteFileAsync (path: string) { | 11 | function 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 @@ | |||
1 | import { logger } from './logger' | 1 | import { logger } from './logger' |
2 | import { generateVideoTmpPath } from './utils' | 2 | import { generateVideoTmpPath } from './utils' |
3 | import * as WebTorrent from 'webtorrent' | 3 | import * as WebTorrent from 'webtorrent' |
4 | import { createWriteStream } from 'fs-extra' | 4 | import { createWriteStream, remove } from 'fs-extra' |
5 | import { CONFIG } from '../initializers' | 5 | import { CONFIG } from '../initializers' |
6 | import { join } from 'path' | 6 | import { join } from 'path' |
7 | import { unlinkPromise } from './core-utils' | ||
8 | 7 | ||
9 | function downloadWebTorrentVideo (target: { magnetUri: string, torrentName: string }) { | 8 | function 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) |