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