mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
优化丑陋的代码
This commit is contained in:
1 parent
62ac2f52c9
commit
dd1b7c363a
19 files changed
+97
-502
No files matched your search
@@ -23,7 +23,7 @@ class RecordListHandler extends RecordHandler {
|
||||
if (uidOrName) {
|
||||
q.$or = [
|
||||
{ unameLower: uidOrName.toLowerCase() },
|
||||
{ _id: parseInt(uidOrName) },
|
||||
{ _id: parseInt(uidOrName, 10) },
|
||||
];
|
||||
}
|
||||
if (pid) q.pid = pid;
|
||||
|
||||
@@ -54,6 +54,7 @@ class SystemSettingHandler extends SystemHandler {
|
||||
const current = {};
|
||||
const settings = setting.SYSTEM_SETTINGS;
|
||||
for (const s of settings) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
current[s.key] = await system.get(s.key);
|
||||
}
|
||||
this.response.body = {
|
||||
|
||||
@@ -39,7 +39,7 @@ async function _parseDagJson(domainId, dag) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await Promise.all(tasks);
|
||||
const newNode = {
|
||||
_id: parseInt(node._id),
|
||||
_id: parseInt(node._id, 10),
|
||||
title: node.title,
|
||||
requireNids: Array.from(new Set(node.requireNids)),
|
||||
pids: Array.from(new Set(node.pids)),
|
||||
@@ -112,8 +112,9 @@ class TrainingDetailHandler extends TrainingHandler {
|
||||
for (const pid in psdict) {
|
||||
const psdoc = psdict[pid];
|
||||
if (psdoc.status) {
|
||||
if (psdoc.status === builtin.STATUS.STATUS_ACCEPTED) donePids.add(parseInt(pid));
|
||||
else progPids.add(parseInt(pid));
|
||||
if (psdoc.status === builtin.STATUS.STATUS_ACCEPTED) {
|
||||
donePids.add(parseInt(pid, 10));
|
||||
} else progPids.add(parseInt(pid, 10));
|
||||
}
|
||||
}
|
||||
const nsdict = {};
|
||||
@@ -124,7 +125,7 @@ class TrainingDetailHandler extends TrainingHandler {
|
||||
const totalCount = node.pids.length;
|
||||
const doneCount = Set.union(new Set(node.pids), donePids).size;
|
||||
const nsdoc = {
|
||||
progress: totalCount ? parseInt(100 * (doneCount / totalCount)) : 100,
|
||||
progress: totalCount ? parseInt(100 * (doneCount / totalCount), 10) : 100,
|
||||
isDone: training.isDone(node, doneNids, donePids),
|
||||
isProgress: training.isProgress(node, doneNids, donePids, progPids),
|
||||
isOpen: training.isOpen(node, doneNids, donePids, progPids),
|
||||
|
||||
@@ -156,7 +156,7 @@ class UserSearchHandler extends Handler {
|
||||
let udocs;
|
||||
if (exactMatch) udocs = [];
|
||||
else udocs = await user.getPrefixList(q, 20);
|
||||
const udoc = await user.getById(domainId, parseInt(q));
|
||||
const udoc = await user.getById(domainId, parseInt(q, 10));
|
||||
if (udoc) udocs.push(udoc);
|
||||
for (const i in udocs) {
|
||||
if (udocs[i].gravatar) {
|
||||
|
||||
+2
-2
@@ -3,8 +3,8 @@ function decodeBase64WithUriEncoding(encodedText) {
|
||||
}
|
||||
|
||||
function unescapedString(escapedString) {
|
||||
escapedString += new Array(5 - escapedString.length % 4).join('=');
|
||||
return escapedString.replace(/\-/g, '+').replace(/_/g, '/');
|
||||
escapedString += new Array(5 - (escapedString.length % 4)).join('=');
|
||||
return escapedString.replace(/-/g, '+').replace(/_/g, '/');
|
||||
}
|
||||
|
||||
function decodeJWT(idToken) {
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ function _digit2(number) {
|
||||
}
|
||||
|
||||
function formatSeconds(seconds = 0) {
|
||||
seconds = parseInt(seconds);
|
||||
seconds = parseInt(seconds, 10);
|
||||
return '{0}:{1}:{2}'.format(
|
||||
_digit2(Math.floor(seconds / 3600)),
|
||||
_digit2(Math.floor((seconds % 3600) / 60)),
|
||||
|
||||
@@ -6,9 +6,9 @@ function convert(ini) {
|
||||
const res = { cases: [] };
|
||||
for (let i = 1; i <= count; i++) {
|
||||
const [input, output, time, score, memory] = f[i].split('|');
|
||||
const cur = { input, output, score: parseInt(score) };
|
||||
const cur = { input, output, score: parseInt(score, 10) };
|
||||
cur.time = `${time}s`;
|
||||
if (!Number.isNaN(parseInt(memory))) cur.memory = `${Math.floor(parseInt(memory) / 1024)}m`;
|
||||
if (!Number.isNaN(parseInt(memory, 10))) cur.memory = `${Math.floor(parseInt(memory, 10) / 1024)}m`;
|
||||
else cur.memory = '128m';
|
||||
res.cases.push(cur);
|
||||
}
|
||||
|
||||
@@ -83,8 +83,8 @@ global.Hydro.model.training = module.exports = {
|
||||
if (!tdoc) throw new TrainingNotFoundError(tid);
|
||||
for (const i in tdoc.dag) {
|
||||
for (const j in tdoc.dag[i].pids) {
|
||||
if (Number.isSafeInteger(parseInt(tdoc.dag[i].pids[j]))) {
|
||||
tdoc.dag[i].pids[j] = parseInt(tdoc.dag[i].pids[j]);
|
||||
if (Number.isSafeInteger(parseInt(tdoc.dag[i].pids[j], 10))) {
|
||||
tdoc.dag[i].pids[j] = parseInt(tdoc.dag[i].pids[j], 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ async function run({ domainId, isSub = false }, report) {
|
||||
memory_kb: 0,
|
||||
score: 0,
|
||||
},
|
||||
progress: Math.floor(((parseInt(i) + 1) / domains.length) * 100),
|
||||
progress: Math.floor(((parseInt(i, 10) + 1) / domains.length) * 100),
|
||||
});
|
||||
}
|
||||
return true;
|
||||
@@ -44,7 +44,7 @@ async function run({ domainId, isSub = false }, report) {
|
||||
udict[udoc.uid] = udoc.new;
|
||||
}
|
||||
if (!isSub) {
|
||||
await report({ progress: Math.floor(((parseInt(i) + 1) / contests.length) * 100) });
|
||||
await report({ progress: Math.floor(((parseInt(i, 10) + 1) / contests.length) * 100) });
|
||||
}
|
||||
await report({
|
||||
case: {
|
||||
@@ -58,7 +58,7 @@ async function run({ domainId, isSub = false }, report) {
|
||||
}
|
||||
const tasks = [];
|
||||
for (const uid in udict) {
|
||||
tasks.push(user.setInDomain(domainId, parseInt(uid), { rating: udict[uid] }));
|
||||
tasks.push(user.setInDomain(domainId, parseInt(uid, 10), { rating: udict[uid] }));
|
||||
}
|
||||
await Promise.all(tasks);
|
||||
return true;
|
||||
|
||||
@@ -5,7 +5,7 @@ async function run({
|
||||
uname, password, mail, uid,
|
||||
}) {
|
||||
if (!uid) uid = await system.inc('user');
|
||||
else uid = parseInt(uid);
|
||||
else uid = parseInt(uid, 10);
|
||||
if (Number.isNaN(uid)) throw new Error('uid');
|
||||
await user.create({
|
||||
uid, uname, password, mail, regip: '127.0.0.1',
|
||||
|
||||
@@ -3,7 +3,7 @@ const user = require('../model/user');
|
||||
async function run({
|
||||
uid,
|
||||
}) {
|
||||
uid = parseInt(uid);
|
||||
uid = parseInt(uid, 10);
|
||||
if (Number.isNaN(uid)) throw new Error('uid');
|
||||
await user.setSuperAdmin(uid);
|
||||
return uid;
|
||||
|
||||
@@ -63,15 +63,15 @@ const validate = {
|
||||
tag: _splitAndTrim,
|
||||
beginAtDate: _date,
|
||||
beginAtTime: _time,
|
||||
pid: (pid) => (Number.isSafeInteger(parseInt(pid)) ? parseInt(pid) : pid),
|
||||
pid: (pid) => (Number.isSafeInteger(parseInt(pid, 10)) ? parseInt(pid, 10) : pid),
|
||||
content: validator.checkContent,
|
||||
title: validator.checkTitle,
|
||||
uid: (uid) => parseInt(validator.checkUid(uid)),
|
||||
uid: (uid) => parseInt(validator.checkUid(uid), 10),
|
||||
password: validator.checkPassword,
|
||||
mail: validator.checkEmail,
|
||||
uname: validator.checkUname,
|
||||
page: (page) => {
|
||||
if (Number.isSafeInteger(parseInt(page))) page = parseInt(page);
|
||||
if (Number.isSafeInteger(parseInt(page, 10))) page = parseInt(page, 10);
|
||||
if (page <= 0) throw new ValidationError('page');
|
||||
return page;
|
||||
},
|
||||
@@ -83,7 +83,7 @@ const validate = {
|
||||
pids: (pids) => {
|
||||
const res = pids.split(',').map((i) => i.trim());
|
||||
for (const i in res) {
|
||||
if (Number.isSafeInteger(parseInt(res[i]))) res[i] = parseInt(res[i]);
|
||||
if (Number.isSafeInteger(parseInt(res[i], 10))) res[i] = parseInt(res[i], 10);
|
||||
}
|
||||
return res;
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user