diff --git a/packages/hydrooj/bin/hydrooj.js b/packages/hydrooj/bin/hydrooj.js index eb417e91..8269b934 100755 --- a/packages/hydrooj/bin/hydrooj.js +++ b/packages/hydrooj/bin/hydrooj.js @@ -5,6 +5,7 @@ const path = require('path'); const cluster = require('cluster'); const fs = require('fs-extra'); const { argv } = require('yargs'); +const child = require('child_process'); if (!cluster.isMaster) { const hydro = require('../dist/loader'); @@ -14,11 +15,25 @@ if (!cluster.isMaster) { process.exit(1); }); } else { - fs.ensureDirSync(path.resolve(os.homedir(), '.hydro')); - const addonPath = path.resolve(os.homedir(), '.hydro', 'addon.json'); + const hydroPath = path.resolve(os.homedir(), '.hydro'); + fs.ensureDirSync(hydroPath); + const addonPath = path.resolve(hydroPath, 'addon.json'); if (!fs.existsSync(addonPath)) fs.writeFileSync(addonPath, '[]'); let addons = JSON.parse(fs.readFileSync(addonPath).toString()); + if (argv._[0] === 'db') { + function buildUrl(opts) { + let mongourl = `${opts.protocol}://`; + if (opts.username) mongourl += `${opts.username}:${opts.password}@`; + mongourl += `${opts.host}:${opts.port}/${opts.name}`; + if (opts.url) mongourl = opts.url; + return mongourl; + } + const dbConfig = fs.readFileSync(path.resolve(hydroPath, 'config.json'), 'utf-8'); + const url = buildUrl(JSON.parse(dbConfig)); + return child.spawn('mongo', [url], { stdio: 'inherit' }); + } + try { const ui = argv.ui || '@hydrooj/ui-default'; require.resolve(ui); diff --git a/packages/hydrooj/locales/en.yaml b/packages/hydrooj/locales/en.yaml index 45ec8636..ca277a2b 100644 --- a/packages/hydrooj/locales/en.yaml +++ b/packages/hydrooj/locales/en.yaml @@ -36,6 +36,7 @@ homework_main: Homework homework_scoreboard: Scoreboard judge_playground: Judge Playground main: Home +manage_dashboard: Control Panel manage_module: Module Management manage_script: Scripts manage_setting: System Settings @@ -58,6 +59,7 @@ perm_training: Trainings problem_create: Problem Create problem_detail: Problem Detail problem_edit: Problem Edit +problem_files: Problem Files problem_import: Import Problem problem_main: Problem Set problem_solution: Problem Solution @@ -87,6 +89,7 @@ setting_smtp: SMTP Settings setting_usage: Usage Preference timeago_locale: en_US training_create: Training Create +training_detail: Training Detail training_edit: Training Edit training_main: Training user_detail: User Detail diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 3d77d2d7..7c99d784 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.20.32", + "version": "2.20.33", "bin": "bin/hydrooj.js", "main": "dist/loader.js", "typings": "dist/loader.d.ts", diff --git a/packages/hydrooj/src/service/db.ts b/packages/hydrooj/src/service/db.ts index 424e12e1..460d064a 100644 --- a/packages/hydrooj/src/service/db.ts +++ b/packages/hydrooj/src/service/db.ts @@ -3,6 +3,7 @@ import * as bus from './bus'; import { Collections } from '../interface'; interface MongoConfig { + protocol?: string, username?: string, password?: string, host?: string, @@ -19,12 +20,17 @@ class MongoService { public db2: Db; private opts: MongoConfig; - async start(opts: MongoConfig) { - this.opts = opts; - let mongourl = 'mongodb://'; + static buildUrl(opts: MongoConfig) { + let mongourl = `${opts.protocol}://`; if (opts.username) mongourl += `${opts.username}:${opts.password}@`; mongourl += `${opts.host}:${opts.port}/${opts.name}`; if (opts.url) mongourl = opts.url; + return mongourl; + } + + async start(opts: MongoConfig) { + this.opts = opts; + const mongourl = MongoService.buildUrl(opts); this.client = await MongoClient.connect(mongourl, { useNewUrlParser: true, useUnifiedTopology: true }); this.db = this.client.db(opts.name); this.client2 = await MongoClient.connect(mongourl, { useNewUrlParser: true, useUnifiedTopology: true });