mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
修复在线IDE
This commit is contained in:
1 parent
b1153b641a
commit
61cba6f180
12 files changed
+94
-76
No files matched your search
@@ -92,10 +92,11 @@ class JudgeHandler extends Handler {
|
||||
async get({ check = false }) {
|
||||
this.response.body = {};
|
||||
if (check) return;
|
||||
const rid = await queue.get('judge', false);
|
||||
if (rid) {
|
||||
const rdoc = await record.get(rid);
|
||||
const pdoc = await problem.getById(rdoc.pid);
|
||||
const tasks = [];
|
||||
let rid = await queue.get('judge', false);
|
||||
while (rid) {
|
||||
const rdoc = await record.get(rid); // eslint-disable-line no-await-in-loop
|
||||
const pdoc = await problem.getById(rdoc.pid); // eslint-disable-line no-await-in-loop
|
||||
const task = {
|
||||
event: 'judge',
|
||||
rid,
|
||||
@@ -105,7 +106,8 @@ class JudgeHandler extends Handler {
|
||||
lang: rdoc.lang,
|
||||
code: rdoc.code,
|
||||
};
|
||||
this.response.body = { task };
|
||||
tasks.push(task);
|
||||
rid = await queue.get('judge', false); // eslint-disable-line no-await-in-loop
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,8 +32,7 @@ class UserLoginHandler extends Handler {
|
||||
}
|
||||
}
|
||||
class UserLogoutHandler extends Handler {
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
async prepare() {
|
||||
this.checkPerm(PERM_LOGGEDIN);
|
||||
}
|
||||
|
||||
@@ -47,8 +46,7 @@ class UserLogoutHandler extends Handler {
|
||||
}
|
||||
}
|
||||
class UserRegisterHandler extends Handler {
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
async prepare() {
|
||||
this.checkPerm(PERM_REGISTER_USER);
|
||||
}
|
||||
|
||||
@@ -76,8 +74,7 @@ class UserRegisterHandler extends Handler {
|
||||
}
|
||||
}
|
||||
class UserRegisterWithCodeHandler extends Handler {
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
async prepare() {
|
||||
this.checkPerm(PERM_REGISTER_USER);
|
||||
}
|
||||
|
||||
@@ -153,11 +150,11 @@ class UserDetailHandler extends Handler {
|
||||
}
|
||||
|
||||
async get({ uid }) {
|
||||
const isSelfProfile = this.ctx.state.user._id === uid;
|
||||
const isSelfProfile = this.user._id === uid;
|
||||
const udoc = await user.getById(uid);
|
||||
if (!udoc) throw new UserNotFoundError(uid);
|
||||
const sdoc = await token.getMostRecentSessionByUid(uid);
|
||||
this.ctx.body = { isSelfProfile, udoc, sdoc };
|
||||
this.response.body = { isSelfProfile, udoc, sdoc };
|
||||
}
|
||||
}
|
||||
class UserSearchHandler extends Handler {
|
||||
@@ -176,7 +173,7 @@ class UserSearchHandler extends Handler {
|
||||
udocs[i].gravatar_url = misc.gravatar_url[udocs[i].gravatar];
|
||||
}
|
||||
}
|
||||
this.ctx.body = { udocs };
|
||||
this.response.body = { udocs };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ exports.gravatar_url = function gravatarUrl(email, size) {
|
||||
return `//gravatar.loli.net/avatar/${md5((email || '').toString().trim().toLowerCase())}?d=mm&s=${size}`;
|
||||
};
|
||||
exports.datetime_span = function datetimeSpan(dt, relative = true, format = '%Y-%m-%d %H:%M:%S') {
|
||||
if (!dt) return 'DATETIME_SPAN_ERROR';
|
||||
if (dt.generationTime) dt = new Date(dt.generationTime * 1000);
|
||||
else if (typeof dt === 'number' || typeof dt === 'string') dt = new Date(dt);
|
||||
return '<span class="time{0}" data-timestamp="{1}">{2}</span>'.format(
|
||||
|
||||
@@ -16,6 +16,7 @@ class Nunjucks extends nunjucks.Environment {
|
||||
this.addFilter('json', (self) => JSON.stringify(self), false);
|
||||
this.addFilter('assign', (self, data) => Object.assign(self, data));
|
||||
this.addFilter('markdown', (self) => markdown.render(self));
|
||||
this.addFilter('base64_encode', (s) => Buffer.from(s).toString('base64'));
|
||||
this.addFilter('gravatar_url', misc.gravatar_url);
|
||||
this.addFilter('format_size', misc.format_size);
|
||||
this.addGlobal('typeof', (o) => typeof o);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const db = require('../service/db.js');
|
||||
const { ValidationError } = require('../error');
|
||||
|
||||
const coll = db.collection('token');
|
||||
|
||||
@@ -33,8 +34,10 @@ module.exports = {
|
||||
* @param {number} tokenType type of the token.
|
||||
* @returns {object} The token document, or null.
|
||||
*/
|
||||
get(tokenId, tokenType) {
|
||||
return coll.findOne({ _id: tokenId, tokenType });
|
||||
async get(tokenId, tokenType) {
|
||||
const res = await coll.findOne({ _id: tokenId, tokenType });
|
||||
if (!res) throw new ValidationError('token');
|
||||
return res;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,9 +13,9 @@ function getMultiStatus(query) {
|
||||
return collStatus.find(query);
|
||||
}
|
||||
async function getListStatus(uid, tids) {
|
||||
const psdocs = await getMultiStatus({ uid, pid: { $in: Array.from(new Set(tids)) } }).toArray();
|
||||
const tsdocs = await getMultiStatus({ uid, tid: { $in: Array.from(new Set(tids)) } }).toArray();
|
||||
const r = {};
|
||||
for (const psdoc of psdocs) r[psdoc.pid] = psdoc;
|
||||
for (const tsdoc of tsdocs) r[tsdoc.pid] = tsdoc;
|
||||
return r;
|
||||
}
|
||||
async function enroll(tid, uid) {
|
||||
@@ -104,6 +104,12 @@ module.exports = {
|
||||
if (!tdoc) throw new TrainingNotFoundError(tid);
|
||||
return tdoc;
|
||||
},
|
||||
async getList(tids) {
|
||||
const tdocs = await this.getMulti({ _id: { $in: Array.from(new Set(tids)) } }).toArray();
|
||||
const r = {};
|
||||
for (const tdoc of tdocs) r[tdoc._id] = tdoc;
|
||||
return r;
|
||||
},
|
||||
getMulti: (query) => coll.find(query),
|
||||
getMultiStatus,
|
||||
getStatus,
|
||||
|
||||
Reference in new issue
Block a user