|
|
@@ -14,7 +14,6 @@ class CdnResourcesService {
|
|
|
constructor() {
|
|
|
this.logger = require('@alias/logger')('growi:service:CdnResourcesService');
|
|
|
|
|
|
- this.noCdn = !!process.env.NO_CDN;
|
|
|
this.loadManifests();
|
|
|
}
|
|
|
|
|
|
@@ -23,6 +22,10 @@ class CdnResourcesService {
|
|
|
this.logger.debug('manifest data loaded : ', this.cdnManifests);
|
|
|
}
|
|
|
|
|
|
+ noCdn() {
|
|
|
+ return /^(true|1)$/i.test(process.env.NO_CDN);
|
|
|
+ }
|
|
|
+
|
|
|
getScriptManifestByName(name) {
|
|
|
const manifests = this.cdnManifests.js
|
|
|
.filter((manifest) => { return manifest.name === name });
|
|
|
@@ -72,9 +75,8 @@ class CdnResourcesService {
|
|
|
* Generate script tag string
|
|
|
*
|
|
|
* @param {Object} manifest
|
|
|
- * @param {boolean} noCdn
|
|
|
*/
|
|
|
- generateScriptTag(manifest, noCdn) {
|
|
|
+ generateScriptTag(manifest) {
|
|
|
const attrs = [];
|
|
|
const args = manifest.args || {};
|
|
|
|
|
|
@@ -87,7 +89,7 @@ class CdnResourcesService {
|
|
|
|
|
|
// TODO process integrity
|
|
|
|
|
|
- const url = noCdn
|
|
|
+ const url = this.noCdn()
|
|
|
? `${urljoin(cdnLocalScriptWebRoot, manifest.name)}.js`
|
|
|
: manifest.url;
|
|
|
return `<script src="${url}" ${attrs.join(' ')}></script>`;
|
|
|
@@ -95,7 +97,7 @@ class CdnResourcesService {
|
|
|
|
|
|
getScriptTagByName(name) {
|
|
|
const manifest = this.getScriptManifestByName(name);
|
|
|
- return this.generateScriptTag(manifest, this.noCdn);
|
|
|
+ return this.generateScriptTag(manifest);
|
|
|
}
|
|
|
|
|
|
getScriptTagsByGroup(group) {
|
|
|
@@ -104,7 +106,7 @@ class CdnResourcesService {
|
|
|
return manifest.groups != null && manifest.groups.includes(group);
|
|
|
})
|
|
|
.map((manifest) => {
|
|
|
- return this.generateScriptTag(manifest, this.noCdn);
|
|
|
+ return this.generateScriptTag(manifest);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -112,9 +114,8 @@ class CdnResourcesService {
|
|
|
* Generate style tag string
|
|
|
*
|
|
|
* @param {Object} manifest
|
|
|
- * @param {boolean} noCdn
|
|
|
*/
|
|
|
- generateStyleTag(manifest, noCdn) {
|
|
|
+ generateStyleTag(manifest) {
|
|
|
const attrs = [];
|
|
|
const args = manifest.args || {};
|
|
|
|
|
|
@@ -127,7 +128,7 @@ class CdnResourcesService {
|
|
|
|
|
|
// TODO process integrity
|
|
|
|
|
|
- const url = noCdn
|
|
|
+ const url = this.noCdn()
|
|
|
? `${urljoin(cdnLocalStyleWebRoot, manifest.name)}.css`
|
|
|
: manifest.url;
|
|
|
|
|
|
@@ -136,7 +137,7 @@ class CdnResourcesService {
|
|
|
|
|
|
getStyleTagByName(name) {
|
|
|
const manifest = this.getStyleManifestByName(name);
|
|
|
- return this.generateStyleTag(manifest, this.noCdn);
|
|
|
+ return this.generateStyleTag(manifest);
|
|
|
}
|
|
|
|
|
|
getStyleTagsByGroup(group) {
|
|
|
@@ -145,7 +146,7 @@ class CdnResourcesService {
|
|
|
return manifest.groups != null && manifest.groups.includes(group);
|
|
|
})
|
|
|
.map((manifest) => {
|
|
|
- return this.generateStyleTag(manifest, this.noCdn);
|
|
|
+ return this.generateStyleTag(manifest);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -160,7 +161,7 @@ class CdnResourcesService {
|
|
|
manifest = Object.assign(manifest, { url: url.toString() });
|
|
|
}
|
|
|
|
|
|
- return this.generateStyleTag(manifest, this.noCdn);
|
|
|
+ return this.generateStyleTag(manifest);
|
|
|
}
|
|
|
|
|
|
}
|