fix error + format
This commit is contained in:
+15
-20
@@ -1,12 +1,9 @@
|
||||
import crypto from "crypto";
|
||||
import crypto from 'crypto'
|
||||
|
||||
let SHA256_cache = {}
|
||||
|
||||
function _SHA256(str) {
|
||||
return crypto
|
||||
.createHash("sha256")
|
||||
.update(str)
|
||||
.digest("base64");
|
||||
return crypto.createHash('sha256').update(str).digest('base64')
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -17,25 +14,23 @@ function _SHA256(str) {
|
||||
* @returns {string} base64 digested hash
|
||||
*/
|
||||
function SHA256(str, salt, num) {
|
||||
if (!num && num !== 0)
|
||||
num = 1;
|
||||
if (!str)
|
||||
return;
|
||||
let identifier = _SHA256(str+salt+num.toString())
|
||||
if(SHA256_cache[identifier] != undefined) {
|
||||
return SHA256_cache[identifier];
|
||||
if (!num && num !== 0) num = 1
|
||||
if (!str) return
|
||||
let identifier = _SHA256(str + salt + num.toString())
|
||||
if (SHA256_cache[identifier] != undefined) {
|
||||
return SHA256_cache[identifier]
|
||||
}
|
||||
let ret = str;
|
||||
let ret = str
|
||||
for (let i = 0; i < num; i++) {
|
||||
ret = _SHA256(ret + salt)
|
||||
}
|
||||
SHA256_cache[identifier] = ret;
|
||||
setTimeout(()=>{
|
||||
SHA256_cache[identifier] = ret
|
||||
setTimeout(() => {
|
||||
SHA256_cache[identifier] = undefined
|
||||
},10000) //cache for 10s
|
||||
return ret;
|
||||
}, 10000) //cache for 10s
|
||||
return ret
|
||||
}
|
||||
export { SHA256 };
|
||||
export { SHA256 }
|
||||
export default {
|
||||
SHA256: SHA256
|
||||
};
|
||||
SHA256: SHA256,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user