WIP
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
|
||||
import AES from 'crypto-js/AES';
|
||||
import CryptoJS from 'crypto-js';
|
||||
import crypto from "crypto"
|
||||
import * as hashFolderModule from "folder-hash"
|
||||
|
||||
|
||||
export const jjDecrypt = (encryptedText, key) => {
|
||||
const bytes = CryptoJS.AES.decrypt(encryptedText, key);
|
||||
@@ -14,3 +17,57 @@ export const jjEncrypt = (text, key) => {
|
||||
return AES.encrypt(text, key).toString();
|
||||
};
|
||||
|
||||
export const generateMD5 = (input) => {
|
||||
return crypto.createHash("md5").update(input).digest("hex");
|
||||
};
|
||||
|
||||
|
||||
export function generateSha1(str) {
|
||||
return crypto.createHash("sha1").update(str).digest("hex")
|
||||
}
|
||||
|
||||
|
||||
export async function generateHasDir(dir, excludeFoldersExtra = [], excludeFilesExtra = []) {
|
||||
// @see https://www.npmjs.com/package/folder-hash
|
||||
let sourceHashes = null
|
||||
|
||||
try {
|
||||
sourceHashes = await hashFolderModule.hashElement(dir, {
|
||||
encoding: "hex",
|
||||
folders: {
|
||||
ignoreRootName: true,
|
||||
exclude: [
|
||||
"node_modules",
|
||||
"dist",
|
||||
"build",
|
||||
".next",
|
||||
".git",
|
||||
"*~~",
|
||||
...excludeFoldersExtra
|
||||
],
|
||||
},
|
||||
files: {
|
||||
exclude: [
|
||||
".DS_Store",
|
||||
"**.DS_Store",
|
||||
".env",
|
||||
...excludeFilesExtra
|
||||
],
|
||||
matchBasename: true,
|
||||
matchPath: false,
|
||||
ignoreRootName: true,
|
||||
},
|
||||
symbolicLinks: {
|
||||
ignoreTargetPath: false,
|
||||
ignoreTargetContent: true,
|
||||
},
|
||||
})
|
||||
} catch (err) {
|
||||
if (err.code === "EMFILE") {
|
||||
throw new Error(`Too many open file descriptors! Increase the max open file descriptors limit for your operating system.`)
|
||||
}
|
||||
throw err
|
||||
}
|
||||
|
||||
return sourceHashes
|
||||
}
|
||||
Reference in New Issue
Block a user