center: support node18 crypto

pull/464/head
undefined 2 years ago
parent e32f285876
commit 067eb2c348

@ -1,15 +1,15 @@
import assert from 'assert'; import assert from 'assert';
import crypto from 'crypto'; import crypto from 'crypto-js';
import { import {
db, definePlugin, ForbiddenError, Handler, post, Types, yaml, db, definePlugin, ForbiddenError, Handler, post, Types, yaml,
} from 'hydrooj'; } from 'hydrooj';
function decrypt(encrypted: string) { function decrypt(encrypted: string) {
if (!encrypted) throw new Error(); return crypto.DES.decrypt(
const decipher = crypto.createDecipheriv('des-ecb', 'hydro-oj', ''); { ciphertext: crypto.enc.Hex.parse(encrypted) },
let decrypted = decipher.update(encrypted, 'hex', 'utf8'); crypto.enc.Utf8.parse('hydro-oj'),
decrypted += decipher.final('utf8'); { mode: crypto.mode.ECB },
return decrypted; ).toString(crypto.enc.Utf8);
} }
declare module 'hydrooj' { declare module 'hydrooj' {
@ -38,6 +38,7 @@ class DataReportHandler extends Handler {
try { try {
assert(typeof payload.url === 'string'); assert(typeof payload.url === 'string');
} catch (e) { } catch (e) {
console.log(payload);
throw new ForbiddenError(); throw new ForbiddenError();
} }
const old = await coll.findOne({ _id: installId }); const old = await coll.findOne({ _id: installId });

@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/center", "name": "@hydrooj/center",
"version": "0.2.0", "version": "0.2.1",
"main": "index.ts", "main": "index.ts",
"repository": "https://github.com/hydro-dev/Hydro.git", "repository": "https://github.com/hydro-dev/Hydro.git",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
@ -8,5 +8,8 @@
"preferUnplugged": true, "preferUnplugged": true,
"peerDependencies": { "peerDependencies": {
"hydrooj": "*" "hydrooj": "*"
},
"dependencies": {
"crypto-js": "^4.1.1"
} }
} }

Loading…
Cancel
Save