import without pid check, fix bulk, upgrade dep

This commit is contained in:
undefined committed 2020-08-13 12:34:43 +08:00
1 parent ac9dc00c6a
commit 76f105c4c8
14 files changed
+117 -193

No files matched your search

+4 -4
View File
@@ -19,19 +19,19 @@
"@types/cross-spawn": "^6.0.2",
"@types/jest": "^26.0.9",
"@types/node": "^14.0.27",
"@typescript-eslint/eslint-plugin": "^3.8.0",
"@typescript-eslint/parser": "^3.8.0",
"@typescript-eslint/eslint-plugin": "^3.9.0",
"@typescript-eslint/parser": "^3.9.0",
"cross-spawn": "^7.0.3",
"eslint": "^7.6.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-import-resolver-typescript": "^2.2.0",
"eslint-plugin-import": "^2.22.0",
"globby": "^11.0.1",
"jest": "^26.2.2",
"jest": "^26.4.0",
"latest-version": "^5.1.0",
"ora": "^5.0.0",
"semver": "^7.3.2",
"ts-jest": "^26.1.4",
"ts-jest": "^26.2.0",
"typescript": "^3.9.7"
},
"dependencies": {
+2 -2
View File
@@ -8,7 +8,7 @@
],
"dependencies": {
"axios": "^0.19.0",
"bson": "^4.0.4",
"bson": "^4.1.0",
"fs-extra": "^9.0.1",
"hydrooj": "^2.12.0",
"js-yaml": "^3.14.0",
@@ -28,4 +28,4 @@
"build": "tsc",
"lint": "eslint . --ext ts --fix"
}
}
}
+3 -17
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.12.14",
"version": "2.12.15",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",
@@ -16,7 +16,6 @@
"cookies": "^0.8.0",
"detect-browser": "^5.1.1",
"fs-extra": "^9.0.1",
"html-to-text": "^5.1.1",
"js-yaml": "^3.13.1",
"koa": "^2.13.0",
"koa-body": "^4.2.0",
@@ -25,29 +24,19 @@
"koa-static-cache": "^5.1.3",
"lodash": "^4.17.19",
"lru-cache": "^6.0.0",
"markdown-it": "^11.0.0",
"markdown-it-anchor": "^5.3.0",
"markdown-it-footnote": "^3.0.2",
"markdown-it-imsize": "^2.0.1",
"markdown-it-mark": "^3.0.0",
"markdown-it-table-of-contents": "^0.4.4",
"moment-timezone": "^0.5.31",
"mongodb": "^3.5.9",
"nodemailer": "^6.4.10",
"nunjucks": "^3.2.2",
"prismjs": "^1.21.0",
"proxy-agent": "^3.1.1",
"ps-list": "^7.2.0",
"serialize-javascript": "^4.0.0",
"sockjs": "^0.3.20",
"superagent": "^5.3.1",
"superagent": "^6.0.0",
"systeminformation": "^4.26.10",
"yargs": "^15.4.1"
},
"devDependencies": {
"@types/adm-zip": "^0.4.33",
"@types/fs-extra": "^9.0.1",
"@types/html-to-text": "^5.1.1",
"@types/js-yaml": "^3.12.5",
"@types/katex": "^0.11.0",
"@types/koa": "^2.11.3",
@@ -56,11 +45,8 @@
"@types/koa-static-cache": "^5.1.0",
"@types/lodash": "^4.14.158",
"@types/lru-cache": "^5.1.0",
"@types/markdown-it": "^10.0.1",
"@types/mongodb": "^3.5.25",
"@types/nodemailer": "^6.4.0",
"@types/nunjucks": "^3.1.3",
"@types/prismjs": "^1.16.1",
"@types/serialize-javascript": "^4.0.0",
"@types/sockjs": "^0.3.32",
"@types/superagent": "^4.1.8",
@@ -70,4 +56,4 @@
"build": "tsc",
"build:watch": "tsc --watch"
}
}
}
+61 -87
View File
@@ -5,99 +5,73 @@ import fs from 'fs-extra';
import Koa, { Context } from 'koa';
import Body from 'koa-body';
import cache from 'koa-static-cache';
import nunjucks from 'nunjucks';
import mongodb from 'mongodb';
import { argv } from 'yargs';
const listenPort = argv.port || 8888;
class Loader {
getSource(name: string) { // eslint-disable-line class-methods-use-this
return {
src: `
<!DOCTYPE html>
<html data-page="setup" data-layout="immersive" class="layout--immersive page--setup nojs">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="chrome=1"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<meta name="msapplication-TileColor" content="#579e9a">
<meta name="theme-color" content="#56758f">
<link rel="stylesheet" media="all" href="/vj4.css">
<title>{{ _('Setup') }}</title>
</head>
<body>
<div class="slideout-panel" id="panel">
<div class="main">
<div class="row"><div class="columns">
<div class="immersive--content immersive--center">
<h1>{{ _('Setup') }}</h1>
<form method="POST">
<div class="row"><div class="columns">
<label class="inverse material textbox">
{{ _('Database Host') }}
<input name="host" type="text" value="127.0.0.1" autofocus>
</label>
</div></div>
<div class="row"><div class="columns">
<label class="inverse material textbox">
{{ _('Database Port') }}
<input name="port" type="number" value="27017">
</label>
</div></div>
<div class="row"><div class="columns">
<label class="inverse material textbox">
{{ _('Database Name') }}
<input name="name" type="text" value="hydro">
</label>
</div></div>
<div class="row"><div class="columns">
<label class="inverse material textbox">
{{ _('Database Username') }}
<input name="username" type="text" placeholder="{{ _('Leave blank if none') }}">
</label>
</div></div>
<div class="row"><div class="columns">
<label class="inverse material textbox">
{{ _('Database Password') }}
<input name="password" type="password" placeholder="{{ _('Leave blank if none') }}">
</label>
</div></div>
<div class="row"><div class="columns">
<div class="text-center">
<input type="submit" value="{{ _('Confirm') }}" class="inverse expanded rounded primary button">
</div>
</div></div>
</form>
</div>
</div></div>
</div>
</div>
</body>
</html>
`,
path: name,
noCache: false,
};
}
}
const env = new nunjucks.Environment(new Loader(), { autoescape: true, trimBlocks: true });
function render(name: string) {
return new Promise((resolve, reject) => {
env.render(name, {
_: (str: string) => str,
}, (err, res) => {
if (err) reject(err);
else resolve(res);
});
});
}
async function get(ctx: Context) {
ctx.body = await render('setup.html');
ctx.body = `<!DOCTYPE html>
<html data-page="setup" data-layout="immersive" class="layout--immersive page--setup nojs">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="chrome=1"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<meta name="msapplication-TileColor" content="#579e9a">
<meta name="theme-color" content="#56758f">
<link rel="stylesheet" media="all" href="/vj4.css">
<title>Setup</title>
</head>
<body>
<div class="slideout-panel" id="panel">
<div class="main">
<div class="row"><div class="columns">
<div class="immersive--content immersive--center">
<h1>Setup</h1>
<form method="POST">
<div class="row"><div class="columns">
<label class="inverse material textbox">
Database Host
<input name="host" type="text" value="127.0.0.1" autofocus>
</label>
</div></div>
<div class="row"><div class="columns">
<label class="inverse material textbox">
Database Port
<input name="port" type="number" value="27017">
</label>
</div></div>
<div class="row"><div class="columns">
<label class="inverse material textbox">
Database Name
<input name="name" type="text" value="hydro">
</label>
</div></div>
<div class="row"><div class="columns">
<label class="inverse material textbox">
Database Username
<input name="username" type="text" placeholder="Leave blank if none">
</label>
</div></div>
<div class="row"><div class="columns">
<label class="inverse material textbox">
Database Password
<input name="password" type="password" placeholder="Leave blank if none">
</label>
</div></div>
<div class="row"><div class="columns">
<div class="text-center">
<input type="submit" value="Confirm" class="inverse expanded rounded primary button">
</div>
</div></div>
</form>
</div>
</div></div>
</div>
</div>
</body>
</html>`;
ctx.response.type = 'text/html';
}
+2 -6
View File
@@ -10,10 +10,6 @@ import {
import { isPid } from '../lib/validator';
class ProblemImportHandler extends Handler {
async prepare() {
this.checkPerm(PERM.PERM_CREATE_PROBLEM);
}
async get() {
this.response.template = 'problem_import.html';
this.response.body = {
@@ -26,7 +22,7 @@ class ProblemImportHandler extends Handler {
}
@param('url', Types.String)
@param('pid', Types.String, isPid)
@param('pid', Types.String, true, isPid)
@param('hidden', Types.Boolean)
@param('remoteType', Types.String)
async post(domainId: string, url: string, pid: string, hidden = false, remoteType: string) {
@@ -55,7 +51,7 @@ class ProblemImportHandler extends Handler {
}
export async function apply() {
Route('problem_import', '/problem/import', ProblemImportHandler);
Route('problem_import', '/problem/import', ProblemImportHandler, PERM.PERM_CREATE_PROBLEM);
}
global.Hydro.handler.import = apply;
-52
View File
@@ -1,52 +0,0 @@
import superagent from 'superagent';
import proxyAgent from 'proxy-agent';
namespace Proxy {
function getUrl() {
return this._url;
}
function setUrl(v: string) {
this._url = v;
// eslint-disable-next-line no-use-before-define
proxy.call(this, this._proxyUri);
}
function setupUrl(req: superagent.Request) {
const desc = Object.getOwnPropertyDescriptor(req, 'url');
if (desc.get === getUrl && desc.set === setUrl) return;
// @ts-ignore
req._url = req.url;
desc.get = getUrl;
desc.set = setUrl;
delete desc.value;
delete desc.writable;
Object.defineProperty(req, 'url', desc);
}
function proxy(uri: string) {
if (!uri) return this;
setupUrl(this);
const agent = proxyAgent(uri);
if (agent) this.agent(agent);
this._proxyUri = uri;
return this;
}
export function setup(agent, uri = '') {
const Request = agent.Request;
if (Request) {
Request.prototype.proxy = proxy;
return agent;
}
return proxy.call(agent, uri);
}
}
declare module 'superagent' {
namespace request {
interface Request {
proxy(url: string): this;
}
}
}
Proxy.setup(superagent);
export = superagent;
+2 -1
View File
@@ -184,7 +184,7 @@ export async function create(
mailLower: mail.trim().toLowerCase(),
uname,
unameLower: uname.trim().toLowerCase(),
hash: pwhash(password, salt),
hash: pwhash(password.toString(), salt),
salt,
hashType: 'hydro',
regat: new Date(),
@@ -195,6 +195,7 @@ export async function create(
gravatar: mail,
});
} catch (e) {
console.log(e);
throw new UserAlreadyExistError([uid, uname, mail]);
}
return uid;
+33
View File
@@ -0,0 +1,33 @@
import 'hydrooj';
import md5 from 'hydrooj/src/lib/md5';
import sha1 from 'hydrooj/src/lib/sha1';
import pwhash from 'hydrooj/src/lib/hash.hydro';
import 'hydrooj/src/utils';
describe('crypto', () => {
const content1 = 'twd2akioi';
const content2 = '陈志鹏爱吃玻璃。';
test('MD5', () => {
const result1 = '57b6a9bd92c0502714ecedc4a5ebf24c';
const result2 = 'f598cb0738e7cd9efbbdf0ad7b6b42a7';
expect(md5(content1)).toStrictEqual(result1);
expect(md5(content2)).toStrictEqual(result2);
});
test('SHA1', () => {
const result1 = 'bade50df188c338fae183cf3bde34fafaf590bc5';
const result2 = '4d3fce39e3a163fe65263d8283ed3e98244fda42';
expect(sha1(content1)).toStrictEqual(result1);
expect(sha1(content2)).toStrictEqual(result2);
});
test('PWHASH', () => {
const password1 = 'password1';
const salt1 = '0326Bc23E6fac733K01g29fBBUSAj7O4';
const salt2 = String.random(32);
const hash1 = '70a2db6a53ecd75d8d4b19d8647a416b4e812c1a6635c4a1f5069a00382fdcb6';
expect(pwhash(password1, salt1)).toStrictEqual(hash1);
expect(pwhash(password1, salt2)).not.toEqual(hash1);
});
});
-14
View File
@@ -1,14 +0,0 @@
import 'hydrooj';
import pwhash from 'hydrooj/src/lib/hash.hydro';
import 'hydrooj/src/utils';
describe('Hash', () => {
test('server', () => {
const password1 = 'password1';
const salt1 = '0326Bc23E6fac733K01g29fBBUSAj7O4';
const salt2 = String.random(32);
const hash1 = '70a2db6a53ecd75d8d4b19d8647a416b4e812c1a6635c4a1f5069a00382fdcb6';
expect(pwhash(password1, salt1)).toStrictEqual(hash1);
expect(pwhash(password1, salt2)).not.toEqual(hash1);
});
});
+1 -1
View File
@@ -15,7 +15,7 @@
},
"dependencies": {
"hydrooj": "^2.12.1",
"superagent": "^5.3.1",
"superagent": "^6.0.0",
"superagent-proxy": "^2.0.0"
}
}
+2 -2
View File
@@ -15,7 +15,7 @@
},
"dependencies": {
"hydrooj": "^2.12.1",
"superagent": "^5.3.1",
"superagent": "^6.0.0",
"superagent-proxy": "^2.0.0"
}
}
}
+2 -2
View File
@@ -15,7 +15,7 @@
},
"dependencies": {
"hydrooj": "^2.12.1",
"superagent": "^5.3.1",
"superagent": "^6.0.0",
"superagent-proxy": "^2.0.0"
}
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/migrate-vijos",
"version": "1.3.5",
"version": "1.3.6",
"main": "package.json",
"repository": "git@github.com:hydro-dev/Hydro.git",
"author": "undefined <masnn0@outlook.com>",
+4 -4
View File
@@ -420,19 +420,19 @@ async function removeInvalidPid(src: Db, report: Function) {
async function userfileUsage(src: Db, report: Function) {
const count = await src.collection('domain.user').find().count();
const bulk = dst.collection('user').initializeUnorderedBulkOp();
await report({ progress: 1, message: `userfileUsage: ${count}` });
const total = Math.floor(count / 50);
for (let i = 0; i <= total; i++) {
const docs = await src.collection('userfileUsage')
const docs = await src.collection('domain.user')
.find().skip(i * 50).limit(50)
.toArray();
const t = [];
for (const doc of docs) {
if (doc.userfile_usage) {
bulk.find({ _id: doc.uid }).updateOne({ $set: { usage: doc.userfile_usage } });
t.push(dst.collection('user').updateOne({ _id: doc.uid }, { $set: { usage: doc.userfile_usage } }));
}
}
await bulk.execute();
await Promise.all(t);
}
}