check validity of stream before returning

This commit is contained in:
mrjvs
2023-10-26 21:07:11 +02:00
parent 9d204c381f
commit bec7c07881
3 changed files with 25 additions and 1 deletions

17
src/utils/valid.ts Normal file
View File

@@ -0,0 +1,17 @@
import { Stream } from '@/providers/streams';
export function isValidStream(stream: Stream | undefined): boolean {
if (!stream) return false;
if (stream.type === 'hls') {
if (!stream.playlist) return false;
return true;
}
if (stream.type === 'file') {
const validQualities = Object.values(stream.qualities).filter((v) => v.url.length > 0);
if (validQualities.length === 0) return false;
return true;
}
// unknown file type
return false;
}