core, ui, judge: rewrite http & ws layer (#352)

This commit is contained in:
undefined authored and GitHub committed 2022-05-03 20:22:12 +08:00
1 parent 3d2384f31a
commit 5af082eac8
37 files changed
+868 -889

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@hydrooj/hydrojudge",
"bin": "bin/hydrojudge.js",
"version": "2.17.4",
"version": "2.18.0",
"main": "package.json",
"author": "undefined <i@undefined.moe>",
"repository": "https://github.com/hydro-dev/Hydro.git",
+9 -9
View File
@@ -278,16 +278,16 @@ export default class Hydro {
async consume(queue: Queue<any>) {
log.info('正在连接 %sjudge/conn', this.config.server_url);
const res = await this.axios.get('judge/conn/info');
this.ws = new WebSocket(`${this.config.server_url.replace(/^http/i, 'ws')}judge/conn/websocket?t=${res.data.entropy}`);
this.ws.on('open', () => {
this.ws.send(this.config.cookie);
global.onDestroy.push(() => this.ws.close());
const content = this.config.minPriority !== undefined
? `{"key":"prio","prio":${this.config.minPriority}}`
: '{"key":"ping"}';
setInterval(() => this.ws.send(content), 30000);
this.ws = new WebSocket(`${this.config.server_url.replace(/^http/i, 'ws')}judge/conn`, {
headers: {
Cookie: `sid=${this.config.cookie}`,
},
});
global.onDestroy.push(() => this.ws.close());
const content = this.config.minPriority !== undefined
? `{"key":"prio","prio":${this.config.minPriority}}`
: '{"key":"ping"}';
setInterval(() => this.ws?.send?.(content), 30000);
this.ws.on('message', (data) => {
const request = JSON.parse(data.toString());
if (request.language) this.language = request.language;