diff --git a/src/config.json b/src/config.json new file mode 100644 index 0000000..ec30533 --- /dev/null +++ b/src/config.json @@ -0,0 +1 @@ +{"secret":"encrypt","algorithm":"AES"} \ No newline at end of file diff --git a/src/decrypt.js b/src/decrypt.js index a6b1fa5..6efd93a 100644 --- a/src/decrypt.js +++ b/src/decrypt.js @@ -1,9 +1,13 @@ const Url = require('url-parse') const CryptoJS = require('crypto-js') +const fs = require('fs') import { isUrl, isPatternUrl, isPattern, isPath } from '../util' +const configData = fs.readFileSync(__dirname + '/config.json', 'utf8') +const configObject = JSON.parse(configData) + const decrypt = (function () { - const secret = 'Secret Passphrase' + const secret = configObject['secret'] return { url: function (givenUrl, options = {}) { if (!givenUrl) throw new Error('url is missing') diff --git a/src/encrypt.js b/src/encrypt.js index 3191ec7..d5538d9 100644 --- a/src/encrypt.js +++ b/src/encrypt.js @@ -1,10 +1,22 @@ const Url = require('url-parse') const CryptoJS = require('crypto-js') +const fs = require('fs') import { isUrl, isPatternUrl, isPatterObject, isPattern, isPath } from '../util' +const configData = fs.readFileSync(__dirname + '/config.json', 'utf8') +const configObject = JSON.parse(configData) + const encrypt = (function () { - const secret = 'Secret Passphrase' + const secret = configObject.secret return { + config: function (config = {}) { + if (Object.keys(config).length === 0) + throw new Error('options is missing') + for (const [key, value] of Object.entries(config)) { + configObject[key] = value + } + fs.writeFileSync(__dirname + '/config.json', JSON.stringify(configObject)) + }, url: function (url, options = {}) { if (!url) throw new Error('url is missing')