mirror of
https://github.com/iptv-org/iptv
synced 2026-09-09 13:27:58 -04:00
fix: address nested playlist review feedback
This commit is contained in:
+5
-7
@@ -45,17 +45,15 @@ export function normalizeURL(url: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getStoragePath(filepath: string, rootDir: string): string {
|
export function getStoragePath(filepath: string, rootDir: string): string {
|
||||||
const relative = path.relative(path.resolve(rootDir), path.resolve(filepath))
|
const root = path.resolve(rootDir)
|
||||||
|
const target = path.resolve(path.isAbsolute(filepath) ? filepath : path.join(root, filepath))
|
||||||
|
const relative = path.relative(root, target)
|
||||||
|
|
||||||
if (relative && relative !== '..' && !relative.startsWith(`..${path.sep}`)) {
|
if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
||||||
return relative
|
|
||||||
}
|
|
||||||
|
|
||||||
if (path.isAbsolute(filepath) || filepath === '..' || filepath.startsWith(`..${path.sep}`)) {
|
|
||||||
throw new Error(`Filepath "${filepath}" is outside the storage directory`)
|
throw new Error(`Filepath "${filepath}" is outside the storage directory`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return filepath
|
return relative
|
||||||
}
|
}
|
||||||
|
|
||||||
export function truncate(string: string, limit: number = 100) {
|
export function truncate(string: string, limit: number = 100) {
|
||||||
|
|||||||
@@ -31,14 +31,12 @@ describe('playlist:format', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
it('formats playlists in nested directories', () => {
|
it('formats playlists in nested directories', () => {
|
||||||
fs.emptyDirSync('tests/__data__/output')
|
const cmd = `${ENV_VAR} npm run playlist:format`
|
||||||
fs.copySync('tests/__data__/input/playlist_paths', 'tests/__data__/output/streams')
|
|
||||||
|
|
||||||
const cmd =
|
|
||||||
'cross-env STREAMS_DIR=tests/__data__/output/streams DATA_DIR=tests/__data__/input/data npm run playlist:format'
|
|
||||||
execSync(cmd, { encoding: 'utf8' })
|
execSync(cmd, { encoding: 'utf8' })
|
||||||
|
|
||||||
const output = content('tests/__data__/output/streams/nested/nested.m3u')
|
const output = content('tests/__data__/output/streams/nested/nested.m3u')
|
||||||
|
expect(output).toContain(',Alpha (720p)')
|
||||||
|
expect(output).toContain(',Zulu (720p)')
|
||||||
expect(output.indexOf(',Alpha (720p)')).toBeLessThan(output.indexOf(',Zulu (720p)'))
|
expect(output.indexOf(',Alpha (720p)')).toBeLessThan(output.indexOf(',Zulu (720p)'))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user