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
bc6426927f
commit
5db23edebb
8 files changed
+74
-58
No files matched your search
+10
-18
@@ -1,20 +1,12 @@
|
||||
const crypto = require('crypto');
|
||||
|
||||
global.Hydro.lib['hash.hydro'] = module.exports = {
|
||||
/**
|
||||
* @param {string} password
|
||||
* @param {string} salt
|
||||
* @param {string} hash
|
||||
*/
|
||||
check(password, salt, hash) {
|
||||
return hash === this.hash(password, salt);
|
||||
},
|
||||
/**
|
||||
* @param {string} password
|
||||
* @param {string} salt
|
||||
*/
|
||||
hash(password, salt) {
|
||||
const res = crypto.pbkdf2Sync(password, salt, 100000, 64, 'sha256');
|
||||
return res.toString('Hex');
|
||||
},
|
||||
};
|
||||
/**
|
||||
* @param {string} password
|
||||
* @param {string} salt
|
||||
*/
|
||||
function hash(password, salt) {
|
||||
const res = crypto.pbkdf2Sync(password, salt, 100000, 64, 'sha256');
|
||||
return res.toString('Hex');
|
||||
}
|
||||
|
||||
global.Hydro.lib['hash.hydro'] = module.exports = hash;
|
||||
@@ -0,0 +1,23 @@
|
||||
const yaml = require('js-yaml');
|
||||
|
||||
function warp(func, type) {
|
||||
return (...args) => {
|
||||
const time = new Date();
|
||||
func(...args);
|
||||
if (global.Hydro.model.message) {
|
||||
global.Hydro.model.message.send(1, 1, yaml.safeDump({ time, type, args }));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
class Logger {
|
||||
constructor() {
|
||||
this.log = warp(console.log, 'log');
|
||||
this.error = warp(console.error, 'error');
|
||||
this.info = warp(console.info, 'info');
|
||||
this.warn = warp(console.warn, 'warn');
|
||||
this.debug = warp(console.debug, 'debug');
|
||||
}
|
||||
}
|
||||
|
||||
global.Hydro.lib.logger = module.exports = new Logger();
|
||||
Reference in new issue
Block a user