aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/tools/repl.ts79
1 files changed, 79 insertions, 0 deletions
diff --git a/server/tools/repl.ts b/server/tools/repl.ts
new file mode 100644
index 000000000..6800ff8ab
--- /dev/null
+++ b/server/tools/repl.ts
@@ -0,0 +1,79 @@
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
23let versionCommitHash
24
25const start = async () => {
26 await initDatabaseModels(true)
27
28 await utils.getVersion().then((data) => {
29 versionCommitHash = data
30 })
31
32 const initContext = (replServer) => {
33 return (context) => {
34 const properties = {
35 context, repl: replServer, env: process.env,
36 lodash: _, path,
37 uuidv1, uuidv3, uuidv4, uuidv5,
38 cli, logger, constants,
39 Sequelize, sequelizeTypescript, modelsUtils,
40 models: sequelizeTypescript.models, transaction: sequelizeTypescript.transaction,
41 query: sequelizeTypescript.query, queryInterface: sequelizeTypescript.getQueryInterface(),
42 YoutubeDL,
43 coreUtils, ffmpegUtils, peertubeCryptoUtils, signupUtils, utils, YoutubeDLUtils
44 }
45
46 for (let prop in properties) {
47 Object.defineProperty(context, prop, {
48 configurable: false,
49 enumerable: true,
50 value: properties[prop]
51 })
52 }
53 }
54 }
55
56 const replServer = repl.start({
57 prompt: `PeerTube [${cli.version}] (${versionCommitHash})> `
58 })
59
60 initContext(replServer)(replServer.context)
61 replServer.on('reset', initContext(replServer))
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
75start().then((data) => {
76 // do nothing
77}).catch((err) => {
78 console.error(err)
79})