remove bson & pandora support

This commit is contained in:
undefined committed 2020-07-02 12:32:55 +08:00
1 parent 31622bc580
commit 8051bb958b
23 files changed
+660 -170

No files matched your search

-16
View File
@@ -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');
+3 -2
View File
@@ -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 -1
View File
@@ -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 -1
View File
@@ -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 -1
View File
@@ -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 -1
View File
@@ -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
View File
@@ -1,4 +1,4 @@
const { ObjectID } = require('bson');
const { ObjectID } = require('mongodb');
exports.udoc = {
_id: 0,
+1 -1
View File
@@ -1,4 +1,4 @@
import { ObjectID } from 'bson';
import { ObjectID } from 'mongodb';
export interface Udoc {
_id: number
+6 -4
View File
@@ -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);
+1 -1
View File
@@ -191,7 +191,7 @@ const RULES = {
};
/**
* @typedef {import('bson').ObjectID} ObjectID
* @typedef {import('mongodb').ObjectID} ObjectID
* @typedef {import('../interface').Tdoc} Tdoc
*/
+1 -1
View File
@@ -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 -1
View File
@@ -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');
+1 -1
View File
@@ -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
*/
+2 -2
View File
@@ -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 -1
View File
@@ -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');
+1 -1
View File
@@ -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 -1
View File
@@ -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');
-33
View File
@@ -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;
+1 -1
View File
@@ -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');