]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tools/peertube-repl.ts
Proxy youtube-dl format command too
[github/Chocobozzz/PeerTube.git] / server / tools / peertube-repl.ts
CommitLineData
2aaa1a3f
C
1import { registerTSPaths } from '../helpers/register-ts-paths'
2registerTSPaths()
3
1e59ca3b
BY
4import * as repl from 'repl'
5import * as path from 'path'
6import * as _ from 'lodash'
7import * as uuidv1 from 'uuid/v1'
8import * as uuidv3 from 'uuid/v3'
9import * as uuidv4 from 'uuid/v4'
10import * as uuidv5 from 'uuid/v5'
11import * as Sequelize from 'sequelize'
12import * as YoutubeDL from 'youtube-dl'
13
14import { initDatabaseModels, sequelizeTypescript } from '../initializers'
15import * as cli from '../tools/cli'
16import { logger } from '../helpers/logger'
17import * as constants from '../initializers/constants'
18import * as modelsUtils from '../models/utils'
19import * as coreUtils from '../helpers/core-utils'
20import * as ffmpegUtils from '../helpers/ffmpeg-utils'
21import * as peertubeCryptoUtils from '../helpers/peertube-crypto'
22import * as signupUtils from '../helpers/signup'
23import * as utils from '../helpers/utils'
24import * as YoutubeDLUtils from '../helpers/youtube-dl'
25
1e59ca3b
BY
26const start = async () => {
27 await initDatabaseModels(true)
28
1b5e2d72 29 const versionCommitHash = await utils.getServerCommit()
1e59ca3b
BY
30
31 const initContext = (replServer) => {
32 return (context) => {
33 const properties = {
34 context, repl: replServer, env: process.env,
35 lodash: _, path,
36 uuidv1, uuidv3, uuidv4, uuidv5,
37 cli, logger, constants,
38 Sequelize, sequelizeTypescript, modelsUtils,
39 models: sequelizeTypescript.models, transaction: sequelizeTypescript.transaction,
40 query: sequelizeTypescript.query, queryInterface: sequelizeTypescript.getQueryInterface(),
41 YoutubeDL,
42 coreUtils, ffmpegUtils, peertubeCryptoUtils, signupUtils, utils, YoutubeDLUtils
43 }
44
45 for (let prop in properties) {
46 Object.defineProperty(context, prop, {
47 configurable: false,
48 enumerable: true,
1a12f66d 49 value: properties[ prop ]
1e59ca3b
BY
50 })
51 }
52 }
53 }
54
55 const replServer = repl.start({
56 prompt: `PeerTube [${cli.version}] (${versionCommitHash})> `
57 })
58
59 initContext(replServer)(replServer.context)
60 replServer.on('reset', initContext(replServer))
1b5e2d72 61 replServer.on('exit', () => process.exit())
1e59ca3b
BY
62
63 const resetCommand = {
64 help: 'Reset REPL',
65 action () {
66 this.write('.clear\n')
67 this.displayPrompt()
68 }
69 }
70 replServer.defineCommand('reset', resetCommand)
71 replServer.defineCommand('r', resetCommand)
72
73}
74
1a12f66d
C
75start()
76 .catch((err) => {
77 console.error(err)
78 })