|
1 | 1 | "use strict"; |
2 | 2 |
|
| 3 | +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } |
| 4 | + |
| 5 | +function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } |
| 6 | + |
| 7 | +function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } |
| 8 | + |
| 9 | +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } |
| 10 | + |
3 | 11 | /*** |
4 | 12 | * Assign a value to a nested object |
5 | 13 | * @function putNestedValue |
@@ -48,31 +56,44 @@ function putNestedValue(params, key, value) { |
48 | 56 |
|
49 | 57 | module.exports = function (new_config, new_value) { |
50 | 58 | if (cloudinary_config == null || new_config === true) { |
| 59 | + if (cloudinary_config == null) { |
| 60 | + cloudinary_config = {}; |
| 61 | + } else { |
| 62 | + Object.keys(cloudinary_config).forEach(function (key) { |
| 63 | + return delete cloudinary_config[key]; |
| 64 | + }); |
| 65 | + } |
| 66 | + |
51 | 67 | var cloudinary_url = process.env.CLOUDINARY_URL; |
52 | 68 |
|
53 | 69 | if (cloudinary_url != null) { |
54 | 70 | var uri = url.parse(cloudinary_url, true); |
55 | | - cloudinary_config = { |
| 71 | + var parsedConfig = { |
56 | 72 | cloud_name: uri.host, |
57 | 73 | api_key: uri.auth && uri.auth.split(":")[0], |
58 | 74 | api_secret: uri.auth && uri.auth.split(":")[1], |
59 | 75 | private_cdn: uri.pathname != null, |
60 | 76 | secure_distribution: uri.pathname && uri.pathname.substring(1) |
61 | 77 | }; |
| 78 | + Object.entries(parsedConfig).forEach(function (_ref) { |
| 79 | + var _ref2 = _slicedToArray(_ref, 2), |
| 80 | + key = _ref2[0], |
| 81 | + value = _ref2[1]; |
62 | 82 |
|
63 | | - if (uri.query != null) { |
64 | | - for (var k in uri.query) { |
65 | | - var v = uri.query[k]; |
66 | | - |
67 | | - if (isNestedKey(k)) { |
68 | | - putNestedValue(cloudinary_config, k, v); |
69 | | - } else { |
70 | | - cloudinary_config[k] = v; |
71 | | - } |
| 83 | + if (value !== undefined) { |
| 84 | + cloudinary_config[key] = value; |
72 | 85 | } |
| 86 | + }); |
| 87 | + |
| 88 | + if (uri.query != null) { |
| 89 | + Object.entries(uri.query).forEach(function (_ref3) { |
| 90 | + var _ref4 = _slicedToArray(_ref3, 2), |
| 91 | + key = _ref4[0], |
| 92 | + value = _ref4[1]; |
| 93 | + |
| 94 | + return putNestedValue(cloudinary_config, key, value); |
| 95 | + }); |
73 | 96 | } |
74 | | - } else { |
75 | | - cloudinary_config = {}; |
76 | 97 | } |
77 | 98 | } |
78 | 99 |
|
|
0 commit comments