diff --git a/package.json b/package.json
index 2e6d9d509..942c8c91b 100644
--- a/package.json
+++ b/package.json
@@ -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": {
diff --git a/packages/hydrojudge/package.json b/packages/hydrojudge/package.json
index c8bfc8e60..e86633f24 100644
--- a/packages/hydrojudge/package.json
+++ b/packages/hydrojudge/package.json
@@ -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"
}
-}
\ No newline at end of file
+}
diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json
index 9da680eb8..6b722ddd8 100644
--- a/packages/hydrooj/package.json
+++ b/packages/hydrooj/package.json
@@ -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"
}
-}
\ No newline at end of file
+}
diff --git a/packages/hydrooj/src/entry/setup.ts b/packages/hydrooj/src/entry/setup.ts
index 1835f3070..70dbc40c2 100644
--- a/packages/hydrooj/src/entry/setup.ts
+++ b/packages/hydrooj/src/entry/setup.ts
@@ -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: `
-
-
-
-
-
-
-
-
-
-
- {{ _('Setup') }}
-
-
-
-
-
- `,
- 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 = `
+
+
+
+
+
+
+
+
+
+ Setup
+
+
+
+
+ `;
ctx.response.type = 'text/html';
}
diff --git a/packages/hydrooj/src/handler/import.ts b/packages/hydrooj/src/handler/import.ts
index 0d73a45b5..e00db4e09 100644
--- a/packages/hydrooj/src/handler/import.ts
+++ b/packages/hydrooj/src/handler/import.ts
@@ -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;
diff --git a/packages/hydrooj/src/lib/superagent.ts b/packages/hydrooj/src/lib/superagent.ts
deleted file mode 100644
index 5c49e5383..000000000
--- a/packages/hydrooj/src/lib/superagent.ts
+++ /dev/null
@@ -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;
diff --git a/packages/hydrooj/src/model/user.ts b/packages/hydrooj/src/model/user.ts
index 32a15ccea..c029dc263 100644
--- a/packages/hydrooj/src/model/user.ts
+++ b/packages/hydrooj/src/model/user.ts
@@ -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;
diff --git a/packages/hydrooj/test/lib.crypto.spec.ts b/packages/hydrooj/test/lib.crypto.spec.ts
new file mode 100644
index 000000000..526ad49e3
--- /dev/null
+++ b/packages/hydrooj/test/lib.crypto.spec.ts
@@ -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);
+ });
+});
diff --git a/packages/hydrooj/test/lib.pwhash.spec.ts b/packages/hydrooj/test/lib.pwhash.spec.ts
deleted file mode 100644
index 94b817cb1..000000000
--- a/packages/hydrooj/test/lib.pwhash.spec.ts
+++ /dev/null
@@ -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);
- });
-});
diff --git a/packages/login-with-github/package.json b/packages/login-with-github/package.json
index 534e2c1e7..494341e8e 100644
--- a/packages/login-with-github/package.json
+++ b/packages/login-with-github/package.json
@@ -15,7 +15,7 @@
},
"dependencies": {
"hydrooj": "^2.12.1",
- "superagent": "^5.3.1",
+ "superagent": "^6.0.0",
"superagent-proxy": "^2.0.0"
}
}
\ No newline at end of file
diff --git a/packages/login-with-google/package.json b/packages/login-with-google/package.json
index 058cf300f..770ae98f8 100644
--- a/packages/login-with-google/package.json
+++ b/packages/login-with-google/package.json
@@ -15,7 +15,7 @@
},
"dependencies": {
"hydrooj": "^2.12.1",
- "superagent": "^5.3.1",
+ "superagent": "^6.0.0",
"superagent-proxy": "^2.0.0"
}
-}
\ No newline at end of file
+}
diff --git a/packages/login-with-osu/package.json b/packages/login-with-osu/package.json
index cfa556d8c..5b97de83a 100644
--- a/packages/login-with-osu/package.json
+++ b/packages/login-with-osu/package.json
@@ -15,7 +15,7 @@
},
"dependencies": {
"hydrooj": "^2.12.1",
- "superagent": "^5.3.1",
+ "superagent": "^6.0.0",
"superagent-proxy": "^2.0.0"
}
-}
\ No newline at end of file
+}
diff --git a/packages/migrate-vijos/package.json b/packages/migrate-vijos/package.json
index f5da499c4..a50419837 100644
--- a/packages/migrate-vijos/package.json
+++ b/packages/migrate-vijos/package.json
@@ -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 ",
diff --git a/packages/migrate-vijos/script.ts b/packages/migrate-vijos/script.ts
index da66c9c57..55f770501 100644
--- a/packages/migrate-vijos/script.ts
+++ b/packages/migrate-vijos/script.ts
@@ -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);
}
}