mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
webpack hot reload support
This commit is contained in:
1 parent
d8e1a63f99
commit
0ee306d0cf
15 files changed
+89
-63
No files matched your search
@@ -220,11 +220,9 @@ export async function wiki(pending: string[], fail: string[]) {
|
|||||||
try {
|
try {
|
||||||
const categories = fs.readdirSync(p);
|
const categories = fs.readdirSync(p);
|
||||||
for (const category of categories) {
|
for (const category of categories) {
|
||||||
console.log('category', category);
|
|
||||||
if (!fs.statSync(p).isDirectory()) return;
|
if (!fs.statSync(p).isDirectory()) return;
|
||||||
const pages = fs.readdirSync(path.join(p, category));
|
const pages = fs.readdirSync(path.join(p, category));
|
||||||
if (!global.Hydro.wiki[category]) global.Hydro.wiki[category] = {};
|
if (!global.Hydro.wiki[category]) global.Hydro.wiki[category] = {};
|
||||||
console.log(pages);
|
|
||||||
for (const page of pages) {
|
for (const page of pages) {
|
||||||
const c = fs.readFileSync(path.join(p, category, page)).toString().split('\n');
|
const c = fs.readFileSync(path.join(p, category, page)).toString().split('\n');
|
||||||
const pagename = page.split('.')[0];
|
const pagename = page.split('.')[0];
|
||||||
|
|||||||
@@ -57,9 +57,9 @@ class SystemCheckConnHandler extends ConnectionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async check() {
|
async check() {
|
||||||
const log = (payload) => this.send({ type: 'log', payload });
|
const log = (payload: any) => this.send({ type: 'log', payload });
|
||||||
const warn = (payload) => this.send({ type: 'warn', payload });
|
const warn = (payload: any) => this.send({ type: 'warn', payload });
|
||||||
const error = (payload) => this.send({ type: 'error', payload });
|
const error = (payload: any) => this.send({ type: 'error', payload });
|
||||||
await check.start(log, warn, error, (id) => { this.id = id; });
|
await check.start(log, warn, error, (id) => { this.id = id; });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,10 +108,10 @@ class SystemScriptHandler extends SystemHandler {
|
|||||||
args = JSON.parse(args);
|
args = JSON.parse(args);
|
||||||
validate(global.Hydro.script[id].validate, args);
|
validate(global.Hydro.script[id].validate, args);
|
||||||
const rid = await record.add(domainId, {
|
const rid = await record.add(domainId, {
|
||||||
pid: 1,
|
pid: -1,
|
||||||
uid: this.user._id,
|
uid: this.user._id,
|
||||||
lang: null,
|
lang: '-',
|
||||||
code: null,
|
code: id,
|
||||||
status: STATUS.STATUS_JUDGING,
|
status: STATUS.STATUS_JUDGING,
|
||||||
hidden: true,
|
hidden: true,
|
||||||
}, false);
|
}, false);
|
||||||
@@ -122,7 +122,7 @@ class SystemScriptHandler extends SystemHandler {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const start = new Date().getTime();
|
const start = new Date().getTime();
|
||||||
global.Hydro.script[id].run(args, report)
|
global.Hydro.script[id].run(args, report)
|
||||||
.then((ret) => {
|
.then((ret: any) => {
|
||||||
const time = new Date().getTime() - start;
|
const time = new Date().getTime() - start;
|
||||||
judge.end({
|
judge.end({
|
||||||
domainId,
|
domainId,
|
||||||
@@ -146,7 +146,7 @@ class SystemScriptHandler extends SystemHandler {
|
|||||||
memory_kb: 0,
|
memory_kb: 0,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, 500);
|
}, 300);
|
||||||
this.response.body = { rid };
|
this.response.body = { rid };
|
||||||
this.response.redirect = this.url('record_detail', { rid });
|
this.response.redirect = this.url('record_detail', { rid });
|
||||||
}
|
}
|
||||||
@@ -192,4 +192,4 @@ async function apply() {
|
|||||||
Connection('manage_check', '/manage/check-conn', SystemCheckConnHandler);
|
Connection('manage_check', '/manage/check-conn', SystemCheckConnHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
global.Hydro.handler.manage = module.exports = apply;
|
global.Hydro.handler.manage = apply;
|
||||||
@@ -201,15 +201,15 @@ class UserSearchHandler extends Handler {
|
|||||||
@param('q', Types.String)
|
@param('q', Types.String)
|
||||||
@param('exectMatch', Types.Boolean, true)
|
@param('exectMatch', Types.Boolean, true)
|
||||||
async get(domainId: string, q: string, exactMatch = false) {
|
async get(domainId: string, q: string, exactMatch = false) {
|
||||||
let udocs;
|
let udoc = await user.getById(domainId, parseInt(q, 10));
|
||||||
if (exactMatch) udocs = [];
|
const udocs = udoc ? [udoc] : [];
|
||||||
else udocs = await user.getPrefixList(q, 20);
|
udoc = await user.getByUname(domainId, q);
|
||||||
const udoc = await user.getById(domainId, parseInt(q, 10));
|
|
||||||
if (udoc) udocs.push(udoc);
|
if (udoc) udocs.push(udoc);
|
||||||
|
udoc = await user.getByEmail(domainId, q);
|
||||||
|
if (udoc) udocs.push(udoc);
|
||||||
|
if (!exactMatch) udocs.push(...await user.getPrefixList(q, 20));
|
||||||
for (const i in udocs) {
|
for (const i in udocs) {
|
||||||
if (udocs[i].gravatar) {
|
udocs[i].gravatar = misc.gravatar(udocs[i].gravatar || '');
|
||||||
udocs[i].gravatar = misc.gravatar(udocs[i].gravatar);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.response.body = udocs;
|
this.response.body = udocs;
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-1
@@ -90,7 +90,18 @@ class RatingCalculator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculate(users: any[]) {
|
interface RatingInputUser {
|
||||||
|
old: number,
|
||||||
|
uid: number,
|
||||||
|
rank: number,
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RatingOutputUser {
|
||||||
|
new: number,
|
||||||
|
uid: number,
|
||||||
|
}
|
||||||
|
|
||||||
|
function calculate(users: RatingInputUser[]): RatingOutputUser[] {
|
||||||
const calculator = new RatingCalculator(users);
|
const calculator = new RatingCalculator(users);
|
||||||
return calculator.calculate();
|
return calculator.calculate();
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-18
@@ -23,36 +23,23 @@ function calc(udict: ND, rankedDocs: [number, number][]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runProblem(pdoc: Pdoc, udict: ND, report: Function): Promise<void>
|
async function runProblem(pdoc: Pdoc, udict: ND): Promise<void>
|
||||||
async function runProblem(
|
async function runProblem(domainId: string, pid: number, udict: ND): Promise<void>
|
||||||
domainId: string, pid: number, udict: ND, report: Function
|
|
||||||
): Promise<void>
|
|
||||||
async function runProblem(...arg: Array<any>) {
|
async function runProblem(...arg: Array<any>) {
|
||||||
const start = new Date().getTime();
|
|
||||||
const pdoc: Pdoc = (typeof arg[0] === 'string')
|
const pdoc: Pdoc = (typeof arg[0] === 'string')
|
||||||
? await contest.get(arg[0], arg[1], -1)
|
? await contest.get(arg[0], arg[1], -1)
|
||||||
: arg[0];
|
: arg[0];
|
||||||
const udict: ND = (typeof arg[0] === 'string') ? arg[2] : arg[1];
|
const udict: ND = (typeof arg[0] === 'string') ? arg[2] : arg[1];
|
||||||
const report = (typeof arg[0] === 'string') ? arg[3] : arg[2];
|
|
||||||
// TODO maybe some other rules?
|
// TODO maybe some other rules?
|
||||||
// TODO pagination
|
// TODO pagination
|
||||||
const psdocs = await problem.getMultiStatus(
|
const psdocs = await problem.getMultiStatus(
|
||||||
pdoc.domainId, { docId: pdoc.docId, status: STATUS.STATUS_ACCEPTED },
|
pdoc.domainId, { docId: pdoc.docId, status: STATUS.STATUS_ACCEPTED },
|
||||||
).sort('rid', 1).toArray();
|
).sort('rid', 1).toArray();
|
||||||
const ranked = [];
|
const ranked = [];
|
||||||
for (const index of psdocs) {
|
for (const index in psdocs) {
|
||||||
ranked.push([index + 1, psdocs[index].uid]);
|
ranked.push([index + 1, psdocs[index].uid]);
|
||||||
}
|
}
|
||||||
calc(udict, ranked);
|
calc(udict, ranked);
|
||||||
await report({
|
|
||||||
case: {
|
|
||||||
status: STATUS.STATUS_ACCEPTED,
|
|
||||||
judgeText: `Problem ${pdoc.title} finished`,
|
|
||||||
time_ms: new Date().getTime() - start,
|
|
||||||
memory_kb: 0,
|
|
||||||
score: 0,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runContest(tdoc: Tdoc, udict: ND, report: Function): Promise<void>
|
async function runContest(tdoc: Tdoc, udict: ND, report: Function): Promise<void>
|
||||||
@@ -93,7 +80,7 @@ async function runInDomain(domainId: string, isSub: boolean, report: Function) {
|
|||||||
await report({ message: `Found ${problems.length} problems in ${domainId}` });
|
await report({ message: `Found ${problems.length} problems in ${domainId}` });
|
||||||
for (const i in problems) {
|
for (const i in problems) {
|
||||||
const pdoc = problems[i];
|
const pdoc = problems[i];
|
||||||
runProblem(pdoc, udict, report);
|
runProblem(pdoc, udict);
|
||||||
if (!isSub) {
|
if (!isSub) {
|
||||||
await report({
|
await report({
|
||||||
progress: Math.floor(((parseInt(i, 10) + 1) / problems.length) * 100),
|
progress: Math.floor(((parseInt(i, 10) + 1) / problems.length) * 100),
|
||||||
@@ -147,4 +134,4 @@ export const validate = {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
global.Hydro.script.recalcRating = { run, description, validate };
|
global.Hydro.script.rating = { run, description, validate };
|
||||||
+19
-7
@@ -20,7 +20,7 @@ import {
|
|||||||
UserNotFoundError, BlacklistedError, PermissionError,
|
UserNotFoundError, BlacklistedError, PermissionError,
|
||||||
UserFacingError, ValidationError, PrivilegeError,
|
UserFacingError, ValidationError, PrivilegeError,
|
||||||
CsrfTokenError, InvalidOperationError, MethodNotAllowedError,
|
CsrfTokenError, InvalidOperationError, MethodNotAllowedError,
|
||||||
NotFoundError,
|
NotFoundError, HydroError,
|
||||||
} from '../error';
|
} from '../error';
|
||||||
import { render } from '../lib/template';
|
import { render } from '../lib/template';
|
||||||
import hash from '../lib/hash.hydro';
|
import hash from '../lib/hash.hydro';
|
||||||
@@ -169,9 +169,15 @@ export function requireCsrfToken(target: any, funcName: string, obj: any) {
|
|||||||
export async function prepare() {
|
export async function prepare() {
|
||||||
server = http.createServer(app.callback());
|
server = http.createServer(app.callback());
|
||||||
app.keys = await system.get('session.keys');
|
app.keys = await system.get('session.keys');
|
||||||
app.use(cache(path.join(os.tmpdir(), 'hydro', 'public'), {
|
if (process.env.debug) {
|
||||||
maxAge: 365 * 24 * 60 * 60,
|
app.use(cache(path.join(process.cwd(), 'public'), {
|
||||||
}));
|
maxAge: 0,
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
app.use(cache(path.join(os.tmpdir(), 'hydro', 'public'), {
|
||||||
|
maxAge: 365 * 24 * 60 * 60,
|
||||||
|
}));
|
||||||
|
}
|
||||||
app.use(Body({
|
app.use(Body({
|
||||||
multipart: true,
|
multipart: true,
|
||||||
formidable: {
|
formidable: {
|
||||||
@@ -553,8 +559,8 @@ async function handle(ctx, HandlerClass, checker) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Checker = (permPrivChecker) => {
|
const Checker = (permPrivChecker) => {
|
||||||
let perm;
|
let perm: bigint;
|
||||||
let priv;
|
let priv: number;
|
||||||
let checker = () => { };
|
let checker = () => { };
|
||||||
for (const item of permPrivChecker) {
|
for (const item of permPrivChecker) {
|
||||||
if (typeof item === 'object') {
|
if (typeof item === 'object') {
|
||||||
@@ -694,8 +700,14 @@ export class ConnectionHandler {
|
|||||||
this.conn.close(code.toString(), reason);
|
this.conn.close(code.toString(), reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
onerror(err: Error) {
|
onerror(err: HydroError) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
this.send({
|
||||||
|
error: {
|
||||||
|
name: err.name,
|
||||||
|
params: err.params || [],
|
||||||
|
},
|
||||||
|
});
|
||||||
this.close(1001, err.toString());
|
this.close(1001, err.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ export default function ({ watch, production, errorHandler }) {
|
|||||||
.pipe(gulp.dest('misc/.iconfont'))
|
.pipe(gulp.dest('misc/.iconfont'))
|
||||||
.pipe(offsetMtimeAtFirstBuild());
|
.pipe(offsetMtimeAtFirstBuild());
|
||||||
|
|
||||||
|
|
||||||
tasks.iconfont = () => gulp
|
tasks.iconfont = () => gulp
|
||||||
.src('misc/icons/*.svg')
|
.src('misc/icons/*.svg')
|
||||||
.pipe(plumber({ errorHandler }))
|
.pipe(plumber({ errorHandler }))
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* eslint-disable import/no-extraneous-dependencies */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import webpack from 'webpack';
|
import webpack from 'webpack';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs';
|
||||||
|
|
||||||
import MonacoWebpackPlugin from 'monaco-editor-webpack-plugin';
|
import MonacoWebpackPlugin from 'monaco-editor-webpack-plugin';
|
||||||
import FriendlyErrorsPlugin from 'friendly-errors-webpack-plugin';
|
import FriendlyErrorsPlugin from 'friendly-errors-webpack-plugin';
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@ import runWebpack from './runWebpack';
|
|||||||
async function main() {
|
async function main() {
|
||||||
const dir = process.cwd();
|
const dir = process.cwd();
|
||||||
process.chdir(root());
|
process.chdir(root());
|
||||||
await runGulp(argv);
|
await runGulp({});
|
||||||
await runWebpack(argv);
|
await runWebpack(argv);
|
||||||
process.chdir(dir);
|
process.chdir(dir);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-7
@@ -4,12 +4,12 @@ import log from 'fancy-log';
|
|||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import gulpConfig from './config/gulp';
|
import gulpConfig from './config/gulp';
|
||||||
|
|
||||||
export default async function ({ watch, production }) {
|
export default async function () {
|
||||||
function handleError(err) {
|
function handleError(err) {
|
||||||
log(chalk.red('Error: %s'), chalk.reset(err.toString()));
|
log(chalk.red('Error: %s'), chalk.reset(err.toString() + err.stack));
|
||||||
if (err && !watch) { process.exit(1); }
|
if (err) process.exit(1);
|
||||||
}
|
}
|
||||||
const gulpTasks = gulpConfig({ watch, production, errorHandler: handleError });
|
const gulpTasks = gulpConfig({ production: true, errorHandler: handleError });
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const taskList = {};
|
const taskList = {};
|
||||||
|
|
||||||
@@ -22,9 +22,6 @@ export default async function ({ watch, production }) {
|
|||||||
taskList[uid] = false;
|
taskList[uid] = false;
|
||||||
|
|
||||||
if (Object.values(taskList).filter((b) => b).length === 0) {
|
if (Object.values(taskList).filter((b) => b).length === 0) {
|
||||||
if (watch) {
|
|
||||||
gulpTasks.watch();
|
|
||||||
}
|
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ function renderItem(domain) {
|
|||||||
return tpl`
|
return tpl`
|
||||||
<div class="media">
|
<div class="media">
|
||||||
<div class="media__left medium">
|
<div class="media__left medium">
|
||||||
<img class="small domain-profile-avatar" src="${domain.gravatar_url}" width="30" height="30">
|
<img class="small domain-profile-avatar" src="${domain.gravatar}" width="30" height="30">
|
||||||
</div>
|
</div>
|
||||||
<div class="media__body medium">
|
<div class="media__body medium">
|
||||||
<div class="domain-select__name">${domain.name}</div>
|
<div class="domain-select__name">${domain.name}</div>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ function renderItem(user) {
|
|||||||
return tpl`
|
return tpl`
|
||||||
<div class="media">
|
<div class="media">
|
||||||
<div class="media__left medium">
|
<div class="media__left medium">
|
||||||
<img class="small user-profile-avatar" src="${user.gravatar_url}" width="30" height="30">
|
<img class="small user-profile-avatar" src="${user.gravatar}" width="30" height="30">
|
||||||
</div>
|
</div>
|
||||||
<div class="media__body medium">
|
<div class="media__body medium">
|
||||||
<div class="user-select__uname">${user.uname}</div>
|
<div class="user-select__uname">${user.uname}</div>
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export default class Notification {
|
|||||||
.appendTo('body');
|
.appendTo('body');
|
||||||
this.$n.width(); // force reflow
|
this.$n.width(); // force reflow
|
||||||
this.$n.removeClass('hide');
|
this.$n.removeClass('hide');
|
||||||
this.autoHideTimer = setTimeout(this.hide.bind(this), duration);
|
if (duration) this.autoHideTimer = setTimeout(this.hide.bind(this), duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClick() {
|
handleClick() {
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ export default class ScratchpadContainer extends React.PureComponent {
|
|||||||
handleChangeSize(uiElement, size) {
|
handleChangeSize(uiElement, size) {
|
||||||
this.props.changeUiSize(uiElement, size);
|
this.props.changeUiSize(uiElement, size);
|
||||||
$('#scratchpad').trigger('vjScratchpadRelayout');
|
$('#scratchpad').trigger('vjScratchpadRelayout');
|
||||||
|
this.props.ui.pretest.visible = !!this.props.ui.pretest.visible;
|
||||||
this.forceUpdate();
|
this.forceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
import SockJS from 'sockjs-client';
|
import SockJS from 'sockjs-client';
|
||||||
import Notification from 'vj/components/notification';
|
import Notification from 'vj/components/notification/index';
|
||||||
import i18n from 'vj/utils/i18n';
|
import i18n from 'vj/utils/i18n';
|
||||||
|
|
||||||
export default class Sock {
|
export default class Sock {
|
||||||
constructor(url) {
|
constructor(url) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.reconnect = false;
|
this.isreconnect = false;
|
||||||
this.init();
|
this.init();
|
||||||
|
this.notification = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this.sock = new SockJS(this.url);
|
this.sock = new SockJS(this.url);
|
||||||
this.sock.onopen = () => {
|
this.sock.onopen = () => {
|
||||||
if (this.reconnect) Notification.info(i18n('Reconnected to the server.'));
|
if (this.isreconnect) {
|
||||||
if (this.onopen) this.onopen(this.reconnect);
|
this.notification.hide();
|
||||||
|
Notification.info(i18n('Reconnected to the server.'));
|
||||||
|
}
|
||||||
|
if (this.onopen) this.onopen(this.isreconnect);
|
||||||
};
|
};
|
||||||
this.sock.onclose = (code, reason) => {
|
this.sock.onclose = (code, reason) => {
|
||||||
console.warn('Connection closed, ', code, reason);
|
console.warn('Connection closed, ', code, reason);
|
||||||
@@ -21,12 +25,29 @@ export default class Sock {
|
|||||||
if (this.onclose) this.onclose(code, reason);
|
if (this.onclose) this.onclose(code, reason);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Notification.warn(i18n('Disconnected from the server. Reconnecting...'));
|
if (!this.closed) {
|
||||||
this.reconnect = setTimeout(() => { this.init(); }, 3000);
|
if (!this.notification) {
|
||||||
|
this.notification = new Notification({
|
||||||
|
message: i18n('Disconnected from the server. Reconnecting...'),
|
||||||
|
type: 'warn',
|
||||||
|
duration: 0,
|
||||||
|
action: this.init.bind(this),
|
||||||
|
});
|
||||||
|
console.log(this.notification);
|
||||||
|
}
|
||||||
|
this.isreconnect = setTimeout(() => { this.init(); }, 3000);
|
||||||
|
} else {
|
||||||
|
if (this.notification) this.notification.hide();
|
||||||
|
Notification.warn(i18n('Disconnected from the server.'));
|
||||||
|
}
|
||||||
if (this.onclose) this.onclose(code, reason);
|
if (this.onclose) this.onclose(code, reason);
|
||||||
};
|
};
|
||||||
this.sock.onmessage = (message) => {
|
this.sock.onmessage = (message) => {
|
||||||
if (process.env.NODE_ENV !== 'production') console.log('Sock.onmessage: ', message);
|
if (process.env.NODE_ENV !== 'production') console.log('Sock.onmessage: ', message);
|
||||||
|
const msg = JSON.parse(message);
|
||||||
|
if (msg.error === 'PermissionError' || msg.error === 'PrivilegeError') {
|
||||||
|
this.closed = true;
|
||||||
|
}
|
||||||
if (this.onmessage) this.onmessage(message);
|
if (this.onmessage) this.onmessage(message);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user