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