Add player mode in watch/embed urls
[oweals/peertube.git] / server / tools / peertube-repl.ts
1 import * as repl from 'repl'
2 import * as path from 'path'
3 import * as _ from 'lodash'
4 import * as uuidv1 from 'uuid/v1'
5 import * as uuidv3 from 'uuid/v3'
6 import * as uuidv4 from 'uuid/v4'
7 import * as uuidv5 from 'uuid/v5'
8 import * as Sequelize from 'sequelize'
9 import * as YoutubeDL from 'youtube-dl'
10
11 import { initDatabaseModels, sequelizeTypescript } from '../initializers'
12 import * as cli from '../tools/cli'
13 import { logger } from '../helpers/logger'
14 import * as constants from '../initializers/constants'
15 import * as modelsUtils from '../models/utils'
16 import * as coreUtils from '../helpers/core-utils'
17 import * as ffmpegUtils from '../helpers/ffmpeg-utils'
18 import * as peertubeCryptoUtils from '../helpers/peertube-crypto'
19 import * as signupUtils from '../helpers/signup'
20 import * as utils from '../helpers/utils'
21 import * as YoutubeDLUtils from '../helpers/youtube-dl'
22
23 const start = async () => {
24   await initDatabaseModels(true)
25
26   const versionCommitHash = await utils.getServerCommit()
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,
46           value: properties[prop]
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))
58   replServer.on('exit', () => process.exit())
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
72 start().then((data) => {
73   // do nothing
74 }).catch((err) => {
75   console.error(err)
76 })