mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
remove bson & pandora support
This commit is contained in:
1 parent
31622bc580
commit
8051bb958b
23 files changed
+660
-170
No files matched your search
@@ -1,27 +1,11 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
/* eslint-disable import/no-dynamic-require */
|
||||
const os = require('os');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const {
|
||||
lib, service, model, setting,
|
||||
builtinLib, builtinHandler, builtinModel,
|
||||
} = require('./common');
|
||||
|
||||
function ensureDir(dir) {
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir);
|
||||
} else if (!fs.statSync(dir).isDirectory()) {
|
||||
fs.unlinkSync(dir);
|
||||
fs.mkdirSync(dir);
|
||||
}
|
||||
}
|
||||
|
||||
async function load(call) {
|
||||
ensureDir(path.resolve(os.tmpdir(), 'hydro'));
|
||||
ensureDir(path.resolve(os.tmpdir(), 'hydro', 'tmp'));
|
||||
ensureDir(path.resolve(os.tmpdir(), 'hydro', 'public'));
|
||||
await call({ entry: 'unzip', newProcess: true });
|
||||
let pending = await require('../lib/hpm').getInstalled();
|
||||
const fail = [];
|
||||
require('../lib/i18n');
|
||||
|
||||
@@ -35,10 +35,11 @@ async function load() {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
ensureDir(path.resolve(os.tmpdir(), 'hydro'));
|
||||
ensureDir(path.resolve(os.tmpdir(), 'hydro', 'tmp'));
|
||||
ensureDir(path.resolve(os.tmpdir(), 'hydro', 'public'));
|
||||
const files = fs.readdirSync(moduleRoot);
|
||||
const t = ['service', 'lib', 'model', 'handler', 'script'];
|
||||
ensureDir(`${os.tmpdir()}/hydro`);
|
||||
ensureDir(`${os.tmpdir()}/hydro/tmp`);
|
||||
for (const file of files) {
|
||||
if (file.endsWith('.hydro')) {
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const moment = require('moment-timezone');
|
||||
const { ObjectID } = require('bson');
|
||||
const { ObjectID } = require('mongodb');
|
||||
const AdmZip = require('adm-zip');
|
||||
const {
|
||||
ContestNotLiveError, ValidationError, ProblemNotFoundError,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { ObjectID } = require('bson');
|
||||
const { ObjectID } = require('mongodb');
|
||||
const paginate = require('../lib/paginate');
|
||||
const system = require('../model/system');
|
||||
const user = require('../model/user');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const yaml = require('js-yaml');
|
||||
const moment = require('moment-timezone');
|
||||
const { ObjectID } = require('bson');
|
||||
const { ObjectID } = require('mongodb');
|
||||
const AdmZip = require('adm-zip');
|
||||
const {
|
||||
ValidationError, HomeworkNotLiveError, ProblemNotFoundError,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { ObjectID } = require('bson');
|
||||
const { ObjectID } = require('mongodb');
|
||||
const { PermissionError } = require('../error');
|
||||
const { PERM_READ_RECORD_CODE, PERM_REJUDGE, PERM_VIEW_PROBLEM_HIDDEN } = require('../model/builtin').PERM;
|
||||
const problem = require('../model/problem');
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
const { ObjectID } = require('bson');
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
exports.udoc = {
|
||||
_id: 0,
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import { ObjectID } from 'bson';
|
||||
import { ObjectID } from 'mongodb';
|
||||
|
||||
export interface Udoc {
|
||||
_id: number
|
||||
|
||||
+6
-4
@@ -4,6 +4,8 @@
|
||||
const cluster = require('cluster');
|
||||
const { argv } = require('yargs');
|
||||
|
||||
if (argv.debug) console.log(process.argv);
|
||||
|
||||
async function terminate() {
|
||||
for (const task of global.onDestory) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
@@ -13,7 +15,7 @@ async function terminate() {
|
||||
}
|
||||
|
||||
async function fork(args = []) {
|
||||
cluster.setupMaster({ args, exec: __filename });
|
||||
cluster.setupMaster({ args });
|
||||
return cluster.fork();
|
||||
}
|
||||
|
||||
@@ -82,7 +84,6 @@ async function messageHandler(worker, msg) {
|
||||
async function load() {
|
||||
global.nodeModules = {
|
||||
'adm-zip': require('adm-zip'),
|
||||
bson: require('bson'),
|
||||
superagent: require('superagent'),
|
||||
'js-yaml': require('js-yaml'),
|
||||
mongodb: require('mongodb'),
|
||||
@@ -104,7 +105,7 @@ async function load() {
|
||||
process.on('SIGINT', terminate);
|
||||
process.on('message', messageHandler);
|
||||
cluster.on('message', messageHandler);
|
||||
if (cluster.isMaster) {
|
||||
if (cluster.isMaster || argv.startAsMaster) {
|
||||
console.log(`Master ${process.pid} Starting`);
|
||||
process.stdin.setEncoding('utf8');
|
||||
process.stdin.on('data', (input) => {
|
||||
@@ -117,6 +118,7 @@ async function load() {
|
||||
executeCommand(input);
|
||||
}
|
||||
});
|
||||
await entry({ entry: 'unzip', newProcess: true });
|
||||
const cnt = await entry({ entry: 'master' });
|
||||
console.log('Master started');
|
||||
cluster.on('exit', (worker, code, signal) => {
|
||||
@@ -145,7 +147,7 @@ async function load() {
|
||||
if (global.gc) global.gc();
|
||||
}
|
||||
|
||||
if (!module.parent) {
|
||||
if (argv.pandora || !module.parent) {
|
||||
load().catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
|
||||
@@ -191,7 +191,7 @@ const RULES = {
|
||||
};
|
||||
|
||||
/**
|
||||
* @typedef {import('bson').ObjectID} ObjectID
|
||||
* @typedef {import('mongodb').ObjectID} ObjectID
|
||||
* @typedef {import('../interface').Tdoc} Tdoc
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { ObjectID } = require('bson');
|
||||
const { ObjectID } = require('mongodb');
|
||||
const problem = require('./problem');
|
||||
const document = require('./document');
|
||||
const contest = require('./contest');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const assert = require('assert');
|
||||
const { ObjectID } = require('bson');
|
||||
const { ObjectID } = require('mongodb');
|
||||
const db = require('../service/db');
|
||||
|
||||
const coll = db.collection('document');
|
||||
|
||||
@@ -7,7 +7,7 @@ const coll = db.collection('domain');
|
||||
|
||||
/**
|
||||
* @typedef {import('../interface').Pdoc} Pdoc
|
||||
* @typedef {import('bson').ObjectID} ObjectID
|
||||
* @typedef {import('mongodb').ObjectID} ObjectID
|
||||
* @typedef {import('mongodb').Cursor} Cursor
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { ObjectId } = require('bson');
|
||||
const { ObjectId } = require('mongodb');
|
||||
const { STATUS_ACCEPTED } = require('./builtin').STATUS;
|
||||
const file = require('./file');
|
||||
const document = require('./document');
|
||||
@@ -8,7 +8,7 @@ const readConfig = require('../lib/readConfig');
|
||||
|
||||
/**
|
||||
* @typedef {import('../interface').Pdoc} Pdoc
|
||||
* @typedef {import('bson').ObjectID} ObjectID
|
||||
* @typedef {import('mongodb').ObjectID} ObjectID
|
||||
* @typedef {import('mongodb').Cursor} Cursor
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const _ = require('lodash');
|
||||
const { ObjectID } = require('bson');
|
||||
const { ObjectID } = require('mongodb');
|
||||
const { STATUS_WAITING } = require('./builtin').STATUS;
|
||||
const task = require('./task');
|
||||
const problem = require('./problem');
|
||||
|
||||
@@ -2,7 +2,7 @@ const description = 'Add blacklist by ip, uid';
|
||||
|
||||
// This code format is just for fun. DO NOT DO THIS IN YOUR CODE !
|
||||
/* eslint-disable */
|
||||
const { ObjectID } = require('bson');
|
||||
const { ObjectID } = require('mongodb');
|
||||
const document = require('../model/document');
|
||||
const discussion = require('../model/discussion');
|
||||
const user = require('../model/user');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const description = 'Calculate the rating of a contest';
|
||||
|
||||
const { ObjectID } = require('bson');
|
||||
const { ObjectID } = require('mongodb');
|
||||
const contest = require('../model/contest');
|
||||
const user = require('../model/user');
|
||||
const rating = require('../lib/rating');
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
class Cron {
|
||||
constructor() {
|
||||
this.tasks = [];
|
||||
}
|
||||
|
||||
plan(time, task) {
|
||||
const now = new Date();
|
||||
if (!(time instanceof Date)) time = new Date(time);
|
||||
this.tasks.push({
|
||||
id: setTimeout(() => {
|
||||
for (const i in this.tasks) {
|
||||
if (this.tasks[i].func === task) {
|
||||
this.tasks.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
task();
|
||||
}, time - now),
|
||||
func: task,
|
||||
});
|
||||
}
|
||||
|
||||
interval(time, task) {
|
||||
const now = new Date();
|
||||
if (!(time instanceof Date)) time = new Date(time);
|
||||
this.tasks.push({
|
||||
id: setTimeout(() => { task(); }, time - now),
|
||||
func: task,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Cron;
|
||||
@@ -2,7 +2,7 @@ const assert = require('assert');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
const _ = require('lodash');
|
||||
const { ObjectID } = require('bson');
|
||||
const { ObjectID } = require('mongodb');
|
||||
const Koa = require('koa');
|
||||
const yaml = require('js-yaml');
|
||||
const morgan = require('koa-morgan');
|
||||
|
||||
+1
-2
@@ -9,7 +9,6 @@
|
||||
"@hydrooj/markdown-it-katex": "^2.1.1",
|
||||
"adm-zip": "^0.4.16",
|
||||
"ansi_up": "^4.0.4",
|
||||
"bson": "^4.0.2",
|
||||
"detect-browser": "^5.1.1",
|
||||
"eslint": "7.2.0",
|
||||
"js-yaml": "^3.13.1",
|
||||
@@ -64,4 +63,4 @@
|
||||
]
|
||||
},
|
||||
"snyk": true
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// For pandora
|
||||
|
||||
/**
|
||||
* @param {import('pandora').ProcfileReconcilerAccessor} pandora
|
||||
*/
|
||||
function start(pandora) {
|
||||
pandora
|
||||
.process('Hydro')
|
||||
.scale(1)
|
||||
.args(['--pandora'])
|
||||
.entry('./hydro/loader.js');
|
||||
}
|
||||
|
||||
module.exports = start;
|
||||
@@ -94,28 +94,28 @@ _prepare, prepare, get, post, post[Operation], cleanup, _cleanup
|
||||
先执行 _prepare(args) (如果存在)
|
||||
args 为传入的参数集合(包括 QueryString, Body, Path)中的全部参数,并对以下字段进行了校验:
|
||||
|
||||
| 名称 | 类型 |
|
||||
|:--------:|:-------------:|
|
||||
| content | string |
|
||||
| title | string |
|
||||
| uid | number(int) |
|
||||
| password | string |
|
||||
| mail | string(mail) |
|
||||
| uname | string |
|
||||
| page | number(int) |
|
||||
| duration | number(float) |
|
||||
| role | string |
|
||||
| roles | string[] |
|
||||
| pids | string |
|
||||
| tid | bson.ObjectID |
|
||||
| rid | bson.ObjectID |
|
||||
| did | bson.ObjectID |
|
||||
| drid | bson.ObjectID |
|
||||
| drrid | bson.ObjectID |
|
||||
| psid | bson.ObjectID |
|
||||
| psrid | bson.ObjectID |
|
||||
| docId | bson.ObjectID |
|
||||
| mongoId | bson.ObjectID |
|
||||
| Key | Type |
|
||||
|:--------:|:----------------:|
|
||||
| content | string |
|
||||
| title | string |
|
||||
| uid | number(int) |
|
||||
| password | string |
|
||||
| mail | string(mail) |
|
||||
| uname | string |
|
||||
| page | number(int) |
|
||||
| duration | number(float) |
|
||||
| role | string |
|
||||
| roles | string[] |
|
||||
| pids | string |
|
||||
| tid | mongodb.ObjectID |
|
||||
| rid | mongodb.ObjectID |
|
||||
| did | mongodb.ObjectID |
|
||||
| drid | mongodb.ObjectID |
|
||||
| drrid | mongodb.ObjectID |
|
||||
| psid | mongodb.ObjectID |
|
||||
| psrid | mongodb.ObjectID |
|
||||
| docId | mongodb.ObjectID |
|
||||
| mongoId | mongodb.ObjectID |
|
||||
|
||||
再执行 prepare(args) (如果存在)
|
||||
检查请求类型:
|
||||
|
||||
Reference in new issue
Block a user