Move createTorrent in webtorrent utils

This commit is contained in:
Chocobozzz 2019-07-15 09:22:57 +02:00 committed by Chocobozzz
parent b2195fafc2
commit 30ff39e7f0
4 changed files with 10 additions and 5 deletions

View File

@ -3,7 +3,6 @@
Useful to avoid circular dependencies. Useful to avoid circular dependencies.
*/ */
import * as createTorrent from 'create-torrent'
import { createHash, HexBase64Latin1Encoding, pseudoRandomBytes } from 'crypto' import { createHash, HexBase64Latin1Encoding, pseudoRandomBytes } from 'crypto'
import { isAbsolute, join } from 'path' import { isAbsolute, join } from 'path'
import * as pem from 'pem' import * as pem from 'pem'
@ -257,7 +256,6 @@ function promisify2WithVoid<T, U> (func: (arg1: T, arg2: U, cb: (err: any) => vo
const pseudoRandomBytesPromise = promisify1<number, Buffer>(pseudoRandomBytes) const pseudoRandomBytesPromise = promisify1<number, Buffer>(pseudoRandomBytes)
const createPrivateKey = promisify1<number, { key: string }>(pem.createPrivateKey) const createPrivateKey = promisify1<number, { key: string }>(pem.createPrivateKey)
const getPublicKey = promisify1<string, { publicKey: string }>(pem.getPublicKey) const getPublicKey = promisify1<string, { publicKey: string }>(pem.getPublicKey)
const createTorrentPromise = promisify2<string, any, any>(createTorrent)
const execPromise2 = promisify2<string, any, string>(exec) const execPromise2 = promisify2<string, any, string>(exec)
const execPromise = promisify1<string, string>(exec) const execPromise = promisify1<string, string>(exec)
@ -288,7 +286,6 @@ export {
pseudoRandomBytesPromise, pseudoRandomBytesPromise,
createPrivateKey, createPrivateKey,
getPublicKey, getPublicKey,
createTorrentPromise,
execPromise2, execPromise2,
execPromise execPromise
} }

View File

@ -4,6 +4,8 @@ import * as WebTorrent from 'webtorrent'
import { createWriteStream, ensureDir, remove } from 'fs-extra' import { createWriteStream, ensureDir, remove } from 'fs-extra'
import { CONFIG } from '../initializers/config' import { CONFIG } from '../initializers/config'
import { dirname, join } from 'path' import { dirname, join } from 'path'
import * as createTorrent from 'create-torrent'
import { promisify2 } from './core-utils'
async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName?: string }, timeout: number) { async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName?: string }, timeout: number) {
const id = target.magnetUri || target.torrentName const id = target.magnetUri || target.torrentName
@ -57,9 +59,12 @@ async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName
}) })
} }
const createTorrentPromise = promisify2<string, any, any>(createTorrent)
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
export { export {
createTorrentPromise,
downloadWebTorrentVideo downloadWebTorrentVideo
} }

View File

@ -40,7 +40,7 @@ import { UserRight, VideoPrivacy, VideoState } from '../../../shared'
import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' import { VideoTorrentObject } from '../../../shared/models/activitypub/objects'
import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos' import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos'
import { VideoFilter } from '../../../shared/models/videos/video-query.type' import { VideoFilter } from '../../../shared/models/videos/video-query.type'
import { createTorrentPromise, peertubeTruncate } from '../../helpers/core-utils' import { peertubeTruncate } from '../../helpers/core-utils'
import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
import { isArray, isBooleanValid } from '../../helpers/custom-validators/misc' import { isArray, isBooleanValid } from '../../helpers/custom-validators/misc'
import { import {
@ -117,6 +117,7 @@ import { VideoPlaylistElementModel } from './video-playlist-element'
import { CONFIG } from '../../initializers/config' import { CONFIG } from '../../initializers/config'
import { ThumbnailModel } from './thumbnail' import { ThumbnailModel } from './thumbnail'
import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type'
import { createTorrentPromise } from '../../helpers/webtorrent'
// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation // FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation
const indexes: (ModelIndexesOptions & { where?: WhereOptions })[] = [ const indexes: (ModelIndexesOptions & { where?: WhereOptions })[] = [

View File

@ -1,6 +1,8 @@
import { PluginType } from './plugin.type'
export interface PeerTubePlugin { export interface PeerTubePlugin {
name: string name: string
type: number type: PluginType
latestVersion: string latestVersion: string
version: string version: string
enabled: boolean enabled: boolean