mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
test1
This commit is contained in:
1 parent
720446b5b4
commit
670b759a98
7 files changed
+114
-30
No files matched your search
@@ -1,7 +1,6 @@
|
||||
const {
|
||||
Route, Connection, Handler, ConnectionHandler,
|
||||
} = global.Hydro.service.server;
|
||||
const { Route, Handler } = global.Hydro.service.server;
|
||||
const { PERM_MANAGE } = global.Hydro.permission;
|
||||
const { message } = global.Hydro.model;
|
||||
const migrate = global.Hydro.script.migrateVijos;
|
||||
|
||||
class MigrateVijosHandler extends Handler {
|
||||
@@ -17,25 +16,21 @@ class MigrateVijosHandler extends Handler {
|
||||
this.response.body = { path };
|
||||
this.response.template = 'migrate_vijos.html';
|
||||
}
|
||||
}
|
||||
|
||||
class MigrateVijosConnectionHandler extends ConnectionHandler {
|
||||
async prepare() {
|
||||
this.checkPerm(PERM_MANAGE);
|
||||
}
|
||||
|
||||
async message(msg) {
|
||||
if (msg.key === 'start') {
|
||||
migrate(msg, (data) => { this.send(data); });
|
||||
}
|
||||
async post({
|
||||
host, port, name, username, password,
|
||||
}) {
|
||||
migrate({
|
||||
host, port, name, username, password,
|
||||
}, (data) => message.send(0, 0, data));
|
||||
this.response.redirect = '/manage/log';
|
||||
}
|
||||
}
|
||||
|
||||
async function apply() {
|
||||
Route('/migrate/vijos', module.exports.MigrateVijosHandler);
|
||||
Connection('/migrate/vijos-conn', module.exports.MigrateVijosConnectionHandler);
|
||||
}
|
||||
|
||||
global.Hydro.handler.pastebin = module.exports = {
|
||||
MigrateVijosHandler, MigrateVijosConnectionHandler, apply,
|
||||
MigrateVijosHandler, apply,
|
||||
};
|
||||
@@ -13,8 +13,8 @@ function parseSolution(doc) {
|
||||
}
|
||||
|
||||
async function problem(src, report) {
|
||||
const count = await src.collection('document').find({ doc_type: 10 }).count();
|
||||
report({ progress: 1, message: `Found ${count} problems.` });
|
||||
let count = await src.collection('document').find({ doc_type: 10 }).count();
|
||||
await report({ progress: 1, message: `Found ${count} problems.` });
|
||||
for (let i = 0; i <= Math.floor(count / 50); i++) {
|
||||
const docs = await src.collection('document').find({ doc_type: 10 })
|
||||
.skip(i * 50).limit(50)
|
||||
@@ -36,12 +36,27 @@ async function problem(src, report) {
|
||||
}
|
||||
await dst.collection('problem').insertMany(problems);
|
||||
}
|
||||
count = await src.collection('document.status').find({ doc_type: 10 }).count();
|
||||
for (let i = 0; i <= Math.floor(count / 50); i++) {
|
||||
const docs = await src.collection('document.status').find({ doc_type: 10 })
|
||||
.skip(i * 50).limit(50)
|
||||
.toArray();
|
||||
const problems = [];
|
||||
for (const doc of docs) {
|
||||
problems.push({
|
||||
pid: doc.pid,
|
||||
rid: doc.rid,
|
||||
});
|
||||
}
|
||||
await dst.collection('problem.status').insertMany(problems);
|
||||
}
|
||||
await report({ progress: 1, message: `Found ${count} problems.` });
|
||||
}
|
||||
|
||||
async function contest(src, report) {
|
||||
const RULES = ['', 'oi', 'acm'];
|
||||
const count = await src.collection('document').find({ doc_type: 30 }).count();
|
||||
report({ progress: 1, message: `Found ${count} contests.` });
|
||||
await report({ progress: 1, message: `Found ${count} contests.` });
|
||||
for (let i = 0; i <= Math.floor(count / 50); i++) {
|
||||
const docs = await src.collection('document').find({ doc_type: 30 })
|
||||
.skip(i * 50).limit(50)
|
||||
@@ -74,12 +89,12 @@ async function migrateVijos({
|
||||
useNewUrlParser: true, useUnifiedTopology: true,
|
||||
});
|
||||
const src = Database.db(name);
|
||||
report({ progress: 0, message: 'Database connected.' });
|
||||
dst.collection('system').insertOne({
|
||||
await report({ progress: 0, message: 'Database connected.' });
|
||||
await dst.collection('system').insertOne({
|
||||
_id: 'user',
|
||||
value: (await src.collection('system').findOne({ _id: 'user_counter' })).value,
|
||||
});
|
||||
report({ progress: 1, message: 'Collection:system done.' });
|
||||
await report({ progress: 1, message: 'Collection:system done.' });
|
||||
await problem(src, report);
|
||||
await contest(src, report);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
{% extends "layout/basic.html" %}
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="medium-9 columns">
|
||||
<div class="section">
|
||||
<div class="section__body">
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
{{ form.form_text({
|
||||
columns:8,
|
||||
label:'Source Database Host',
|
||||
name:'host',
|
||||
value:'127.0.0.1',
|
||||
autofocus:true,
|
||||
row:false
|
||||
}) }}
|
||||
{{ form.form_text({
|
||||
columns:4,
|
||||
label:'Source Database Port',
|
||||
name:'post',
|
||||
value:'27017',
|
||||
row:false
|
||||
}) }}
|
||||
</div><div class="row">
|
||||
{{ form.form_text({
|
||||
columns:4,
|
||||
label:'Source Database Name',
|
||||
name:'name',
|
||||
value:'vijos',
|
||||
row:false
|
||||
}) }}
|
||||
{{ form.form_text({
|
||||
columns:4,
|
||||
label:'Source Database Username',
|
||||
name:'username',
|
||||
placeholder:'Leave empty if none.',
|
||||
row:false
|
||||
}) }}
|
||||
{{ form.form_text({
|
||||
columns:4,
|
||||
label:'Source Database Password',
|
||||
name:'password',
|
||||
placeholder:'Leave empty if none.',
|
||||
row:false
|
||||
}) }}
|
||||
</div>
|
||||
<div class="row"><div class="columns">
|
||||
<input type="hidden" name="csrfToken" value="{{ handler.csrfToken }}">
|
||||
<button type="submit" class="rounded primary button">
|
||||
{{ _('Migrate') }}
|
||||
</button>
|
||||
</div></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="medium-3 columns">
|
||||
{% include 'components/md_hint.html' %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in new issue
Block a user