hlx-url-rewriter
Advanced tools
Comparing version 0.0.22 to 0.0.23
@@ -64,6 +64,27 @@ const path = require('path'); | ||
function createRelativeFunc(fromPath) { | ||
return pathname => path.relative(path.dirname(fromPath), pathname); | ||
function createPath(url, rootPath) { | ||
let absolutePath; | ||
if (url.protocol === 'file:') { | ||
if (url.pathname.startsWith(rootPath)) { | ||
absolutePath = url.pathname; | ||
} else { | ||
absolutePath = path.join(rootPath, url.pathname); | ||
} | ||
} else { | ||
absolutePath = path.join('/', url.hostname, url.pathname); | ||
} | ||
print(`\tcreatePath: ${url.href} => ${absolutePath}`); | ||
return absolutePath; | ||
} | ||
function createRelativePath(fromUrl, toUrl) { | ||
const {rootPath = '/'} = defaultFunc.options; | ||
const fromPath = createPath(fromUrl, rootPath); | ||
let toPath = createPath(toUrl, rootPath); | ||
if (fromUrl.protocol === 'file:' && toUrl.protocol !== 'file:') { | ||
toPath = path.join(rootPath, toPath); | ||
} | ||
return path.relative(path.dirname(fromPath), toPath); | ||
} | ||
function rewrite(uri, base) { | ||
@@ -81,11 +102,3 @@ const {rootPath = '/'} = defaultFunc.options; | ||
} | ||
const relativeToPlaylist = createRelativeFunc(playlistUrl.pathname); | ||
let result; | ||
if (url.protocol === playlistUrl.protocol && url.hostname === playlistUrl.hostname) { | ||
print('\tpattern-A'); | ||
result = relativeToPlaylist(url.pathname); | ||
} else { | ||
print('\tpattern-B'); | ||
result = relativeToPlaylist(path.join(playlistUrl.protocol === 'file:' ? rootPath : '/', url.hostname, url.pathname)); | ||
} | ||
const result = createRelativePath(playlistUrl, url); | ||
print(`\t>>> "${result}"`); | ||
@@ -92,0 +105,0 @@ return `${result}${url.search}${url.hash}`; |
{ | ||
"name": "hlx-url-rewriter", | ||
"version": "0.0.22", | ||
"version": "0.0.23", | ||
"description": "A transform stream to modify URLs contained in HLS playlists", | ||
@@ -60,3 +60,3 @@ "main": "index.js", | ||
"debug": "^4.1.1", | ||
"hlx-util": "0.0.8" | ||
"hlx-util": "0.0.9" | ||
}, | ||
@@ -63,0 +63,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9430
127
+ Addedhlx-util@0.0.9(transitive)
- Removedhlx-util@0.0.8(transitive)
Updatedhlx-util@0.0.9