center: support node18 crypto

This commit is contained in:
undefined committed 2022-11-20 12:37:27 +08:00
1 parent e32f285876
commit 067eb2c348
2 files changed
+11 -7

No files matched your search

+7 -6
View File
@@ -1,15 +1,15 @@
import assert from 'assert';
import crypto from 'crypto';
import crypto from 'crypto-js';
import {
db, definePlugin, ForbiddenError, Handler, post, Types, yaml,
} from 'hydrooj';
function decrypt(encrypted: string) {
if (!encrypted) throw new Error();
const decipher = crypto.createDecipheriv('des-ecb', 'hydro-oj', '');
let decrypted = decipher.update(encrypted, 'hex', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
return crypto.DES.decrypt(
{ ciphertext: crypto.enc.Hex.parse(encrypted) },
crypto.enc.Utf8.parse('hydro-oj'),
{ mode: crypto.mode.ECB },
).toString(crypto.enc.Utf8);
}
declare module 'hydrooj' {
@@ -38,6 +38,7 @@ class DataReportHandler extends Handler {
try {
assert(typeof payload.url === 'string');
} catch (e) {
console.log(payload);
throw new ForbiddenError();
}
const old = await coll.findOne({ _id: installId });
+4 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/center",
"version": "0.2.0",
"version": "0.2.1",
"main": "index.ts",
"repository": "https://github.com/hydro-dev/Hydro.git",
"author": "undefined <i@undefined.moe>",
@@ -8,5 +8,8 @@
"preferUnplugged": true,
"peerDependencies": {
"hydrooj": "*"
},
"dependencies": {
"crypto-js": "^4.1.1"
}
}