check validity of stream before returning
This commit is contained in:
parent
9d204c381f
commit
bec7c07881
|
@ -6,6 +6,7 @@ import { EmbedOutput, SourcererOutput } from '@/providers/base';
|
||||||
import { ProviderList } from '@/providers/get';
|
import { ProviderList } from '@/providers/get';
|
||||||
import { ScrapeContext } from '@/utils/context';
|
import { ScrapeContext } from '@/utils/context';
|
||||||
import { NotFoundError } from '@/utils/errors';
|
import { NotFoundError } from '@/utils/errors';
|
||||||
|
import { isValidStream } from '@/utils/valid';
|
||||||
|
|
||||||
export type IndividualSourceRunnerOptions = {
|
export type IndividualSourceRunnerOptions = {
|
||||||
features: FeatureMap;
|
features: FeatureMap;
|
||||||
|
@ -50,7 +51,7 @@ export async function scrapeInvidualSource(
|
||||||
});
|
});
|
||||||
|
|
||||||
// stream doesn't satisfy the feature flags, so gets removed in output
|
// stream doesn't satisfy the feature flags, so gets removed in output
|
||||||
if (output?.stream && !flagsAllowedInFeatures(ops.features, output.stream.flags)) {
|
if (output?.stream && (!isValidStream(output.stream) || !flagsAllowedInFeatures(ops.features, output.stream.flags))) {
|
||||||
output.stream = undefined;
|
output.stream = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +88,9 @@ export async function scrapeIndividualEmbed(
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!isValidStream(output.stream)) throw new NotFoundError('stream is incomplete');
|
||||||
if (!flagsAllowedInFeatures(ops.features, output.stream.flags))
|
if (!flagsAllowedInFeatures(ops.features, output.stream.flags))
|
||||||
throw new NotFoundError("stream doesn't satisfy target feature flags");
|
throw new NotFoundError("stream doesn't satisfy target feature flags");
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { Stream } from '@/providers/streams';
|
||||||
import { ScrapeContext } from '@/utils/context';
|
import { ScrapeContext } from '@/utils/context';
|
||||||
import { NotFoundError } from '@/utils/errors';
|
import { NotFoundError } from '@/utils/errors';
|
||||||
import { reorderOnIdList } from '@/utils/list';
|
import { reorderOnIdList } from '@/utils/list';
|
||||||
|
import { isValidStream } from '@/utils/valid';
|
||||||
|
|
||||||
export type RunOutput = {
|
export type RunOutput = {
|
||||||
sourceId: string;
|
sourceId: string;
|
||||||
|
@ -79,6 +80,9 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
|
||||||
...contextBase,
|
...contextBase,
|
||||||
media: ops.media,
|
media: ops.media,
|
||||||
});
|
});
|
||||||
|
if (!isValidStream(output?.stream)) {
|
||||||
|
throw new NotFoundError('stream is incomplete');
|
||||||
|
}
|
||||||
if (output?.stream && !flagsAllowedInFeatures(ops.features, output.stream.flags)) {
|
if (output?.stream && !flagsAllowedInFeatures(ops.features, output.stream.flags)) {
|
||||||
throw new NotFoundError("stream doesn't satisfy target feature flags");
|
throw new NotFoundError("stream doesn't satisfy target feature flags");
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue