strapi-cdn-url-rewrite
Advanced tools
Comparing version 0.0.3 to 0.0.4
28
index.js
@@ -15,3 +15,3 @@ const flatten = require('flat') | ||
) { | ||
this.orignal = storageUrl | ||
this.storage = storageUrl | ||
this.cdn = cdnUrl | ||
@@ -25,20 +25,16 @@ } else { | ||
try { | ||
if (data && data.constructor === Object) { | ||
const flattened = flatten(data) | ||
const flattened = flatten(data) | ||
let matches = [] | ||
for (let prop in flattened) { | ||
if (typeof flattened[prop] == 'string' && flattened[prop].includes(this.storage)) { | ||
matches.push({ | ||
prop, | ||
value: flattened[prop].replace(this.storage, this.cdn) | ||
}) | ||
} | ||
let matches = [] | ||
for (let prop in flattened) { | ||
if (typeof flattened[prop] == 'string' && flattened[prop].includes(this.storage)) { | ||
matches.push({ | ||
prop, | ||
value: flattened[prop].replace(this.storage, this.cdn) | ||
}) | ||
} | ||
} | ||
matches.forEach(match => dset(data, match.prop, match.value)) | ||
return data | ||
} else { | ||
throw new Error('`data` must be valid object') | ||
} | ||
matches.forEach(match => dset(data, match.prop, match.value)) | ||
return data | ||
} catch (err) { | ||
@@ -45,0 +41,0 @@ console.error(err) |
{ | ||
"name": "strapi-cdn-url-rewrite", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Strapi controller module to rewrite upload URLs to CDN", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
5843
107