mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 09:38:19 +08:00
修复一些小错误
This commit is contained in:
1 parent
8cd84f29e8
commit
a596231a06
15 files changed
+125
-124
No files matched your search
@@ -73,8 +73,8 @@ class TrainingMainHandler extends TrainingHandler {
|
||||
$or: [{ _id: { $in: Array.from(tids) } }, { enroll: 1 }],
|
||||
}).toArray();
|
||||
for (const tsdoc of tsdocs) {
|
||||
tsdict[tsdoc._id] = tsdoc;
|
||||
enrolledTids.add(tsdoc._id);
|
||||
tsdict[tsdoc.tid] = tsdoc;
|
||||
enrolledTids.add(tsdoc.tid);
|
||||
}
|
||||
for (const tid of tids) enrolledTids.delete(tid);
|
||||
if (enrolledTids.size) tdict = await training.getList(Array.from(enrolledTids));
|
||||
@@ -117,7 +117,7 @@ class TrainingDetailHandler extends TrainingHandler {
|
||||
for (const node of tdoc.dag) {
|
||||
ndict[node._id] = node;
|
||||
const totalCount = node.pids.length;
|
||||
const doneCount = Set.union(new Set(node.pids), new Set(donePids));
|
||||
const doneCount = Set.union(new Set(node.pids), new Set(donePids)).size;
|
||||
const nsdoc = {
|
||||
progress: totalCount ? parseInt(100 * (doneCount / totalCount)) : 100,
|
||||
isDone: training.isDone(node, doneNids, donePids),
|
||||
@@ -172,8 +172,6 @@ class TrainingCreateHandler extends TrainingHandler {
|
||||
}) {
|
||||
dag = await _parseDagJson(dag);
|
||||
const pids = training.getPids({ dag });
|
||||
console.log(pids);
|
||||
console.log(pids.length, pids.size);
|
||||
assert(pids.length, new ValidationError('dag'));
|
||||
const pdocs = await problem.getMulti({
|
||||
$or: [{ _id: { $in: pids } }, { pid: { $in: pids } }],
|
||||
|
||||
@@ -37,7 +37,6 @@ async function setStatus(tid, uid, $set) {
|
||||
|
||||
module.exports = {
|
||||
getPids(tdoc) {
|
||||
console.log(tdoc.dag);
|
||||
const pids = new Set();
|
||||
for (const node of tdoc.dag) {
|
||||
for (const pid of node.pids) pids.add(pid);
|
||||
|
||||
+8
-23
@@ -303,19 +303,11 @@ class ConnectionHandler {
|
||||
* @param {import('sockjs').Connection} conn
|
||||
*/
|
||||
constructor(conn) {
|
||||
const that = this;
|
||||
this.conn = conn;
|
||||
this.request = {
|
||||
cookies: {
|
||||
get(name) {
|
||||
return that.request.cookies[name];
|
||||
},
|
||||
set() { },
|
||||
},
|
||||
params: {},
|
||||
headers: conn.headers,
|
||||
};
|
||||
this._handler = {};
|
||||
const p = (conn.url.split('?')[1] || '').split('&');
|
||||
for (const i in p) p[i] = p[i].split('=');
|
||||
for (const i in p) this.request.params[p[i][0]] = decodeURIComponent(p[i][1]);
|
||||
@@ -342,21 +334,14 @@ class ConnectionHandler {
|
||||
}
|
||||
|
||||
async ___prepare() {
|
||||
await new Promise((resolve, reject) => {
|
||||
this.conn.once('data', (msg) => {
|
||||
for (const i of msg.split(';')) {
|
||||
const [k, v] = i.trim().split('=');
|
||||
this.request.cookies[k] = v;
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
setTimeout(reject, 5000);
|
||||
});
|
||||
this._handler.sid = this.request.cookies.get('sid');
|
||||
this.session = this._handler.sid
|
||||
? await token.get(this._handler.sid, token.TYPE_SESSION)
|
||||
: { uid: 1 };
|
||||
if (!this.session) this.session = { uid: 1 };
|
||||
try {
|
||||
this.session = {
|
||||
uid: await token.get(this.request.params.token, token.TYPE_CSRF_TOKEN),
|
||||
};
|
||||
await token.delete(this.request.params.token, token.TYPE_CSRF_TOKEN);
|
||||
} catch (e) {
|
||||
this.session = { uid: 1 };
|
||||
}
|
||||
const bdoc = await blacklist.get(this.request.ip);
|
||||
if (bdoc) throw new BlacklistedError(this.request.ip);
|
||||
this.user = await user.getById(this.session.uid);
|
||||
|
||||
Reference in new issue
Block a user