Skip to content

Commit

Permalink
fix(JS): safety check on resolve uri (#3915)
Browse files Browse the repository at this point in the history
  • Loading branch information
freeboub authored Jun 20, 2024
1 parent 3d6bc94 commit 84bb910
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}

Expand Down

0 comments on commit 84bb910

Please sign in to comment.