validateDownloadRequest method
void
validateDownloadRequest({
- required String manifestUrl,
- required String fileName,
- required HlsDownloadOptions options,
Implementation
void validateDownloadRequest({
required String manifestUrl,
required String fileName,
required HlsDownloadOptions options,
}) {
final parsed = Uri.tryParse(manifestUrl);
if (parsed == null ||
!(parsed.isScheme('http') || parsed.isScheme('https'))) {
throw const HlsDownloadException(
code: HlsErrorCode.invalidUrl,
message: 'manifestUrl must be a valid http(s) URL',
);
}
if (sanitizeFileName(fileName).isEmpty) {
throw const HlsDownloadException(
code: HlsErrorCode.invalidFileName,
message: 'fileName cannot be empty',
);
}
if (options.retryAttempts < 0) {
throw const HlsDownloadException(
code: HlsErrorCode.invalidOptions,
message: 'retryAttempts cannot be negative',
);
}
if (options.outputFileExtension.trim().isEmpty) {
throw const HlsDownloadException(
code: HlsErrorCode.invalidOptions,
message: 'outputFileExtension cannot be empty',
);
}
if (options.outputDirectoryPath != null &&
options.outputDirectoryPath!.trim().isEmpty) {
throw const HlsDownloadException(
code: HlsErrorCode.invalidOptions,
message: 'outputDirectoryPath cannot be blank',
);
}
final hasBlankHeaderKey = options.customHeaders.keys.any(
(key) => key.trim().isEmpty,
);
if (hasBlankHeaderKey) {
throw const HlsDownloadException(
code: HlsErrorCode.invalidOptions,
message: 'customHeaders cannot contain blank keys',
);
}
}