Skip to content

Commit

Permalink
tech(config): set and get config from json
Browse files Browse the repository at this point in the history
  • Loading branch information
shangan23 committed Apr 21, 2021
1 parent cf7a31f commit e46b77b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/decrypt.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
14 changes: 13 additions & 1 deletion src/encrypt.js
Original file line number Diff line number Diff line change
@@ -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')

Expand Down

0 comments on commit e46b77b

Please sign in to comment.