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); const originalText = bytes.toString(CryptoJS.enc.Utf8); return originalText; }; 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 }