mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 09: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,10 +1,7 @@
|
||||
const MarkdownIt = require('markdown-it');
|
||||
const katex = require('markdown-it-katex');
|
||||
const Prism = require('prismjs');
|
||||
const loadLanguages = require('prismjs/components/');
|
||||
|
||||
// FIXME doesnt work in webpack
|
||||
loadLanguages(['js', 'javascript', 'go', 'c', 'pascal', 'hs', 'java', 'cs', 'cpp', 'py', 'ruby']);
|
||||
require('prismjs/components/index');
|
||||
|
||||
class Markdown extends MarkdownIt {
|
||||
constructor(safe) {
|
||||
|
||||
@@ -53,6 +53,12 @@ async function addReply(_id, from, content) {
|
||||
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() {
|
||||
return Promise.all([
|
||||
coll.createIndex({ to: 1, _id: -1 }),
|
||||
@@ -68,5 +74,6 @@ global.Hydro.model.message = module.exports = {
|
||||
getMany,
|
||||
getMulti,
|
||||
addReply,
|
||||
send,
|
||||
index,
|
||||
};
|
||||
+13
-3
@@ -21,10 +21,20 @@ function del(_id) {
|
||||
|
||||
async function getFirst(query) {
|
||||
const res = await coll.find(query).sort('_id', 1).limit(1).toArray();
|
||||
await coll.deleteOne({ _id: res[0]._id });
|
||||
return res[0];
|
||||
if (res) {
|
||||
await coll.deleteOne({ _id: res[0]._id });
|
||||
return res[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function consume(query, cb) {
|
||||
setInterval(async () => {
|
||||
const res = await getFirst(query);
|
||||
if (res) cb(res);
|
||||
}, 100);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
add, get, del, count, getFirst,
|
||||
add, get, del, count, getFirst, consume,
|
||||
};
|
||||
@@ -1,4 +1,3 @@
|
||||
// Webpack Required
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const child = require('child_process');
|
||||
@@ -157,7 +156,7 @@ async function postInit() {
|
||||
await judger[this.config.type || 'default'].judge(this);
|
||||
}
|
||||
}
|
||||
task.consume((t) => {
|
||||
task.consume({ type: 'judge' }, (t) => {
|
||||
(new JudgeTask(t)).handle();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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