From 41fb13c330de629df2d23379209e79c7af0f2e9a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 27 Aug 2021 14:32:44 +0200 Subject: esModuleInterop to true --- server/helpers/activitypub.ts | 2 +- server/helpers/audit-logger.ts | 30 +++++++++++------------ server/helpers/captions-utils.ts | 4 ++-- server/helpers/core-utils.ts | 6 ++--- server/helpers/custom-jsonld-signature.ts | 5 ++-- server/helpers/custom-validators/videos.ts | 2 +- server/helpers/database-utils.ts | 4 ++-- server/helpers/express-utils.ts | 6 ++--- server/helpers/ffmpeg-utils.ts | 38 +++++++++++++++--------------- server/helpers/ffprobe-utils.ts | 28 +++++++++++----------- server/helpers/image-utils.ts | 6 ++--- server/helpers/logger.ts | 32 ++++++++++++------------- server/helpers/peertube-crypto.ts | 20 ++++++++-------- server/helpers/uuid.ts | 4 ++-- server/helpers/webtorrent.ts | 20 ++++++++-------- 15 files changed, 104 insertions(+), 103 deletions(-) (limited to 'server/helpers') 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 @@ -import * as Bluebird from 'bluebird' +import Bluebird from 'bluebird' import { URL } from 'url' import validator from 'validator' 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 @@ import { diff } from 'deep-object-diff' -import * as express from 'express' -import * as flatten from 'flat' +import express from 'express' +import flatten from 'flat' import { chain } from 'lodash' -import * as path from 'path' -import * as winston from 'winston' +import { join } from 'path' +import { addColors, config, createLogger, format, transports } from 'winston' import { AUDIT_LOG_FILENAME } from '@server/initializers/constants' import { AdminAbuse, User, VideoChannel, VideoDetails, VideoImport } from '../../shared' import { CustomConfig } from '../../shared/models/server/custom-config.model' @@ -21,23 +21,23 @@ enum AUDIT_TYPE { DELETE = 'delete' } -const colors = winston.config.npm.colors -colors.audit = winston.config.npm.colors.info +const colors = config.npm.colors +colors.audit = config.npm.colors.info -winston.addColors(colors) +addColors(colors) -const auditLogger = winston.createLogger({ +const auditLogger = createLogger({ levels: { audit: 0 }, transports: [ - new winston.transports.File({ - filename: path.join(CONFIG.STORAGE.LOG_DIR, AUDIT_LOG_FILENAME), + new transports.File({ + filename: join(CONFIG.STORAGE.LOG_DIR, AUDIT_LOG_FILENAME), level: 'audit', maxsize: 5242880, maxFiles: 5, - format: winston.format.combine( - winston.format.timestamp(), + format: format.combine( + format.timestamp(), labelFormatter(), - winston.format.splat(), + format.splat(), jsonLoggerFormat ) }) @@ -84,9 +84,9 @@ abstract class EntityAuditView { constructor (private readonly keysToKeep: string[], private readonly prefix: string, private readonly entityInfos: object) { } toLogKeys (): object { - return chain(flatten(this.entityInfos, { delimiter: '-', safe: true })) + return chain(flatten(this.entityInfos, { delimiter: '-', safe: true })) .pick(this.keysToKeep) - .mapKeys((value, key) => `${this.prefix}-${key}`) + .mapKeys((_value, key) => `${this.prefix}-${key}`) .value() } } 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 @@ import { createReadStream, createWriteStream, move, remove } from 'fs-extra' import { join } from 'path' -import * as srt2vtt from 'srt-to-vtt' +import srt2vtt from 'srt-to-vtt' +import { Transform } from 'stream' import { MVideoCaption } from '@server/types/models' import { CONFIG } from '../initializers/config' import { pipelinePromise } from './core-utils' -import { Transform } from 'stream' async function moveAndProcessCaptionFile (physicalFile: { filename: string, path: string }, videoCaption: MVideoCaption) { 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' import { BinaryToTextEncoding, createHash, randomBytes } from 'crypto' import { truncate } from 'lodash' import { basename, extname, isAbsolute, join, resolve } from 'path' -import * as pem from 'pem' +import { createPrivateKey as createPrivateKey_1, getPublicKey as getPublicKey_1 } from 'pem' import { pipeline } from 'stream' import { URL } from 'url' import { promisify } from 'util' @@ -281,8 +281,8 @@ function promisify2 (func: (arg1: T, arg2: U, cb: (err: any, result: A) } const randomBytesPromise = promisify1(randomBytes) -const createPrivateKey = promisify1(pem.createPrivateKey) -const getPublicKey = promisify1(pem.getPublicKey) +const createPrivateKey = promisify1(createPrivateKey_1) +const getPublicKey = promisify1(getPublicKey_1) const execPromise2 = promisify2(exec) const execPromise = promisify1(exec) 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 @@ -import * as AsyncLRU from 'async-lru' -import * as jsonld from 'jsonld' +import AsyncLRU from 'async-lru' import { logger } from './logger' +import jsonld = require('jsonld') + const CACHE = { 'https://w3id.org/security/v1': { '@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 @@ import { UploadFilesForCheck } from 'express' import { values } from 'lodash' -import * as magnetUtil from 'magnet-uri' +import magnetUtil from 'magnet-uri' import validator from 'validator' import { VideoFilter, VideoPrivacy, VideoRateType } from '../../../shared' 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 @@ -import * as retry from 'async/retry' -import * as Bluebird from 'bluebird' +import retry from 'async/retry' +import Bluebird from 'bluebird' import { Transaction } from 'sequelize' import { Model } from 'sequelize-typescript' 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 @@ -import * as express from 'express' -import * as multer from 'multer' +import express from 'express' +import multer, { diskStorage } from 'multer' import { HttpStatusCode } from '../../shared/models/http/http-error-codes' import { CONFIG } from '../initializers/config' import { REMOTE_SCHEME } from '../initializers/constants' @@ -70,7 +70,7 @@ function createReqFiles ( mimeTypes: { [id: string]: string | string[] }, destinations: { [fieldName: string]: string } ) { - const storage = multer.diskStorage({ + const storage = diskStorage({ destination: (req, file, cb) => { cb(null, destinations[file.fieldname]) }, 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 @@ import { Job } from 'bull' -import * as ffmpeg from 'fluent-ffmpeg' +import ffmpeg, { FfmpegCommand, FilterSpecification, getAvailableEncoders } from 'fluent-ffmpeg' import { readFile, remove, writeFile } from 'fs-extra' import { dirname, join } from 'path' import { FFMPEG_NICE, VIDEO_LIVE } from '@server/initializers/constants' @@ -42,7 +42,7 @@ async function checkFFmpegEncoders (peertubeAvailableEncoders: AvailableEncoders return supportedEncoders } - const getAvailableEncodersPromise = promisify0(ffmpeg.getAvailableEncoders) + const getAvailableEncodersPromise = promisify0(getAvailableEncoders) const availableFFmpegEncoders = await getAvailableEncodersPromise() const searchEncoders = new Set() @@ -191,7 +191,7 @@ type TranscodeOptions = | QuickTranscodeOptions const builders: { - [ type in TranscodeOptionsType ]: (c: ffmpeg.FfmpegCommand, o?: TranscodeOptions) => Promise | ffmpeg.FfmpegCommand + [ type in TranscodeOptionsType ]: (c: FfmpegCommand, o?: TranscodeOptions) => Promise | FfmpegCommand } = { 'quick-transcode': buildQuickTranscodeCommand, 'hls': buildHLSVODCommand, @@ -241,7 +241,7 @@ async function getLiveTranscodingCommand (options: { const varStreamMap: string[] = [] - const complexFilter: ffmpeg.FilterSpecification[] = [ + const complexFilter: FilterSpecification[] = [ { inputs: '[v:0]', filter: 'split', @@ -353,7 +353,7 @@ function buildStreamSuffix (base: string, streamNum?: number) { // --------------------------------------------------------------------------- function addDefaultEncoderGlobalParams (options: { - command: ffmpeg.FfmpegCommand + command: FfmpegCommand }) { const { command } = options @@ -370,7 +370,7 @@ function addDefaultEncoderGlobalParams (options: { } function addDefaultEncoderParams (options: { - command: ffmpeg.FfmpegCommand + command: FfmpegCommand encoder: 'libx264' | string streamNum?: number fps?: number @@ -390,7 +390,7 @@ function addDefaultEncoderParams (options: { } } -function addDefaultLiveHLSParams (command: ffmpeg.FfmpegCommand, outPath: string, masterPlaylistName: string) { +function addDefaultLiveHLSParams (command: FfmpegCommand, outPath: string, masterPlaylistName: string) { command.outputOption('-hls_time ' + VIDEO_LIVE.SEGMENT_TIME_SECONDS) command.outputOption('-hls_list_size ' + VIDEO_LIVE.SEGMENTS_LIST_SIZE) command.outputOption('-hls_flags delete_segments+independent_segments') @@ -405,7 +405,7 @@ function addDefaultLiveHLSParams (command: ffmpeg.FfmpegCommand, outPath: string // Transcode VOD command builders // --------------------------------------------------------------------------- -async function buildx264VODCommand (command: ffmpeg.FfmpegCommand, options: TranscodeOptions) { +async function buildx264VODCommand (command: FfmpegCommand, options: TranscodeOptions) { let fps = await getVideoFileFPS(options.inputPath) fps = computeFPS(fps, options.resolution) @@ -422,7 +422,7 @@ async function buildx264VODCommand (command: ffmpeg.FfmpegCommand, options: Tran return command } -async function buildAudioMergeCommand (command: ffmpeg.FfmpegCommand, options: MergeAudioTranscodeOptions) { +async function buildAudioMergeCommand (command: FfmpegCommand, options: MergeAudioTranscodeOptions) { command = command.loop(undefined) const scaleFilterValue = getScaleCleanerValue() @@ -437,13 +437,13 @@ async function buildAudioMergeCommand (command: ffmpeg.FfmpegCommand, options: M return command } -function buildOnlyAudioCommand (command: ffmpeg.FfmpegCommand, _options: OnlyAudioTranscodeOptions) { +function buildOnlyAudioCommand (command: FfmpegCommand, _options: OnlyAudioTranscodeOptions) { command = presetOnlyAudio(command) return command } -function buildQuickTranscodeCommand (command: ffmpeg.FfmpegCommand) { +function buildQuickTranscodeCommand (command: FfmpegCommand) { command = presetCopy(command) command = command.outputOption('-map_metadata -1') // strip all metadata @@ -452,7 +452,7 @@ function buildQuickTranscodeCommand (command: ffmpeg.FfmpegCommand) { return command } -function addCommonHLSVODCommandOptions (command: ffmpeg.FfmpegCommand, outputPath: string) { +function addCommonHLSVODCommandOptions (command: FfmpegCommand, outputPath: string) { return command.outputOption('-hls_time 4') .outputOption('-hls_list_size 0') .outputOption('-hls_playlist_type vod') @@ -462,7 +462,7 @@ function addCommonHLSVODCommandOptions (command: ffmpeg.FfmpegCommand, outputPat .outputOption('-hls_flags single_file') } -async function buildHLSVODCommand (command: ffmpeg.FfmpegCommand, options: HLSTranscodeOptions) { +async function buildHLSVODCommand (command: FfmpegCommand, options: HLSTranscodeOptions) { const videoPath = getHLSVideoPath(options) if (options.copyCodecs) command = presetCopy(command) @@ -474,7 +474,7 @@ async function buildHLSVODCommand (command: ffmpeg.FfmpegCommand, options: HLSTr return command } -function buildHLSVODFromTSCommand (command: ffmpeg.FfmpegCommand, options: HLSFromTSTranscodeOptions) { +function buildHLSVODFromTSCommand (command: FfmpegCommand, options: HLSFromTSTranscodeOptions) { const videoPath = getHLSVideoPath(options) command.outputOption('-c copy') @@ -571,7 +571,7 @@ async function getEncoderBuilderResult (options: EncoderOptionsBuilderParams & { } async function presetVideo (options: { - command: ffmpeg.FfmpegCommand + command: FfmpegCommand input: string transcodeOptions: TranscodeOptions fps?: number @@ -640,21 +640,21 @@ async function presetVideo (options: { return localCommand } -function presetCopy (command: ffmpeg.FfmpegCommand): ffmpeg.FfmpegCommand { +function presetCopy (command: FfmpegCommand): FfmpegCommand { return command .format('mp4') .videoCodec('copy') .audioCodec('copy') } -function presetOnlyAudio (command: ffmpeg.FfmpegCommand): ffmpeg.FfmpegCommand { +function presetOnlyAudio (command: FfmpegCommand): FfmpegCommand { return command .format('mp4') .audioCodec('copy') .noVideo() } -function applyEncoderOptions (command: ffmpeg.FfmpegCommand, options: EncoderOptions): ffmpeg.FfmpegCommand { +function applyEncoderOptions (command: FfmpegCommand, options: EncoderOptions): FfmpegCommand { return command .inputOptions(options.inputOptions ?? []) .outputOptions(options.outputOptions ?? []) @@ -714,7 +714,7 @@ function getFFmpegVersion () { } async function runCommand (options: { - command: ffmpeg.FfmpegCommand + command: FfmpegCommand silent?: boolean // false job?: Job }) { 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 @@ -import * as ffmpeg from 'fluent-ffmpeg' +import { ffprobe, FfprobeData } from 'fluent-ffmpeg' import { getMaxBitrate } from '@shared/core-utils' import { VideoFileMetadata, VideoResolution, VideoTranscodingFPS } from '../../shared/models/videos' import { CONFIG } from '../initializers/config' @@ -12,8 +12,8 @@ import { logger } from './logger' */ function ffprobePromise (path: string) { - return new Promise((res, rej) => { - ffmpeg.ffprobe(path, (err, data) => { + return new Promise((res, rej) => { + ffprobe(path, (err, data) => { if (err) return rej(err) return res(data) @@ -21,7 +21,7 @@ function ffprobePromise (path: string) { }) } -async function getAudioStream (videoPath: string, existingProbe?: ffmpeg.FfprobeData) { +async function getAudioStream (videoPath: string, existingProbe?: FfprobeData) { // without position, ffprobe considers the last input only // we make it consider the first input only // 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) { } } -async function getVideoStreamSize (path: string, existingProbe?: ffmpeg.FfprobeData): Promise<{ width: number, height: number }> { +async function getVideoStreamSize (path: string, existingProbe?: FfprobeData): Promise<{ width: number, height: number }> { const videoStream = await getVideoStreamFromFile(path, existingProbe) return videoStream === null @@ -127,7 +127,7 @@ async function getVideoStreamCodec (path: string) { return `${videoCodec}.${baseProfile}${level}` } -async function getAudioStreamCodec (path: string, existingProbe?: ffmpeg.FfprobeData) { +async function getAudioStreamCodec (path: string, existingProbe?: FfprobeData) { const { audioStream } = await getAudioStream(path, existingProbe) if (!audioStream) return '' @@ -143,7 +143,7 @@ async function getAudioStreamCodec (path: string, existingProbe?: ffmpeg.Ffprobe return 'mp4a.40.2' // Fallback } -async function getVideoFileResolution (path: string, existingProbe?: ffmpeg.FfprobeData) { +async function getVideoFileResolution (path: string, existingProbe?: FfprobeData) { const size = await getVideoStreamSize(path, existingProbe) return { @@ -155,7 +155,7 @@ async function getVideoFileResolution (path: string, existingProbe?: ffmpeg.Ffpr } } -async function getVideoFileFPS (path: string, existingProbe?: ffmpeg.FfprobeData) { +async function getVideoFileFPS (path: string, existingProbe?: FfprobeData) { const videoStream = await getVideoStreamFromFile(path, existingProbe) if (videoStream === null) return 0 @@ -173,13 +173,13 @@ async function getVideoFileFPS (path: string, existingProbe?: ffmpeg.FfprobeData return 0 } -async function getMetadataFromFile (path: string, existingProbe?: ffmpeg.FfprobeData) { +async function getMetadataFromFile (path: string, existingProbe?: FfprobeData) { const metadata = existingProbe || await ffprobePromise(path) return new VideoFileMetadata(metadata) } -async function getVideoFileBitrate (path: string, existingProbe?: ffmpeg.FfprobeData): Promise { +async function getVideoFileBitrate (path: string, existingProbe?: FfprobeData): Promise { const metadata = await getMetadataFromFile(path, existingProbe) let bitrate = metadata.format.bit_rate as number @@ -194,13 +194,13 @@ async function getVideoFileBitrate (path: string, existingProbe?: ffmpeg.Ffprobe return undefined } -async function getDurationFromVideoFile (path: string, existingProbe?: ffmpeg.FfprobeData) { +async function getDurationFromVideoFile (path: string, existingProbe?: FfprobeData) { const metadata = await getMetadataFromFile(path, existingProbe) return Math.round(metadata.format.duration) } -async function getVideoStreamFromFile (path: string, existingProbe?: ffmpeg.FfprobeData) { +async function getVideoStreamFromFile (path: string, existingProbe?: FfprobeData) { const metadata = await getMetadataFromFile(path, existingProbe) return metadata.streams.find(s => s.codec_type === 'video') || null @@ -243,7 +243,7 @@ async function canDoQuickTranscode (path: string): Promise { await canDoQuickAudioTranscode(path, probe) } -async function canDoQuickVideoTranscode (path: string, probe?: ffmpeg.FfprobeData): Promise { +async function canDoQuickVideoTranscode (path: string, probe?: FfprobeData): Promise { const videoStream = await getVideoStreamFromFile(path, probe) const fps = await getVideoFileFPS(path, probe) const bitRate = await getVideoFileBitrate(path, probe) @@ -262,7 +262,7 @@ async function canDoQuickVideoTranscode (path: string, probe?: ffmpeg.FfprobeDat return true } -async function canDoQuickAudioTranscode (path: string, probe?: ffmpeg.FfprobeData): Promise { +async function canDoQuickAudioTranscode (path: string, probe?: FfprobeData): Promise { const parsedAudio = await getAudioStream(path, probe) 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 @@ import { copy, readFile, remove, rename } from 'fs-extra' -import * as Jimp from 'jimp' +import Jimp, { read } from 'jimp' import { getLowercaseExtension } from './core-utils' import { convertWebPToJPG, processGIF } from './ffmpeg-utils' import { logger } from './logger' @@ -47,7 +47,7 @@ async function jimpProcessor (path: string, destination: string, newSize: { widt const inputBuffer = await readFile(path) try { - jimpInstance = await Jimp.read(inputBuffer) + jimpInstance = await read(inputBuffer) } catch (err) { logger.debug('Cannot read %s with jimp. Try to convert the image using ffmpeg first.', path, { err }) @@ -55,7 +55,7 @@ async function jimpProcessor (path: string, destination: string, newSize: { widt await convertWebPToJPG(path, newName) await rename(newName, path) - jimpInstance = await Jimp.read(path) + jimpInstance = await read(path) } 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 @@ // Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/ import { mkdirpSync, stat } from 'fs-extra' import { omit } from 'lodash' -import * as path from 'path' +import { join } from 'path' import { format as sqlFormat } from 'sql-formatter' -import * as winston from 'winston' +import { createLogger, format, transports } from 'winston' import { FileTransportOptions } from 'winston/lib/winston/transports' import { CONFIG } from '../initializers/config' import { LOG_FILENAME } from '../initializers/constants' @@ -47,7 +47,7 @@ function getLoggerReplacer () { } } -const consoleLoggerFormat = winston.format.printf(info => { +const consoleLoggerFormat = format.printf(info => { const toOmit = [ 'label', 'timestamp', 'level', 'message', 'sql', 'tags' ] const obj = omit(info, ...toOmit) @@ -71,24 +71,24 @@ const consoleLoggerFormat = winston.format.printf(info => { return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}${additionalInfos}` }) -const jsonLoggerFormat = winston.format.printf(info => { +const jsonLoggerFormat = format.printf(info => { return JSON.stringify(info, getLoggerReplacer()) }) -const timestampFormatter = winston.format.timestamp({ +const timestampFormatter = format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss.SSS' }) const labelFormatter = (suffix?: string) => { - return winston.format.label({ + return format.label({ label: suffix ? `${label} ${suffix}` : label }) } const fileLoggerOptions: FileTransportOptions = { - filename: path.join(CONFIG.STORAGE.LOG_DIR, LOG_FILENAME), + filename: join(CONFIG.STORAGE.LOG_DIR, LOG_FILENAME), handleExceptions: true, - format: winston.format.combine( - winston.format.timestamp(), + format: format.combine( + format.timestamp(), jsonLoggerFormat ) } @@ -101,19 +101,19 @@ if (CONFIG.LOG.ROTATION.ENABLED) { const logger = buildLogger() function buildLogger (labelSuffix?: string) { - return winston.createLogger({ + return createLogger({ level: CONFIG.LOG.LEVEL, - format: winston.format.combine( + format: format.combine( labelFormatter(labelSuffix), - winston.format.splat() + format.splat() ), transports: [ - new winston.transports.File(fileLoggerOptions), - new winston.transports.Console({ + new transports.File(fileLoggerOptions), + new transports.Console({ handleExceptions: true, - format: winston.format.combine( + format: format.combine( timestampFormatter, - winston.format.colorize(), + format.colorize(), consoleLoggerFormat ) }) 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 @@ +import { compare, genSalt, hash } from 'bcrypt' +import { createSign, createVerify } from 'crypto' import { Request } from 'express' +import { cloneDeep } from 'lodash' import { BCRYPT_SALT_SIZE, HTTP_SIGNATURE, PRIVATE_RSA_KEY_SIZE } from '../initializers/constants' +import { MActor } from '../types/models' import { createPrivateKey, getPublicKey, promisify1, promisify2, sha256 } from './core-utils' import { jsonld } from './custom-jsonld-signature' import { logger } from './logger' -import { cloneDeep } from 'lodash' -import { createSign, createVerify } from 'crypto' -import * as bcrypt from 'bcrypt' -import { MActor } from '../types/models' -const bcryptComparePromise = promisify2(bcrypt.compare) -const bcryptGenSaltPromise = promisify1(bcrypt.genSalt) -const bcryptHashPromise = promisify2(bcrypt.hash) +const bcryptComparePromise = promisify2(compare) +const bcryptGenSaltPromise = promisify1(genSalt) +const bcryptHashPromise = promisify2(hash) const httpSignature = require('http-signature') @@ -129,7 +129,7 @@ export { // --------------------------------------------------------------------------- -function hash (obj: any): Promise { +function hashObject (obj: any): Promise { return jsonld.promises .normalize(obj, { algorithm: 'URDNA2015', @@ -151,12 +151,12 @@ function createSignatureHash (signature: any) { delete signatureCopy.id delete signatureCopy.signatureValue - return hash(signatureCopy) + return hashObject(signatureCopy) } function createDocWithoutSignatureHash (doc: any) { const docWithoutSignature = cloneDeep(doc) delete docWithoutSignature.signature - return hash(docWithoutSignature) + return hashObject(docWithoutSignature) } 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 @@ -import * as short from 'short-uuid' +import short, { uuid } from 'short-uuid' const translator = short() function buildUUID () { - return short.uuid() + return uuid() } 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 @@ -import * as bencode from 'bencode' -import * as createTorrent from 'create-torrent' +import { decode, encode } from 'bencode' +import createTorrent from 'create-torrent' import { createWriteStream, ensureDir, readFile, remove, writeFile } from 'fs-extra' -import * as magnetUtil from 'magnet-uri' -import * as parseTorrent from 'parse-torrent' +import magnetUtil from 'magnet-uri' +import parseTorrent from 'parse-torrent' import { dirname, join } from 'path' -import * as WebTorrent from 'webtorrent' +import { pipeline } from 'stream' +import WebTorrent, { Instance, TorrentFile } from 'webtorrent' import { isArray } from '@server/helpers/custom-validators/misc' import { WEBSERVER } from '@server/initializers/constants' import { generateTorrentFileName } from '@server/lib/paths' @@ -17,7 +18,6 @@ import { promisify2 } from './core-utils' import { logger } from './logger' import { generateVideoImportTmpPath } from './utils' import { extractVideo } from './video' -import { pipeline } from 'stream' const createTorrentPromise = promisify2(createTorrent) @@ -33,7 +33,7 @@ async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName return new Promise((res, rej) => { const webtorrent = new WebTorrent() - let file: WebTorrent.TorrentFile + let file: TorrentFile const torrentId = target.magnetUri || join(CONFIG.STORAGE.TORRENTS_DIR, target.torrentName) @@ -126,7 +126,7 @@ async function updateTorrentUrls (videoOrPlaylist: MVideo | MStreamingPlaylistVi const oldTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename) const torrentContent = await readFile(oldTorrentPath) - const decoded = bencode.decode(torrentContent) + const decoded = decode(torrentContent) decoded['announce-list'] = buildAnnounceList() decoded.announce = decoded['announce-list'][0][0] @@ -138,7 +138,7 @@ async function updateTorrentUrls (videoOrPlaylist: MVideo | MStreamingPlaylistVi logger.info('Updating torrent URLs %s -> %s.', oldTorrentPath, newTorrentPath) - await writeFile(newTorrentPath, bencode.encode(decoded)) + await writeFile(newTorrentPath, encode(decoded)) await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)) videoFile.torrentFilename = newTorrentFilename @@ -180,7 +180,7 @@ export { // --------------------------------------------------------------------------- function safeWebtorrentDestroy ( - webtorrent: WebTorrent.Instance, + webtorrent: Instance, torrentId: string, downloadedFile?: { directoryPath: string, filepath: string }, torrentName?: string -- cgit v1.2.3