fix(JS): safety check on resolve uri (#3915)

This commit is contained in:
Olivier Bouillet 2024-06-20 11:19:18 +02:00 committed by GitHub
parent 3d6bc9409c
commit 84bb910d10
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -15,17 +15,28 @@ type Source = ImageSourcePropType | ReactVideoSource;
export function resolveAssetSourceForVideo(
source: Source,
): ReactVideoSourceProperties {
// will convert source id to uri
const convertToUri = (sourceItem: number): string | undefined => {
const resolveItem = Image.resolveAssetSource(sourceItem);
if (resolveItem) {
return resolveItem.uri;
} else {
console.warn('cannot resolve item ', sourceItem);
return undefined;
}
};
// This is deprecated, but we need to support it for backward compatibility
if (typeof source === 'number') {
return {
uri: Image.resolveAssetSource(source).uri,
uri: convertToUri(source),
};
}
if ('uri' in source && typeof source.uri === 'number') {
return {
...source,
uri: Image.resolveAssetSource(source.uri).uri,
uri: convertToUri(source.uri),
};
}