This commit is contained in:
undefined committed 2020-05-11 12:15:52 +08:00
1 parent 720446b5b4
commit 670b759a98
7 files changed
+112 -28

No files matched your search

+1 -4
View File
@@ -1,10 +1,7 @@
const MarkdownIt = require('markdown-it'); const MarkdownIt = require('markdown-it');
const katex = require('markdown-it-katex'); const katex = require('markdown-it-katex');
const Prism = require('prismjs'); const Prism = require('prismjs');
const loadLanguages = require('prismjs/components/'); require('prismjs/components/index');
// FIXME doesnt work in webpack
loadLanguages(['js', 'javascript', 'go', 'c', 'pascal', 'hs', 'java', 'cs', 'cpp', 'py', 'ruby']);
class Markdown extends MarkdownIt { class Markdown extends MarkdownIt {
constructor(safe) { constructor(safe) {
+7
View File
@@ -53,6 +53,12 @@ async function addReply(_id, from, content) {
return await coll.findOne({ _id }); // eslint-disable-line no-return-await return await coll.findOne({ _id }); // eslint-disable-line no-return-await
} }
async function send(from, to, content) {
const sdoc = await coll.findOne({ $or: [{ from, to }, { from: to, to: from }] });
await addReply(sdoc._id, from, content);
return sdoc._id;
}
function index() { function index() {
return Promise.all([ return Promise.all([
coll.createIndex({ to: 1, _id: -1 }), coll.createIndex({ to: 1, _id: -1 }),
@@ -68,5 +74,6 @@ global.Hydro.model.message = module.exports = {
getMany, getMany,
getMulti, getMulti,
addReply, addReply,
send,
index, index,
}; };
+11 -1
View File
@@ -21,10 +21,20 @@ function del(_id) {
async function getFirst(query) { async function getFirst(query) {
const res = await coll.find(query).sort('_id', 1).limit(1).toArray(); const res = await coll.find(query).sort('_id', 1).limit(1).toArray();
if (res) {
await coll.deleteOne({ _id: res[0]._id }); await coll.deleteOne({ _id: res[0]._id });
return res[0]; return res[0];
}
return null;
}
async function consume(query, cb) {
setInterval(async () => {
const res = await getFirst(query);
if (res) cb(res);
}, 100);
} }
module.exports = { module.exports = {
add, get, del, count, getFirst, add, get, del, count, getFirst, consume,
}; };
+1 -2
View File
@@ -1,4 +1,3 @@
// Webpack Required
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const child = require('child_process'); const child = require('child_process');
@@ -157,7 +156,7 @@ async function postInit() {
await judger[this.config.type || 'default'].judge(this); await judger[this.config.type || 'default'].judge(this);
} }
} }
task.consume((t) => { task.consume({ type: 'judge' }, (t) => {
(new JudgeTask(t)).handle(); (new JudgeTask(t)).handle();
}); });
} }
+10 -15
View File
@@ -1,7 +1,6 @@
const { const { Route, Handler } = global.Hydro.service.server;
Route, Connection, Handler, ConnectionHandler,
} = global.Hydro.service.server;
const { PERM_MANAGE } = global.Hydro.permission; const { PERM_MANAGE } = global.Hydro.permission;
const { message } = global.Hydro.model;
const migrate = global.Hydro.script.migrateVijos; const migrate = global.Hydro.script.migrateVijos;
class MigrateVijosHandler extends Handler { class MigrateVijosHandler extends Handler {
@@ -17,25 +16,21 @@ class MigrateVijosHandler extends Handler {
this.response.body = { path }; this.response.body = { path };
this.response.template = 'migrate_vijos.html'; this.response.template = 'migrate_vijos.html';
} }
}
class MigrateVijosConnectionHandler extends ConnectionHandler { async post({
async prepare() { host, port, name, username, password,
this.checkPerm(PERM_MANAGE); }) {
} migrate({
host, port, name, username, password,
async message(msg) { }, (data) => message.send(0, 0, data));
if (msg.key === 'start') { this.response.redirect = '/manage/log';
migrate(msg, (data) => { this.send(data); });
}
} }
} }
async function apply() { async function apply() {
Route('/migrate/vijos', module.exports.MigrateVijosHandler); Route('/migrate/vijos', module.exports.MigrateVijosHandler);
Connection('/migrate/vijos-conn', module.exports.MigrateVijosConnectionHandler);
} }
global.Hydro.handler.pastebin = module.exports = { global.Hydro.handler.pastebin = module.exports = {
MigrateVijosHandler, MigrateVijosConnectionHandler, apply, MigrateVijosHandler, apply,
}; };
+21 -6
View File
@@ -13,8 +13,8 @@ function parseSolution(doc) {
} }
async function problem(src, report) { async function problem(src, report) {
const count = await src.collection('document').find({ doc_type: 10 }).count(); let count = await src.collection('document').find({ doc_type: 10 }).count();
report({ progress: 1, message: `Found ${count} problems.` }); await report({ progress: 1, message: `Found ${count} problems.` });
for (let i = 0; i <= Math.floor(count / 50); i++) { for (let i = 0; i <= Math.floor(count / 50); i++) {
const docs = await src.collection('document').find({ doc_type: 10 }) const docs = await src.collection('document').find({ doc_type: 10 })
.skip(i * 50).limit(50) .skip(i * 50).limit(50)
@@ -36,12 +36,27 @@ async function problem(src, report) {
} }
await dst.collection('problem').insertMany(problems); 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) { async function contest(src, report) {
const RULES = ['', 'oi', 'acm']; const RULES = ['', 'oi', 'acm'];
const count = await src.collection('document').find({ doc_type: 30 }).count(); 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++) { for (let i = 0; i <= Math.floor(count / 50); i++) {
const docs = await src.collection('document').find({ doc_type: 30 }) const docs = await src.collection('document').find({ doc_type: 30 })
.skip(i * 50).limit(50) .skip(i * 50).limit(50)
@@ -74,12 +89,12 @@ async function migrateVijos({
useNewUrlParser: true, useUnifiedTopology: true, useNewUrlParser: true, useUnifiedTopology: true,
}); });
const src = Database.db(name); const src = Database.db(name);
report({ progress: 0, message: 'Database connected.' }); await report({ progress: 0, message: 'Database connected.' });
dst.collection('system').insertOne({ await dst.collection('system').insertOne({
_id: 'user', _id: 'user',
value: (await src.collection('system').findOne({ _id: 'user_counter' })).value, 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 problem(src, report);
await contest(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 %}