strapi-cdn-url-rewrite
Advanced tools
Comparing version 0.1.0 to 0.1.1
28
index.js
@@ -22,13 +22,29 @@ const { flatten, unflatten } = require('safe-flat') | ||
crawl = data => { | ||
const flattened = flatten(data) | ||
for (let prop in flattened) { | ||
if (typeof flattened[prop] === 'string' && flattened[prop].startsWith(this.storage)) { | ||
flattened[prop] = flattened[prop].replace(this.storage, this.cdn) | ||
} | ||
} | ||
return unflatten(flattened) | ||
} | ||
cdnRewrite = async data => { | ||
try { | ||
const flattened = flatten(await flatten(data)['0']) | ||
data = await data | ||
for (let prop in flattened) { | ||
if (typeof flattened[prop] === 'string' && flattened[prop].startsWith(this.storage)) { | ||
flattened[prop] = flattened[prop].replace(this.storage, this.cdn) | ||
if (Array.isArray(data)) { | ||
let out = [] | ||
for (let item of data) { | ||
out.push(this.crawl(await item)) | ||
} | ||
return out | ||
} else { | ||
return this.crawl(data) | ||
} | ||
return unflatten(flattened) | ||
} catch (err) { | ||
@@ -35,0 +51,0 @@ console.error(err) |
{ | ||
"name": "strapi-cdn-url-rewrite", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Strapi controller module to rewrite upload URLs to CDN", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
6421
114