mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
+table prefix support
This commit is contained in:
1 parent
b472b5c245
commit
081a75af8c
4 files changed
+15
-6
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.12.10",
|
||||
"version": "2.12.11",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
|
||||
@@ -12,6 +12,7 @@ const tmpdir = path.resolve(os.tmpdir(), 'hydro');
|
||||
const lockfile = path.resolve(tmpdir, 'lock.json');
|
||||
|
||||
export async function load(call: Entry) {
|
||||
fs.ensureDirSync(tmpdir);
|
||||
if (fs.existsSync(lockfile) && !argv.ignorelock) {
|
||||
try {
|
||||
const file = require(lockfile);
|
||||
|
||||
@@ -52,6 +52,12 @@ class Loader {
|
||||
<input name="name" type="text" value="hydro">
|
||||
</label>
|
||||
</div></div>
|
||||
<div class="row"><div class="columns">
|
||||
<label class="inverse material textbox">
|
||||
{{ _('Table Prefix') }}
|
||||
<input name="prefix" type="text" placeholder="{{ _('Leave blank if none') }}">>
|
||||
</label>
|
||||
</div></div>
|
||||
<div class="row"><div class="columns">
|
||||
<label class="inverse material textbox">
|
||||
{{ _('Database Username') }}
|
||||
@@ -103,7 +109,7 @@ async function get(ctx: Context) {
|
||||
|
||||
async function post(ctx: Context) {
|
||||
const {
|
||||
host, port, name, username, password,
|
||||
host, port, name, username, password, prefix,
|
||||
} = ctx.request.body;
|
||||
let mongourl = 'mongodb://';
|
||||
if (username) mongourl += `${username}:${password}@`;
|
||||
@@ -113,23 +119,24 @@ async function post(ctx: Context) {
|
||||
useNewUrlParser: true, useUnifiedTopology: true,
|
||||
});
|
||||
const db = Database.db(name);
|
||||
const coll = prefix ? db.collection('system') : db.collection(`${prefix}.system`);
|
||||
await Promise.all([
|
||||
db.collection('system').updateOne(
|
||||
coll.updateOne(
|
||||
{ _id: 'server.host' },
|
||||
{ $set: { value: ctx.request.host } },
|
||||
{ upsert: true },
|
||||
),
|
||||
db.collection('system').updateOne(
|
||||
coll.updateOne(
|
||||
{ _id: 'server.hostname' },
|
||||
{ $set: { value: ctx.request.hostname } },
|
||||
{ upsert: true },
|
||||
),
|
||||
db.collection('system').updateOne(
|
||||
coll.updateOne(
|
||||
{ _id: 'server.url' },
|
||||
{ $set: { value: ctx.request.href } },
|
||||
{ upsert: true },
|
||||
),
|
||||
db.collection('system').updateOne(
|
||||
coll.updateOne(
|
||||
{ _id: 'server.port' },
|
||||
{ $set: { value: parseInt(listenPort as string, 10) } },
|
||||
{ upsert: true },
|
||||
|
||||
@@ -19,6 +19,7 @@ mongodb.MongoClient.connect(mongourl, { useNewUrlParser: true, useUnifiedTopolog
|
||||
});
|
||||
|
||||
export function collection(c: string) {
|
||||
if (opts.prefix) return db.collection(`${opts.prefix}.${c}`);
|
||||
return db.collection(c);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user