mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
Hello Typescript!
This commit is contained in:
1 parent
c9b6412527
commit
ba03d7a7bf
98 files changed
+3186
-2616
No files matched your search
@@ -1,35 +1,35 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
/* eslint-disable no-eval */
|
||||
const os = require('os');
|
||||
const fs = require('fs');
|
||||
const yaml = require('js-yaml');
|
||||
import os from 'os';
|
||||
import fs from 'fs';
|
||||
import yaml from 'js-yaml';
|
||||
|
||||
const builtinLib = [
|
||||
export const builtinLib = [
|
||||
'jwt', 'download', 'i18n', 'mail', 'markdown',
|
||||
'md5', 'misc', 'paginate', 'hash.hydro', 'rank',
|
||||
'template', 'validator', 'nav', 'sysinfo', 'testdata.convert.ini',
|
||||
'readConfig', 'logger', 'useragent',
|
||||
];
|
||||
|
||||
const builtinModel = [
|
||||
export const builtinModel = [
|
||||
'builtin', 'document', 'domain', 'blacklist', 'opcount',
|
||||
'setting', 'token', 'user', 'problem', 'record',
|
||||
'contest', 'message', 'solution', 'training', 'file',
|
||||
'discussion', 'system',
|
||||
];
|
||||
|
||||
const builtinHandler = [
|
||||
export const builtinHandler = [
|
||||
'home', 'problem', 'record', 'judge', 'user',
|
||||
'contest', 'training', 'discussion', 'manage', 'import',
|
||||
'misc', 'homework', 'domain', 'wiki',
|
||||
];
|
||||
|
||||
const builtinScript = [
|
||||
export const builtinScript = [
|
||||
'install', 'rating', 'recalcRating', 'register', 'problemStat',
|
||||
'blacklist', 'setSuperadmin', 'deleteUser',
|
||||
];
|
||||
|
||||
async function handler(pending, fail) {
|
||||
export async function handler(pending, fail) {
|
||||
for (const i of pending) {
|
||||
const p = `${os.tmpdir()}/hydro/tmp/${i}/handler.js`;
|
||||
if (fs.existsSync(p) && !fail.includes(i)) {
|
||||
@@ -46,7 +46,7 @@ async function handler(pending, fail) {
|
||||
}
|
||||
}
|
||||
|
||||
async function locale(pending, fail) {
|
||||
export async function locale(pending, fail) {
|
||||
for (const i of pending) {
|
||||
const p = `${os.tmpdir()}/hydro/tmp/${i}/locale.json`;
|
||||
if (fs.existsSync(p) && !fail.includes(i)) {
|
||||
@@ -61,7 +61,7 @@ async function locale(pending, fail) {
|
||||
}
|
||||
}
|
||||
|
||||
async function setting(pending, fail, modelSetting, modelSystem) {
|
||||
export async function setting(pending, fail, modelSetting, modelSystem = null) {
|
||||
const map = {
|
||||
system: modelSetting.SystemSetting,
|
||||
account: modelSetting.AccountSetting,
|
||||
@@ -71,7 +71,7 @@ async function setting(pending, fail, modelSetting, modelSystem) {
|
||||
const p = `${os.tmpdir()}/hydro/tmp/${i}/setting.yaml`;
|
||||
if (fs.existsSync(p) && !fail.includes(i)) {
|
||||
try {
|
||||
const cfg = yaml.safeLoad(fs.readFileSync(p).toString());
|
||||
const cfg: any = yaml.safeLoad(fs.readFileSync(p).toString());
|
||||
for (const key in cfg) {
|
||||
if (cfg[key].default && modelSystem) {
|
||||
const current = await modelSystem.get(`${i}.${key}`);
|
||||
@@ -91,7 +91,7 @@ async function setting(pending, fail, modelSetting, modelSystem) {
|
||||
}
|
||||
}
|
||||
|
||||
async function template(pending, fail) {
|
||||
export async function template(pending, fail) {
|
||||
for (const i of pending) {
|
||||
const p = `${os.tmpdir()}/hydro/tmp/${i}/template.json`;
|
||||
if (fs.existsSync(p) && !fail.includes(i)) {
|
||||
@@ -106,7 +106,7 @@ async function template(pending, fail) {
|
||||
}
|
||||
}
|
||||
|
||||
async function model(pending, fail) {
|
||||
export async function model(pending, fail) {
|
||||
for (const i of pending) {
|
||||
const p = `${os.tmpdir()}/hydro/tmp/${i}/model.js`;
|
||||
if (fs.existsSync(p) && !fail.includes(i)) {
|
||||
@@ -123,7 +123,7 @@ async function model(pending, fail) {
|
||||
}
|
||||
}
|
||||
|
||||
async function lib(pending, fail) {
|
||||
export async function lib(pending, fail) {
|
||||
for (const i of pending) {
|
||||
const p = `${os.tmpdir()}/hydro/tmp/${i}/lib.js`;
|
||||
if (fs.existsSync(p) && !fail.includes(i)) {
|
||||
@@ -141,7 +141,7 @@ async function lib(pending, fail) {
|
||||
}
|
||||
}
|
||||
|
||||
async function service(pending, fail) {
|
||||
export async function service(pending, fail) {
|
||||
for (const i of pending) {
|
||||
const p = `${os.tmpdir()}/hydro/tmp/${i}/service.js`;
|
||||
if (fs.existsSync(p) && !fail.includes(i)) {
|
||||
@@ -159,7 +159,7 @@ async function service(pending, fail) {
|
||||
}
|
||||
}
|
||||
|
||||
async function script(pending, fail, active) {
|
||||
export async function script(pending, fail, active) {
|
||||
for (const i of pending) {
|
||||
const p = `${os.tmpdir()}/hydro/tmp/${i}/script.js`;
|
||||
if (fs.existsSync(p) && !fail.includes(i)) {
|
||||
@@ -176,18 +176,3 @@ async function script(pending, fail, active) {
|
||||
active.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
builtinLib,
|
||||
builtinModel,
|
||||
builtinHandler,
|
||||
builtinScript,
|
||||
handler,
|
||||
lib,
|
||||
locale,
|
||||
model,
|
||||
script,
|
||||
service,
|
||||
template,
|
||||
setting,
|
||||
};
|
||||
@@ -1,11 +1,11 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
/* eslint-disable import/no-dynamic-require */
|
||||
const {
|
||||
import {
|
||||
lib, service, model, setting,
|
||||
builtinLib, builtinHandler, builtinModel,
|
||||
} = require('./common');
|
||||
} from './common';
|
||||
|
||||
async function load(call) {
|
||||
export async function load(call) {
|
||||
let pending = await require('../lib/hpm').getInstalled();
|
||||
const fail = [];
|
||||
require('../lib/i18n');
|
||||
@@ -14,10 +14,10 @@ async function load(call) {
|
||||
try {
|
||||
require('../options');
|
||||
} catch (e) {
|
||||
await call({ entry: 'install' });
|
||||
await call({ entry: 'setup' });
|
||||
require('../options');
|
||||
}
|
||||
const bus = require('../service/bus');
|
||||
const bus = require('../service/bus').default;
|
||||
await new Promise((resolve) => {
|
||||
const h = () => {
|
||||
console.log('Database connected');
|
||||
@@ -32,7 +32,7 @@ async function load(call) {
|
||||
require('../service/gridfs');
|
||||
require('../service/monitor');
|
||||
const server = require('../service/server');
|
||||
await server.prepare();
|
||||
await server.default.prepare();
|
||||
await service(pending, fail);
|
||||
for (const i of builtinModel) require(`../model/${i}`);
|
||||
for (const i of builtinHandler) require(`../handler/${i}`);
|
||||
@@ -62,5 +62,3 @@ async function load(call) {
|
||||
pending = [];
|
||||
return await modelSystem.get('server.worker');
|
||||
}
|
||||
|
||||
module.exports = load;
|
||||
@@ -1,16 +1,16 @@
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const http = require('http');
|
||||
const Koa = require('koa');
|
||||
const Body = require('koa-body');
|
||||
const Router = require('koa-router');
|
||||
const cache = require('koa-static-cache');
|
||||
const nunjucks = require('nunjucks');
|
||||
const mongodb = require('mongodb');
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import http from 'http';
|
||||
import Koa from 'koa';
|
||||
import Body from 'koa-body';
|
||||
import Router from 'koa-router';
|
||||
import cache from 'koa-static-cache';
|
||||
import nunjucks from 'nunjucks';
|
||||
import mongodb from 'mongodb';
|
||||
|
||||
class Loader {
|
||||
getSource(name) { // eslint-disable-line class-methods-use-this
|
||||
getSource(name: string) { // eslint-disable-line class-methods-use-this
|
||||
return {
|
||||
src: `
|
||||
<!DOCTYPE html>
|
||||
@@ -76,6 +76,7 @@ class Loader {
|
||||
</html>
|
||||
`,
|
||||
path: name,
|
||||
noCache: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -93,7 +94,7 @@ function render(name) {
|
||||
});
|
||||
}
|
||||
|
||||
async function load() {
|
||||
export async function load() {
|
||||
const app = new Koa();
|
||||
const server = http.createServer(app.callback());
|
||||
const router = new Router();
|
||||
@@ -158,5 +159,3 @@ async function load() {
|
||||
});
|
||||
return 'Done! Restarting...';
|
||||
}
|
||||
|
||||
module.exports = load;
|
||||
@@ -1,8 +1,8 @@
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const zlib = require('zlib');
|
||||
const yaml = require('js-yaml');
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import zlib from 'zlib';
|
||||
import yaml from 'js-yaml';
|
||||
|
||||
function ensureDir(dir) {
|
||||
if (!fs.existsSync(dir)) {
|
||||
@@ -30,7 +30,8 @@ for (const i of moduleRoots) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
async function load() {
|
||||
|
||||
export async function load() {
|
||||
process.on('unhandledRejection', (e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
@@ -45,7 +46,7 @@ async function load() {
|
||||
try {
|
||||
const f = fs.readFileSync(root(`${moduleRoot}/${file}`));
|
||||
const s = fs.statSync(root(`${moduleRoot}/${file}`));
|
||||
const m = yaml.safeLoad(zlib.gunzipSync(f));
|
||||
const m: any = yaml.safeLoad(zlib.gunzipSync(f).toString());
|
||||
const { id } = m;
|
||||
if (m.os) {
|
||||
if (!m.os.includes(os.platform().toLowerCase())) {
|
||||
@@ -123,5 +124,3 @@ async function load() {
|
||||
console.log('Unzip done.');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
module.exports = load;
|
||||
@@ -1,11 +1,11 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
/* eslint-disable import/no-dynamic-require */
|
||||
const {
|
||||
import {
|
||||
locale, template, lib, service, model, handler, script, setting,
|
||||
builtinLib, builtinScript, builtinHandler, builtinModel,
|
||||
} = require('./common');
|
||||
} from './common';
|
||||
|
||||
async function load() {
|
||||
export async function load() {
|
||||
let pending = await require('../lib/hpm').getInstalled();
|
||||
const fail = [];
|
||||
const active = [];
|
||||
@@ -27,7 +27,7 @@ async function load() {
|
||||
for (const i of builtinLib) require(`../lib/${i}`);
|
||||
await lib(pending, fail);
|
||||
require('../service/gridfs');
|
||||
const server = require('../service/server');
|
||||
const server = require('../service/server').default;
|
||||
await server.prepare();
|
||||
await service(pending, fail);
|
||||
for (const i of builtinModel) require(`../model/${i}`);
|
||||
@@ -40,7 +40,7 @@ async function load() {
|
||||
await global.Hydro.handler[i]();
|
||||
}
|
||||
const notfound = require('../handler/notfound');
|
||||
await notfound();
|
||||
await notfound.apply();
|
||||
for (const i in global.Hydro.service) {
|
||||
if (global.Hydro.service[i].postInit) {
|
||||
try {
|
||||
@@ -60,5 +60,3 @@ async function load() {
|
||||
}, 30 * 1000);
|
||||
return { active, fail };
|
||||
}
|
||||
|
||||
module.exports = load;
|
||||
Reference in new issue
Block a user