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