diff options
author | Chocobozzz <me@florianbigard.com> | 2021-08-27 14:32:44 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-08-27 15:12:22 +0200 |
commit | 41fb13c330de629df2d23379209e79c7af0f2e9a (patch) | |
tree | 73bc5a90566406b3910f142beae2a879c1e4265d /server/helpers | |
parent | 40e7ed0714f96c01e16de3ac971a4b28116294e1 (diff) | |
download | PeerTube-41fb13c330de629df2d23379209e79c7af0f2e9a.tar.gz PeerTube-41fb13c330de629df2d23379209e79c7af0f2e9a.tar.zst PeerTube-41fb13c330de629df2d23379209e79c7af0f2e9a.zip |
esModuleInterop to true
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/activitypub.ts | 2 | ||||
-rw-r--r-- | server/helpers/audit-logger.ts | 30 | ||||
-rw-r--r-- | server/helpers/captions-utils.ts | 4 | ||||
-rw-r--r-- | server/helpers/core-utils.ts | 6 | ||||
-rw-r--r-- | server/helpers/custom-jsonld-signature.ts | 5 | ||||
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 2 | ||||
-rw-r--r-- | server/helpers/database-utils.ts | 4 | ||||
-rw-r--r-- | server/helpers/express-utils.ts | 6 | ||||
-rw-r--r-- | server/helpers/ffmpeg-utils.ts | 38 | ||||
-rw-r--r-- | server/helpers/ffprobe-utils.ts | 28 | ||||
-rw-r--r-- | server/helpers/image-utils.ts | 6 | ||||
-rw-r--r-- | server/helpers/logger.ts | 32 | ||||
-rw-r--r-- | server/helpers/peertube-crypto.ts | 20 | ||||
-rw-r--r-- | server/helpers/uuid.ts | 4 | ||||
-rw-r--r-- | server/helpers/webtorrent.ts | 20 |
15 files changed, 104 insertions, 103 deletions
diff --git a/server/helpers/activitypub.ts b/server/helpers/activitypub.ts index e0754b501..8b56d2d50 100644 --- a/server/helpers/activitypub.ts +++ b/server/helpers/activitypub.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import Bluebird from 'bluebird' |
2 | import { URL } from 'url' | 2 | import { URL } from 'url' |
3 | import validator from 'validator' | 3 | import validator from 'validator' |
4 | import { ContextType } from '@shared/models/activitypub/context' | 4 | import { ContextType } from '@shared/models/activitypub/context' |
diff --git a/server/helpers/audit-logger.ts b/server/helpers/audit-logger.ts index 884bd187d..5f2e870e3 100644 --- a/server/helpers/audit-logger.ts +++ b/server/helpers/audit-logger.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | import { diff } from 'deep-object-diff' | 1 | import { diff } from 'deep-object-diff' |
2 | import * as express from 'express' | 2 | import express from 'express' |
3 | import * as flatten from 'flat' | 3 | import flatten from 'flat' |
4 | import { chain } from 'lodash' | 4 | import { chain } from 'lodash' |
5 | import * as path from 'path' | 5 | import { join } from 'path' |
6 | import * as winston from 'winston' | 6 | import { addColors, config, createLogger, format, transports } from 'winston' |
7 | import { AUDIT_LOG_FILENAME } from '@server/initializers/constants' | 7 | import { AUDIT_LOG_FILENAME } from '@server/initializers/constants' |
8 | import { AdminAbuse, User, VideoChannel, VideoDetails, VideoImport } from '../../shared' | 8 | import { AdminAbuse, User, VideoChannel, VideoDetails, VideoImport } from '../../shared' |
9 | import { CustomConfig } from '../../shared/models/server/custom-config.model' | 9 | import { CustomConfig } from '../../shared/models/server/custom-config.model' |
@@ -21,23 +21,23 @@ enum AUDIT_TYPE { | |||
21 | DELETE = 'delete' | 21 | DELETE = 'delete' |
22 | } | 22 | } |
23 | 23 | ||
24 | const colors = winston.config.npm.colors | 24 | const colors = config.npm.colors |
25 | colors.audit = winston.config.npm.colors.info | 25 | colors.audit = config.npm.colors.info |
26 | 26 | ||
27 | winston.addColors(colors) | 27 | addColors(colors) |
28 | 28 | ||
29 | const auditLogger = winston.createLogger({ | 29 | const auditLogger = createLogger({ |
30 | levels: { audit: 0 }, | 30 | levels: { audit: 0 }, |
31 | transports: [ | 31 | transports: [ |
32 | new winston.transports.File({ | 32 | new transports.File({ |
33 | filename: path.join(CONFIG.STORAGE.LOG_DIR, AUDIT_LOG_FILENAME), | 33 | filename: join(CONFIG.STORAGE.LOG_DIR, AUDIT_LOG_FILENAME), |
34 | level: 'audit', | 34 | level: 'audit', |
35 | maxsize: 5242880, | 35 | maxsize: 5242880, |
36 | maxFiles: 5, | 36 | maxFiles: 5, |
37 | format: winston.format.combine( | 37 | format: format.combine( |
38 | winston.format.timestamp(), | 38 | format.timestamp(), |
39 | labelFormatter(), | 39 | labelFormatter(), |
40 | winston.format.splat(), | 40 | format.splat(), |
41 | jsonLoggerFormat | 41 | jsonLoggerFormat |
42 | ) | 42 | ) |
43 | }) | 43 | }) |
@@ -84,9 +84,9 @@ abstract class EntityAuditView { | |||
84 | constructor (private readonly keysToKeep: string[], private readonly prefix: string, private readonly entityInfos: object) { } | 84 | constructor (private readonly keysToKeep: string[], private readonly prefix: string, private readonly entityInfos: object) { } |
85 | 85 | ||
86 | toLogKeys (): object { | 86 | toLogKeys (): object { |
87 | return chain(flatten(this.entityInfos, { delimiter: '-', safe: true })) | 87 | return chain(flatten<object, any>(this.entityInfos, { delimiter: '-', safe: true })) |
88 | .pick(this.keysToKeep) | 88 | .pick(this.keysToKeep) |
89 | .mapKeys((value, key) => `${this.prefix}-${key}`) | 89 | .mapKeys((_value, key) => `${this.prefix}-${key}`) |
90 | .value() | 90 | .value() |
91 | } | 91 | } |
92 | } | 92 | } |
diff --git a/server/helpers/captions-utils.ts b/server/helpers/captions-utils.ts index ca03f7a49..f6e5b9784 100644 --- a/server/helpers/captions-utils.ts +++ b/server/helpers/captions-utils.ts | |||
@@ -1,10 +1,10 @@ | |||
1 | import { createReadStream, createWriteStream, move, remove } from 'fs-extra' | 1 | import { createReadStream, createWriteStream, move, remove } from 'fs-extra' |
2 | import { join } from 'path' | 2 | import { join } from 'path' |
3 | import * as srt2vtt from 'srt-to-vtt' | 3 | import srt2vtt from 'srt-to-vtt' |
4 | import { Transform } from 'stream' | ||
4 | import { MVideoCaption } from '@server/types/models' | 5 | import { MVideoCaption } from '@server/types/models' |
5 | import { CONFIG } from '../initializers/config' | 6 | import { CONFIG } from '../initializers/config' |
6 | import { pipelinePromise } from './core-utils' | 7 | import { pipelinePromise } from './core-utils' |
7 | import { Transform } from 'stream' | ||
8 | 8 | ||
9 | async function moveAndProcessCaptionFile (physicalFile: { filename: string, path: string }, videoCaption: MVideoCaption) { | 9 | async function moveAndProcessCaptionFile (physicalFile: { filename: string, path: string }, videoCaption: MVideoCaption) { |
10 | const videoCaptionsDir = CONFIG.STORAGE.CAPTIONS_DIR | 10 | const videoCaptionsDir = CONFIG.STORAGE.CAPTIONS_DIR |
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts index 9abc532d2..7f28cfc8b 100644 --- a/server/helpers/core-utils.ts +++ b/server/helpers/core-utils.ts | |||
@@ -9,7 +9,7 @@ import { exec, ExecOptions } from 'child_process' | |||
9 | import { BinaryToTextEncoding, createHash, randomBytes } from 'crypto' | 9 | import { BinaryToTextEncoding, createHash, randomBytes } from 'crypto' |
10 | import { truncate } from 'lodash' | 10 | import { truncate } from 'lodash' |
11 | import { basename, extname, isAbsolute, join, resolve } from 'path' | 11 | import { basename, extname, isAbsolute, join, resolve } from 'path' |
12 | import * as pem from 'pem' | 12 | import { createPrivateKey as createPrivateKey_1, getPublicKey as getPublicKey_1 } from 'pem' |
13 | import { pipeline } from 'stream' | 13 | import { pipeline } from 'stream' |
14 | import { URL } from 'url' | 14 | import { URL } from 'url' |
15 | import { promisify } from 'util' | 15 | import { promisify } from 'util' |
@@ -281,8 +281,8 @@ function promisify2<T, U, A> (func: (arg1: T, arg2: U, cb: (err: any, result: A) | |||
281 | } | 281 | } |
282 | 282 | ||
283 | const randomBytesPromise = promisify1<number, Buffer>(randomBytes) | 283 | const randomBytesPromise = promisify1<number, Buffer>(randomBytes) |
284 | const createPrivateKey = promisify1<number, { key: string }>(pem.createPrivateKey) | 284 | const createPrivateKey = promisify1<number, { key: string }>(createPrivateKey_1) |
285 | const getPublicKey = promisify1<string, { publicKey: string }>(pem.getPublicKey) | 285 | const getPublicKey = promisify1<string, { publicKey: string }>(getPublicKey_1) |
286 | const execPromise2 = promisify2<string, any, string>(exec) | 286 | const execPromise2 = promisify2<string, any, string>(exec) |
287 | const execPromise = promisify1<string, string>(exec) | 287 | const execPromise = promisify1<string, string>(exec) |
288 | const pipelinePromise = promisify(pipeline) | 288 | const pipelinePromise = promisify(pipeline) |
diff --git a/server/helpers/custom-jsonld-signature.ts b/server/helpers/custom-jsonld-signature.ts index 56f10086c..3c706e372 100644 --- a/server/helpers/custom-jsonld-signature.ts +++ b/server/helpers/custom-jsonld-signature.ts | |||
@@ -1,7 +1,8 @@ | |||
1 | import * as AsyncLRU from 'async-lru' | 1 | import AsyncLRU from 'async-lru' |
2 | import * as jsonld from 'jsonld' | ||
3 | import { logger } from './logger' | 2 | import { logger } from './logger' |
4 | 3 | ||
4 | import jsonld = require('jsonld') | ||
5 | |||
5 | const CACHE = { | 6 | const CACHE = { |
6 | 'https://w3id.org/security/v1': { | 7 | 'https://w3id.org/security/v1': { |
7 | '@context': { | 8 | '@context': { |
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index b33e088eb..c3604fbad 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { UploadFilesForCheck } from 'express' | 1 | import { UploadFilesForCheck } from 'express' |
2 | import { values } from 'lodash' | 2 | import { values } from 'lodash' |
3 | import * as magnetUtil from 'magnet-uri' | 3 | import magnetUtil from 'magnet-uri' |
4 | import validator from 'validator' | 4 | import validator from 'validator' |
5 | import { VideoFilter, VideoPrivacy, VideoRateType } from '../../../shared' | 5 | import { VideoFilter, VideoPrivacy, VideoRateType } from '../../../shared' |
6 | import { | 6 | import { |
diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts index ec35295df..aedcc5e64 100644 --- a/server/helpers/database-utils.ts +++ b/server/helpers/database-utils.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as retry from 'async/retry' | 1 | import retry from 'async/retry' |
2 | import * as Bluebird from 'bluebird' | 2 | import Bluebird from 'bluebird' |
3 | import { Transaction } from 'sequelize' | 3 | import { Transaction } from 'sequelize' |
4 | import { Model } from 'sequelize-typescript' | 4 | import { Model } from 'sequelize-typescript' |
5 | import { sequelizeTypescript } from '@server/initializers/database' | 5 | import { sequelizeTypescript } from '@server/initializers/database' |
diff --git a/server/helpers/express-utils.ts b/server/helpers/express-utils.ts index c299b70f1..38fe6926b 100644 --- a/server/helpers/express-utils.ts +++ b/server/helpers/express-utils.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import express from 'express' |
2 | import * as multer from 'multer' | 2 | import multer, { diskStorage } from 'multer' |
3 | import { HttpStatusCode } from '../../shared/models/http/http-error-codes' | 3 | import { HttpStatusCode } from '../../shared/models/http/http-error-codes' |
4 | import { CONFIG } from '../initializers/config' | 4 | import { CONFIG } from '../initializers/config' |
5 | import { REMOTE_SCHEME } from '../initializers/constants' | 5 | import { REMOTE_SCHEME } from '../initializers/constants' |
@@ -70,7 +70,7 @@ function createReqFiles ( | |||
70 | mimeTypes: { [id: string]: string | string[] }, | 70 | mimeTypes: { [id: string]: string | string[] }, |
71 | destinations: { [fieldName: string]: string } | 71 | destinations: { [fieldName: string]: string } |
72 | ) { | 72 | ) { |
73 | const storage = multer.diskStorage({ | 73 | const storage = diskStorage({ |
74 | destination: (req, file, cb) => { | 74 | destination: (req, file, cb) => { |
75 | cb(null, destinations[file.fieldname]) | 75 | cb(null, destinations[file.fieldname]) |
76 | }, | 76 | }, |
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index a99c9ee7c..54fd031b7 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { Job } from 'bull' | 1 | import { Job } from 'bull' |
2 | import * as ffmpeg from 'fluent-ffmpeg' | 2 | import ffmpeg, { FfmpegCommand, FilterSpecification, getAvailableEncoders } from 'fluent-ffmpeg' |
3 | import { readFile, remove, writeFile } from 'fs-extra' | 3 | import { readFile, remove, writeFile } from 'fs-extra' |
4 | import { dirname, join } from 'path' | 4 | import { dirname, join } from 'path' |
5 | import { FFMPEG_NICE, VIDEO_LIVE } from '@server/initializers/constants' | 5 | import { FFMPEG_NICE, VIDEO_LIVE } from '@server/initializers/constants' |
@@ -42,7 +42,7 @@ async function checkFFmpegEncoders (peertubeAvailableEncoders: AvailableEncoders | |||
42 | return supportedEncoders | 42 | return supportedEncoders |
43 | } | 43 | } |
44 | 44 | ||
45 | const getAvailableEncodersPromise = promisify0(ffmpeg.getAvailableEncoders) | 45 | const getAvailableEncodersPromise = promisify0(getAvailableEncoders) |
46 | const availableFFmpegEncoders = await getAvailableEncodersPromise() | 46 | const availableFFmpegEncoders = await getAvailableEncodersPromise() |
47 | 47 | ||
48 | const searchEncoders = new Set<string>() | 48 | const searchEncoders = new Set<string>() |
@@ -191,7 +191,7 @@ type TranscodeOptions = | |||
191 | | QuickTranscodeOptions | 191 | | QuickTranscodeOptions |
192 | 192 | ||
193 | const builders: { | 193 | const builders: { |
194 | [ type in TranscodeOptionsType ]: (c: ffmpeg.FfmpegCommand, o?: TranscodeOptions) => Promise<ffmpeg.FfmpegCommand> | ffmpeg.FfmpegCommand | 194 | [ type in TranscodeOptionsType ]: (c: FfmpegCommand, o?: TranscodeOptions) => Promise<FfmpegCommand> | FfmpegCommand |
195 | } = { | 195 | } = { |
196 | 'quick-transcode': buildQuickTranscodeCommand, | 196 | 'quick-transcode': buildQuickTranscodeCommand, |
197 | 'hls': buildHLSVODCommand, | 197 | 'hls': buildHLSVODCommand, |
@@ -241,7 +241,7 @@ async function getLiveTranscodingCommand (options: { | |||
241 | 241 | ||
242 | const varStreamMap: string[] = [] | 242 | const varStreamMap: string[] = [] |
243 | 243 | ||
244 | const complexFilter: ffmpeg.FilterSpecification[] = [ | 244 | const complexFilter: FilterSpecification[] = [ |
245 | { | 245 | { |
246 | inputs: '[v:0]', | 246 | inputs: '[v:0]', |
247 | filter: 'split', | 247 | filter: 'split', |
@@ -353,7 +353,7 @@ function buildStreamSuffix (base: string, streamNum?: number) { | |||
353 | // --------------------------------------------------------------------------- | 353 | // --------------------------------------------------------------------------- |
354 | 354 | ||
355 | function addDefaultEncoderGlobalParams (options: { | 355 | function addDefaultEncoderGlobalParams (options: { |
356 | command: ffmpeg.FfmpegCommand | 356 | command: FfmpegCommand |
357 | }) { | 357 | }) { |
358 | const { command } = options | 358 | const { command } = options |
359 | 359 | ||
@@ -370,7 +370,7 @@ function addDefaultEncoderGlobalParams (options: { | |||
370 | } | 370 | } |
371 | 371 | ||
372 | function addDefaultEncoderParams (options: { | 372 | function addDefaultEncoderParams (options: { |
373 | command: ffmpeg.FfmpegCommand | 373 | command: FfmpegCommand |
374 | encoder: 'libx264' | string | 374 | encoder: 'libx264' | string |
375 | streamNum?: number | 375 | streamNum?: number |
376 | fps?: number | 376 | fps?: number |
@@ -390,7 +390,7 @@ function addDefaultEncoderParams (options: { | |||
390 | } | 390 | } |
391 | } | 391 | } |
392 | 392 | ||
393 | function addDefaultLiveHLSParams (command: ffmpeg.FfmpegCommand, outPath: string, masterPlaylistName: string) { | 393 | function addDefaultLiveHLSParams (command: FfmpegCommand, outPath: string, masterPlaylistName: string) { |
394 | command.outputOption('-hls_time ' + VIDEO_LIVE.SEGMENT_TIME_SECONDS) | 394 | command.outputOption('-hls_time ' + VIDEO_LIVE.SEGMENT_TIME_SECONDS) |
395 | command.outputOption('-hls_list_size ' + VIDEO_LIVE.SEGMENTS_LIST_SIZE) | 395 | command.outputOption('-hls_list_size ' + VIDEO_LIVE.SEGMENTS_LIST_SIZE) |
396 | command.outputOption('-hls_flags delete_segments+independent_segments') | 396 | command.outputOption('-hls_flags delete_segments+independent_segments') |
@@ -405,7 +405,7 @@ function addDefaultLiveHLSParams (command: ffmpeg.FfmpegCommand, outPath: string | |||
405 | // Transcode VOD command builders | 405 | // Transcode VOD command builders |
406 | // --------------------------------------------------------------------------- | 406 | // --------------------------------------------------------------------------- |
407 | 407 | ||
408 | async function buildx264VODCommand (command: ffmpeg.FfmpegCommand, options: TranscodeOptions) { | 408 | async function buildx264VODCommand (command: FfmpegCommand, options: TranscodeOptions) { |
409 | let fps = await getVideoFileFPS(options.inputPath) | 409 | let fps = await getVideoFileFPS(options.inputPath) |
410 | fps = computeFPS(fps, options.resolution) | 410 | fps = computeFPS(fps, options.resolution) |
411 | 411 | ||
@@ -422,7 +422,7 @@ async function buildx264VODCommand (command: ffmpeg.FfmpegCommand, options: Tran | |||
422 | return command | 422 | return command |
423 | } | 423 | } |
424 | 424 | ||
425 | async function buildAudioMergeCommand (command: ffmpeg.FfmpegCommand, options: MergeAudioTranscodeOptions) { | 425 | async function buildAudioMergeCommand (command: FfmpegCommand, options: MergeAudioTranscodeOptions) { |
426 | command = command.loop(undefined) | 426 | command = command.loop(undefined) |
427 | 427 | ||
428 | const scaleFilterValue = getScaleCleanerValue() | 428 | const scaleFilterValue = getScaleCleanerValue() |
@@ -437,13 +437,13 @@ async function buildAudioMergeCommand (command: ffmpeg.FfmpegCommand, options: M | |||
437 | return command | 437 | return command |
438 | } | 438 | } |
439 | 439 | ||
440 | function buildOnlyAudioCommand (command: ffmpeg.FfmpegCommand, _options: OnlyAudioTranscodeOptions) { | 440 | function buildOnlyAudioCommand (command: FfmpegCommand, _options: OnlyAudioTranscodeOptions) { |
441 | command = presetOnlyAudio(command) | 441 | command = presetOnlyAudio(command) |
442 | 442 | ||
443 | return command | 443 | return command |
444 | } | 444 | } |
445 | 445 | ||
446 | function buildQuickTranscodeCommand (command: ffmpeg.FfmpegCommand) { | 446 | function buildQuickTranscodeCommand (command: FfmpegCommand) { |
447 | command = presetCopy(command) | 447 | command = presetCopy(command) |
448 | 448 | ||
449 | command = command.outputOption('-map_metadata -1') // strip all metadata | 449 | command = command.outputOption('-map_metadata -1') // strip all metadata |
@@ -452,7 +452,7 @@ function buildQuickTranscodeCommand (command: ffmpeg.FfmpegCommand) { | |||
452 | return command | 452 | return command |
453 | } | 453 | } |
454 | 454 | ||
455 | function addCommonHLSVODCommandOptions (command: ffmpeg.FfmpegCommand, outputPath: string) { | 455 | function addCommonHLSVODCommandOptions (command: FfmpegCommand, outputPath: string) { |
456 | return command.outputOption('-hls_time 4') | 456 | return command.outputOption('-hls_time 4') |
457 | .outputOption('-hls_list_size 0') | 457 | .outputOption('-hls_list_size 0') |
458 | .outputOption('-hls_playlist_type vod') | 458 | .outputOption('-hls_playlist_type vod') |
@@ -462,7 +462,7 @@ function addCommonHLSVODCommandOptions (command: ffmpeg.FfmpegCommand, outputPat | |||
462 | .outputOption('-hls_flags single_file') | 462 | .outputOption('-hls_flags single_file') |
463 | } | 463 | } |
464 | 464 | ||
465 | async function buildHLSVODCommand (command: ffmpeg.FfmpegCommand, options: HLSTranscodeOptions) { | 465 | async function buildHLSVODCommand (command: FfmpegCommand, options: HLSTranscodeOptions) { |
466 | const videoPath = getHLSVideoPath(options) | 466 | const videoPath = getHLSVideoPath(options) |
467 | 467 | ||
468 | if (options.copyCodecs) command = presetCopy(command) | 468 | if (options.copyCodecs) command = presetCopy(command) |
@@ -474,7 +474,7 @@ async function buildHLSVODCommand (command: ffmpeg.FfmpegCommand, options: HLSTr | |||
474 | return command | 474 | return command |
475 | } | 475 | } |
476 | 476 | ||
477 | function buildHLSVODFromTSCommand (command: ffmpeg.FfmpegCommand, options: HLSFromTSTranscodeOptions) { | 477 | function buildHLSVODFromTSCommand (command: FfmpegCommand, options: HLSFromTSTranscodeOptions) { |
478 | const videoPath = getHLSVideoPath(options) | 478 | const videoPath = getHLSVideoPath(options) |
479 | 479 | ||
480 | command.outputOption('-c copy') | 480 | command.outputOption('-c copy') |
@@ -571,7 +571,7 @@ async function getEncoderBuilderResult (options: EncoderOptionsBuilderParams & { | |||
571 | } | 571 | } |
572 | 572 | ||
573 | async function presetVideo (options: { | 573 | async function presetVideo (options: { |
574 | command: ffmpeg.FfmpegCommand | 574 | command: FfmpegCommand |
575 | input: string | 575 | input: string |
576 | transcodeOptions: TranscodeOptions | 576 | transcodeOptions: TranscodeOptions |
577 | fps?: number | 577 | fps?: number |
@@ -640,21 +640,21 @@ async function presetVideo (options: { | |||
640 | return localCommand | 640 | return localCommand |
641 | } | 641 | } |
642 | 642 | ||
643 | function presetCopy (command: ffmpeg.FfmpegCommand): ffmpeg.FfmpegCommand { | 643 | function presetCopy (command: FfmpegCommand): FfmpegCommand { |
644 | return command | 644 | return command |
645 | .format('mp4') | 645 | .format('mp4') |
646 | .videoCodec('copy') | 646 | .videoCodec('copy') |
647 | .audioCodec('copy') | 647 | .audioCodec('copy') |
648 | } | 648 | } |
649 | 649 | ||
650 | function presetOnlyAudio (command: ffmpeg.FfmpegCommand): ffmpeg.FfmpegCommand { | 650 | function presetOnlyAudio (command: FfmpegCommand): FfmpegCommand { |
651 | return command | 651 | return command |
652 | .format('mp4') | 652 | .format('mp4') |
653 | .audioCodec('copy') | 653 | .audioCodec('copy') |
654 | .noVideo() | 654 | .noVideo() |
655 | } | 655 | } |
656 | 656 | ||
657 | function applyEncoderOptions (command: ffmpeg.FfmpegCommand, options: EncoderOptions): ffmpeg.FfmpegCommand { | 657 | function applyEncoderOptions (command: FfmpegCommand, options: EncoderOptions): FfmpegCommand { |
658 | return command | 658 | return command |
659 | .inputOptions(options.inputOptions ?? []) | 659 | .inputOptions(options.inputOptions ?? []) |
660 | .outputOptions(options.outputOptions ?? []) | 660 | .outputOptions(options.outputOptions ?? []) |
@@ -714,7 +714,7 @@ function getFFmpegVersion () { | |||
714 | } | 714 | } |
715 | 715 | ||
716 | async function runCommand (options: { | 716 | async function runCommand (options: { |
717 | command: ffmpeg.FfmpegCommand | 717 | command: FfmpegCommand |
718 | silent?: boolean // false | 718 | silent?: boolean // false |
719 | job?: Job | 719 | job?: Job |
720 | }) { | 720 | }) { |
diff --git a/server/helpers/ffprobe-utils.ts b/server/helpers/ffprobe-utils.ts index e58444b07..8381dee84 100644 --- a/server/helpers/ffprobe-utils.ts +++ b/server/helpers/ffprobe-utils.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import * as ffmpeg from 'fluent-ffmpeg' | 1 | import { ffprobe, FfprobeData } from 'fluent-ffmpeg' |
2 | import { getMaxBitrate } from '@shared/core-utils' | 2 | import { getMaxBitrate } from '@shared/core-utils' |
3 | import { VideoFileMetadata, VideoResolution, VideoTranscodingFPS } from '../../shared/models/videos' | 3 | import { VideoFileMetadata, VideoResolution, VideoTranscodingFPS } from '../../shared/models/videos' |
4 | import { CONFIG } from '../initializers/config' | 4 | import { CONFIG } from '../initializers/config' |
@@ -12,8 +12,8 @@ import { logger } from './logger' | |||
12 | */ | 12 | */ |
13 | 13 | ||
14 | function ffprobePromise (path: string) { | 14 | function ffprobePromise (path: string) { |
15 | return new Promise<ffmpeg.FfprobeData>((res, rej) => { | 15 | return new Promise<FfprobeData>((res, rej) => { |
16 | ffmpeg.ffprobe(path, (err, data) => { | 16 | ffprobe(path, (err, data) => { |
17 | if (err) return rej(err) | 17 | if (err) return rej(err) |
18 | 18 | ||
19 | return res(data) | 19 | return res(data) |
@@ -21,7 +21,7 @@ function ffprobePromise (path: string) { | |||
21 | }) | 21 | }) |
22 | } | 22 | } |
23 | 23 | ||
24 | async function getAudioStream (videoPath: string, existingProbe?: ffmpeg.FfprobeData) { | 24 | async function getAudioStream (videoPath: string, existingProbe?: FfprobeData) { |
25 | // without position, ffprobe considers the last input only | 25 | // without position, ffprobe considers the last input only |
26 | // we make it consider the first input only | 26 | // we make it consider the first input only |
27 | // if you pass a file path to pos, then ffprobe acts on that file directly | 27 | // if you pass a file path to pos, then ffprobe acts on that file directly |
@@ -76,7 +76,7 @@ function getMaxAudioBitrate (type: 'aac' | 'mp3' | string, bitrate: number) { | |||
76 | } | 76 | } |
77 | } | 77 | } |
78 | 78 | ||
79 | async function getVideoStreamSize (path: string, existingProbe?: ffmpeg.FfprobeData): Promise<{ width: number, height: number }> { | 79 | async function getVideoStreamSize (path: string, existingProbe?: FfprobeData): Promise<{ width: number, height: number }> { |
80 | const videoStream = await getVideoStreamFromFile(path, existingProbe) | 80 | const videoStream = await getVideoStreamFromFile(path, existingProbe) |
81 | 81 | ||
82 | return videoStream === null | 82 | return videoStream === null |
@@ -127,7 +127,7 @@ async function getVideoStreamCodec (path: string) { | |||
127 | return `${videoCodec}.${baseProfile}${level}` | 127 | return `${videoCodec}.${baseProfile}${level}` |
128 | } | 128 | } |
129 | 129 | ||
130 | async function getAudioStreamCodec (path: string, existingProbe?: ffmpeg.FfprobeData) { | 130 | async function getAudioStreamCodec (path: string, existingProbe?: FfprobeData) { |
131 | const { audioStream } = await getAudioStream(path, existingProbe) | 131 | const { audioStream } = await getAudioStream(path, existingProbe) |
132 | 132 | ||
133 | if (!audioStream) return '' | 133 | if (!audioStream) return '' |
@@ -143,7 +143,7 @@ async function getAudioStreamCodec (path: string, existingProbe?: ffmpeg.Ffprobe | |||
143 | return 'mp4a.40.2' // Fallback | 143 | return 'mp4a.40.2' // Fallback |
144 | } | 144 | } |
145 | 145 | ||
146 | async function getVideoFileResolution (path: string, existingProbe?: ffmpeg.FfprobeData) { | 146 | async function getVideoFileResolution (path: string, existingProbe?: FfprobeData) { |
147 | const size = await getVideoStreamSize(path, existingProbe) | 147 | const size = await getVideoStreamSize(path, existingProbe) |
148 | 148 | ||
149 | return { | 149 | return { |
@@ -155,7 +155,7 @@ async function getVideoFileResolution (path: string, existingProbe?: ffmpeg.Ffpr | |||
155 | } | 155 | } |
156 | } | 156 | } |
157 | 157 | ||
158 | async function getVideoFileFPS (path: string, existingProbe?: ffmpeg.FfprobeData) { | 158 | async function getVideoFileFPS (path: string, existingProbe?: FfprobeData) { |
159 | const videoStream = await getVideoStreamFromFile(path, existingProbe) | 159 | const videoStream = await getVideoStreamFromFile(path, existingProbe) |
160 | if (videoStream === null) return 0 | 160 | if (videoStream === null) return 0 |
161 | 161 | ||
@@ -173,13 +173,13 @@ async function getVideoFileFPS (path: string, existingProbe?: ffmpeg.FfprobeData | |||
173 | return 0 | 173 | return 0 |
174 | } | 174 | } |
175 | 175 | ||
176 | async function getMetadataFromFile (path: string, existingProbe?: ffmpeg.FfprobeData) { | 176 | async function getMetadataFromFile (path: string, existingProbe?: FfprobeData) { |
177 | const metadata = existingProbe || await ffprobePromise(path) | 177 | const metadata = existingProbe || await ffprobePromise(path) |
178 | 178 | ||
179 | return new VideoFileMetadata(metadata) | 179 | return new VideoFileMetadata(metadata) |
180 | } | 180 | } |
181 | 181 | ||
182 | async function getVideoFileBitrate (path: string, existingProbe?: ffmpeg.FfprobeData): Promise<number> { | 182 | async function getVideoFileBitrate (path: string, existingProbe?: FfprobeData): Promise<number> { |
183 | const metadata = await getMetadataFromFile(path, existingProbe) | 183 | const metadata = await getMetadataFromFile(path, existingProbe) |
184 | 184 | ||
185 | let bitrate = metadata.format.bit_rate as number | 185 | let bitrate = metadata.format.bit_rate as number |
@@ -194,13 +194,13 @@ async function getVideoFileBitrate (path: string, existingProbe?: ffmpeg.Ffprobe | |||
194 | return undefined | 194 | return undefined |
195 | } | 195 | } |
196 | 196 | ||
197 | async function getDurationFromVideoFile (path: string, existingProbe?: ffmpeg.FfprobeData) { | 197 | async function getDurationFromVideoFile (path: string, existingProbe?: FfprobeData) { |
198 | const metadata = await getMetadataFromFile(path, existingProbe) | 198 | const metadata = await getMetadataFromFile(path, existingProbe) |
199 | 199 | ||
200 | return Math.round(metadata.format.duration) | 200 | return Math.round(metadata.format.duration) |
201 | } | 201 | } |
202 | 202 | ||
203 | async function getVideoStreamFromFile (path: string, existingProbe?: ffmpeg.FfprobeData) { | 203 | async function getVideoStreamFromFile (path: string, existingProbe?: FfprobeData) { |
204 | const metadata = await getMetadataFromFile(path, existingProbe) | 204 | const metadata = await getMetadataFromFile(path, existingProbe) |
205 | 205 | ||
206 | return metadata.streams.find(s => s.codec_type === 'video') || null | 206 | return metadata.streams.find(s => s.codec_type === 'video') || null |
@@ -243,7 +243,7 @@ async function canDoQuickTranscode (path: string): Promise<boolean> { | |||
243 | await canDoQuickAudioTranscode(path, probe) | 243 | await canDoQuickAudioTranscode(path, probe) |
244 | } | 244 | } |
245 | 245 | ||
246 | async function canDoQuickVideoTranscode (path: string, probe?: ffmpeg.FfprobeData): Promise<boolean> { | 246 | async function canDoQuickVideoTranscode (path: string, probe?: FfprobeData): Promise<boolean> { |
247 | const videoStream = await getVideoStreamFromFile(path, probe) | 247 | const videoStream = await getVideoStreamFromFile(path, probe) |
248 | const fps = await getVideoFileFPS(path, probe) | 248 | const fps = await getVideoFileFPS(path, probe) |
249 | const bitRate = await getVideoFileBitrate(path, probe) | 249 | const bitRate = await getVideoFileBitrate(path, probe) |
@@ -262,7 +262,7 @@ async function canDoQuickVideoTranscode (path: string, probe?: ffmpeg.FfprobeDat | |||
262 | return true | 262 | return true |
263 | } | 263 | } |
264 | 264 | ||
265 | async function canDoQuickAudioTranscode (path: string, probe?: ffmpeg.FfprobeData): Promise<boolean> { | 265 | async function canDoQuickAudioTranscode (path: string, probe?: FfprobeData): Promise<boolean> { |
266 | const parsedAudio = await getAudioStream(path, probe) | 266 | const parsedAudio = await getAudioStream(path, probe) |
267 | 267 | ||
268 | if (!parsedAudio.audioStream) return true | 268 | if (!parsedAudio.audioStream) return true |
diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts index c76ed545b..033be2c50 100644 --- a/server/helpers/image-utils.ts +++ b/server/helpers/image-utils.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { copy, readFile, remove, rename } from 'fs-extra' | 1 | import { copy, readFile, remove, rename } from 'fs-extra' |
2 | import * as Jimp from 'jimp' | 2 | import Jimp, { read } from 'jimp' |
3 | import { getLowercaseExtension } from './core-utils' | 3 | import { getLowercaseExtension } from './core-utils' |
4 | import { convertWebPToJPG, processGIF } from './ffmpeg-utils' | 4 | import { convertWebPToJPG, processGIF } from './ffmpeg-utils' |
5 | import { logger } from './logger' | 5 | import { logger } from './logger' |
@@ -47,7 +47,7 @@ async function jimpProcessor (path: string, destination: string, newSize: { widt | |||
47 | const inputBuffer = await readFile(path) | 47 | const inputBuffer = await readFile(path) |
48 | 48 | ||
49 | try { | 49 | try { |
50 | jimpInstance = await Jimp.read(inputBuffer) | 50 | jimpInstance = await read(inputBuffer) |
51 | } catch (err) { | 51 | } catch (err) { |
52 | logger.debug('Cannot read %s with jimp. Try to convert the image using ffmpeg first.', path, { err }) | 52 | logger.debug('Cannot read %s with jimp. Try to convert the image using ffmpeg first.', path, { err }) |
53 | 53 | ||
@@ -55,7 +55,7 @@ async function jimpProcessor (path: string, destination: string, newSize: { widt | |||
55 | await convertWebPToJPG(path, newName) | 55 | await convertWebPToJPG(path, newName) |
56 | await rename(newName, path) | 56 | await rename(newName, path) |
57 | 57 | ||
58 | jimpInstance = await Jimp.read(path) | 58 | jimpInstance = await read(path) |
59 | } | 59 | } |
60 | 60 | ||
61 | await remove(destination) | 61 | await remove(destination) |
diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts index 20c3c3edb..4bd00e503 100644 --- a/server/helpers/logger.ts +++ b/server/helpers/logger.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | // Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/ | 1 | // Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/ |
2 | import { mkdirpSync, stat } from 'fs-extra' | 2 | import { mkdirpSync, stat } from 'fs-extra' |
3 | import { omit } from 'lodash' | 3 | import { omit } from 'lodash' |
4 | import * as path from 'path' | 4 | import { join } from 'path' |
5 | import { format as sqlFormat } from 'sql-formatter' | 5 | import { format as sqlFormat } from 'sql-formatter' |
6 | import * as winston from 'winston' | 6 | import { createLogger, format, transports } from 'winston' |
7 | import { FileTransportOptions } from 'winston/lib/winston/transports' | 7 | import { FileTransportOptions } from 'winston/lib/winston/transports' |
8 | import { CONFIG } from '../initializers/config' | 8 | import { CONFIG } from '../initializers/config' |
9 | import { LOG_FILENAME } from '../initializers/constants' | 9 | import { LOG_FILENAME } from '../initializers/constants' |
@@ -47,7 +47,7 @@ function getLoggerReplacer () { | |||
47 | } | 47 | } |
48 | } | 48 | } |
49 | 49 | ||
50 | const consoleLoggerFormat = winston.format.printf(info => { | 50 | const consoleLoggerFormat = format.printf(info => { |
51 | const toOmit = [ 'label', 'timestamp', 'level', 'message', 'sql', 'tags' ] | 51 | const toOmit = [ 'label', 'timestamp', 'level', 'message', 'sql', 'tags' ] |
52 | 52 | ||
53 | const obj = omit(info, ...toOmit) | 53 | const obj = omit(info, ...toOmit) |
@@ -71,24 +71,24 @@ const consoleLoggerFormat = winston.format.printf(info => { | |||
71 | return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}${additionalInfos}` | 71 | return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}${additionalInfos}` |
72 | }) | 72 | }) |
73 | 73 | ||
74 | const jsonLoggerFormat = winston.format.printf(info => { | 74 | const jsonLoggerFormat = format.printf(info => { |
75 | return JSON.stringify(info, getLoggerReplacer()) | 75 | return JSON.stringify(info, getLoggerReplacer()) |
76 | }) | 76 | }) |
77 | 77 | ||
78 | const timestampFormatter = winston.format.timestamp({ | 78 | const timestampFormatter = format.timestamp({ |
79 | format: 'YYYY-MM-DD HH:mm:ss.SSS' | 79 | format: 'YYYY-MM-DD HH:mm:ss.SSS' |
80 | }) | 80 | }) |
81 | const labelFormatter = (suffix?: string) => { | 81 | const labelFormatter = (suffix?: string) => { |
82 | return winston.format.label({ | 82 | return format.label({ |
83 | label: suffix ? `${label} ${suffix}` : label | 83 | label: suffix ? `${label} ${suffix}` : label |
84 | }) | 84 | }) |
85 | } | 85 | } |
86 | 86 | ||
87 | const fileLoggerOptions: FileTransportOptions = { | 87 | const fileLoggerOptions: FileTransportOptions = { |
88 | filename: path.join(CONFIG.STORAGE.LOG_DIR, LOG_FILENAME), | 88 | filename: join(CONFIG.STORAGE.LOG_DIR, LOG_FILENAME), |
89 | handleExceptions: true, | 89 | handleExceptions: true, |
90 | format: winston.format.combine( | 90 | format: format.combine( |
91 | winston.format.timestamp(), | 91 | format.timestamp(), |
92 | jsonLoggerFormat | 92 | jsonLoggerFormat |
93 | ) | 93 | ) |
94 | } | 94 | } |
@@ -101,19 +101,19 @@ if (CONFIG.LOG.ROTATION.ENABLED) { | |||
101 | const logger = buildLogger() | 101 | const logger = buildLogger() |
102 | 102 | ||
103 | function buildLogger (labelSuffix?: string) { | 103 | function buildLogger (labelSuffix?: string) { |
104 | return winston.createLogger({ | 104 | return createLogger({ |
105 | level: CONFIG.LOG.LEVEL, | 105 | level: CONFIG.LOG.LEVEL, |
106 | format: winston.format.combine( | 106 | format: format.combine( |
107 | labelFormatter(labelSuffix), | 107 | labelFormatter(labelSuffix), |
108 | winston.format.splat() | 108 | format.splat() |
109 | ), | 109 | ), |
110 | transports: [ | 110 | transports: [ |
111 | new winston.transports.File(fileLoggerOptions), | 111 | new transports.File(fileLoggerOptions), |
112 | new winston.transports.Console({ | 112 | new transports.Console({ |
113 | handleExceptions: true, | 113 | handleExceptions: true, |
114 | format: winston.format.combine( | 114 | format: format.combine( |
115 | timestampFormatter, | 115 | timestampFormatter, |
116 | winston.format.colorize(), | 116 | format.colorize(), |
117 | consoleLoggerFormat | 117 | consoleLoggerFormat |
118 | ) | 118 | ) |
119 | }) | 119 | }) |
diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index bc6f1d074..66060bde2 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts | |||
@@ -1,16 +1,16 @@ | |||
1 | import { compare, genSalt, hash } from 'bcrypt' | ||
2 | import { createSign, createVerify } from 'crypto' | ||
1 | import { Request } from 'express' | 3 | import { Request } from 'express' |
4 | import { cloneDeep } from 'lodash' | ||
2 | import { BCRYPT_SALT_SIZE, HTTP_SIGNATURE, PRIVATE_RSA_KEY_SIZE } from '../initializers/constants' | 5 | import { BCRYPT_SALT_SIZE, HTTP_SIGNATURE, PRIVATE_RSA_KEY_SIZE } from '../initializers/constants' |
6 | import { MActor } from '../types/models' | ||
3 | import { createPrivateKey, getPublicKey, promisify1, promisify2, sha256 } from './core-utils' | 7 | import { createPrivateKey, getPublicKey, promisify1, promisify2, sha256 } from './core-utils' |
4 | import { jsonld } from './custom-jsonld-signature' | 8 | import { jsonld } from './custom-jsonld-signature' |
5 | import { logger } from './logger' | 9 | import { logger } from './logger' |
6 | import { cloneDeep } from 'lodash' | ||
7 | import { createSign, createVerify } from 'crypto' | ||
8 | import * as bcrypt from 'bcrypt' | ||
9 | import { MActor } from '../types/models' | ||
10 | 10 | ||
11 | const bcryptComparePromise = promisify2<any, string, boolean>(bcrypt.compare) | 11 | const bcryptComparePromise = promisify2<any, string, boolean>(compare) |
12 | const bcryptGenSaltPromise = promisify1<number, string>(bcrypt.genSalt) | 12 | const bcryptGenSaltPromise = promisify1<number, string>(genSalt) |
13 | const bcryptHashPromise = promisify2<any, string | number, string>(bcrypt.hash) | 13 | const bcryptHashPromise = promisify2<any, string | number, string>(hash) |
14 | 14 | ||
15 | const httpSignature = require('http-signature') | 15 | const httpSignature = require('http-signature') |
16 | 16 | ||
@@ -129,7 +129,7 @@ export { | |||
129 | 129 | ||
130 | // --------------------------------------------------------------------------- | 130 | // --------------------------------------------------------------------------- |
131 | 131 | ||
132 | function hash (obj: any): Promise<any> { | 132 | function hashObject (obj: any): Promise<any> { |
133 | return jsonld.promises | 133 | return jsonld.promises |
134 | .normalize(obj, { | 134 | .normalize(obj, { |
135 | algorithm: 'URDNA2015', | 135 | algorithm: 'URDNA2015', |
@@ -151,12 +151,12 @@ function createSignatureHash (signature: any) { | |||
151 | delete signatureCopy.id | 151 | delete signatureCopy.id |
152 | delete signatureCopy.signatureValue | 152 | delete signatureCopy.signatureValue |
153 | 153 | ||
154 | return hash(signatureCopy) | 154 | return hashObject(signatureCopy) |
155 | } | 155 | } |
156 | 156 | ||
157 | function createDocWithoutSignatureHash (doc: any) { | 157 | function createDocWithoutSignatureHash (doc: any) { |
158 | const docWithoutSignature = cloneDeep(doc) | 158 | const docWithoutSignature = cloneDeep(doc) |
159 | delete docWithoutSignature.signature | 159 | delete docWithoutSignature.signature |
160 | 160 | ||
161 | return hash(docWithoutSignature) | 161 | return hashObject(docWithoutSignature) |
162 | } | 162 | } |
diff --git a/server/helpers/uuid.ts b/server/helpers/uuid.ts index 3eb06c773..f3c80e046 100644 --- a/server/helpers/uuid.ts +++ b/server/helpers/uuid.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | import * as short from 'short-uuid' | 1 | import short, { uuid } from 'short-uuid' |
2 | 2 | ||
3 | const translator = short() | 3 | const translator = short() |
4 | 4 | ||
5 | function buildUUID () { | 5 | function buildUUID () { |
6 | return short.uuid() | 6 | return uuid() |
7 | } | 7 | } |
8 | 8 | ||
9 | function uuidToShort (uuid: string) { | 9 | function uuidToShort (uuid: string) { |
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts index 813ebc236..83b46e085 100644 --- a/server/helpers/webtorrent.ts +++ b/server/helpers/webtorrent.ts | |||
@@ -1,10 +1,11 @@ | |||
1 | import * as bencode from 'bencode' | 1 | import { decode, encode } from 'bencode' |
2 | import * as createTorrent from 'create-torrent' | 2 | import createTorrent from 'create-torrent' |
3 | import { createWriteStream, ensureDir, readFile, remove, writeFile } from 'fs-extra' | 3 | import { createWriteStream, ensureDir, readFile, remove, writeFile } from 'fs-extra' |
4 | import * as magnetUtil from 'magnet-uri' | 4 | import magnetUtil from 'magnet-uri' |
5 | import * as parseTorrent from 'parse-torrent' | 5 | import parseTorrent from 'parse-torrent' |
6 | import { dirname, join } from 'path' | 6 | import { dirname, join } from 'path' |
7 | import * as WebTorrent from 'webtorrent' | 7 | import { pipeline } from 'stream' |
8 | import WebTorrent, { Instance, TorrentFile } from 'webtorrent' | ||
8 | import { isArray } from '@server/helpers/custom-validators/misc' | 9 | import { isArray } from '@server/helpers/custom-validators/misc' |
9 | import { WEBSERVER } from '@server/initializers/constants' | 10 | import { WEBSERVER } from '@server/initializers/constants' |
10 | import { generateTorrentFileName } from '@server/lib/paths' | 11 | import { generateTorrentFileName } from '@server/lib/paths' |
@@ -17,7 +18,6 @@ import { promisify2 } from './core-utils' | |||
17 | import { logger } from './logger' | 18 | import { logger } from './logger' |
18 | import { generateVideoImportTmpPath } from './utils' | 19 | import { generateVideoImportTmpPath } from './utils' |
19 | import { extractVideo } from './video' | 20 | import { extractVideo } from './video' |
20 | import { pipeline } from 'stream' | ||
21 | 21 | ||
22 | const createTorrentPromise = promisify2<string, any, any>(createTorrent) | 22 | const createTorrentPromise = promisify2<string, any, any>(createTorrent) |
23 | 23 | ||
@@ -33,7 +33,7 @@ async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName | |||
33 | 33 | ||
34 | return new Promise<string>((res, rej) => { | 34 | return new Promise<string>((res, rej) => { |
35 | const webtorrent = new WebTorrent() | 35 | const webtorrent = new WebTorrent() |
36 | let file: WebTorrent.TorrentFile | 36 | let file: TorrentFile |
37 | 37 | ||
38 | const torrentId = target.magnetUri || join(CONFIG.STORAGE.TORRENTS_DIR, target.torrentName) | 38 | const torrentId = target.magnetUri || join(CONFIG.STORAGE.TORRENTS_DIR, target.torrentName) |
39 | 39 | ||
@@ -126,7 +126,7 @@ async function updateTorrentUrls (videoOrPlaylist: MVideo | MStreamingPlaylistVi | |||
126 | const oldTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename) | 126 | const oldTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename) |
127 | 127 | ||
128 | const torrentContent = await readFile(oldTorrentPath) | 128 | const torrentContent = await readFile(oldTorrentPath) |
129 | const decoded = bencode.decode(torrentContent) | 129 | const decoded = decode(torrentContent) |
130 | 130 | ||
131 | decoded['announce-list'] = buildAnnounceList() | 131 | decoded['announce-list'] = buildAnnounceList() |
132 | decoded.announce = decoded['announce-list'][0][0] | 132 | decoded.announce = decoded['announce-list'][0][0] |
@@ -138,7 +138,7 @@ async function updateTorrentUrls (videoOrPlaylist: MVideo | MStreamingPlaylistVi | |||
138 | 138 | ||
139 | logger.info('Updating torrent URLs %s -> %s.', oldTorrentPath, newTorrentPath) | 139 | logger.info('Updating torrent URLs %s -> %s.', oldTorrentPath, newTorrentPath) |
140 | 140 | ||
141 | await writeFile(newTorrentPath, bencode.encode(decoded)) | 141 | await writeFile(newTorrentPath, encode(decoded)) |
142 | await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)) | 142 | await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)) |
143 | 143 | ||
144 | videoFile.torrentFilename = newTorrentFilename | 144 | videoFile.torrentFilename = newTorrentFilename |
@@ -180,7 +180,7 @@ export { | |||
180 | // --------------------------------------------------------------------------- | 180 | // --------------------------------------------------------------------------- |
181 | 181 | ||
182 | function safeWebtorrentDestroy ( | 182 | function safeWebtorrentDestroy ( |
183 | webtorrent: WebTorrent.Instance, | 183 | webtorrent: Instance, |
184 | torrentId: string, | 184 | torrentId: string, |
185 | downloadedFile?: { directoryPath: string, filepath: string }, | 185 | downloadedFile?: { directoryPath: string, filepath: string }, |
186 | torrentName?: string | 186 | torrentName?: string |