Changeset View
Changeset View
Standalone View
Standalone View
native/media/identifier-utils.js
// @flow | // @flow | ||||
import { fetchableMediaURI } from 'lib/media/media-utils.js'; | |||||
function getCompatibleMediaURI(uri: string, ext: ?string): string { | function getCompatibleMediaURI(uri: string, ext: ?string): string { | ||||
if (!ext) { | if (!ext) { | ||||
return uri; | return uri; | ||||
} | } | ||||
if (!uri.startsWith('ph://') && !uri.startsWith('ph-upload://')) { | if (!uri.startsWith('ph://') && !uri.startsWith('ph-upload://')) { | ||||
return uri; | return uri; | ||||
} | } | ||||
const photoKitLocalIdentifier = uri.split('/')[2]; | const photoKitLocalIdentifier = uri.split('/')[2]; | ||||
Show All 26 Lines | function getMediaLibraryIdentifier(inputURI: string): ?string { | ||||
const matches = uri.match(mediaLibraryIdentifierRegex); | const matches = uri.match(mediaLibraryIdentifierRegex); | ||||
if (!matches) { | if (!matches) { | ||||
return null; | return null; | ||||
} | } | ||||
return matches[1]; | return matches[1]; | ||||
} | } | ||||
function getFetchableURI(inputURI: string): string { | function getFetchableURI(inputURI: string): string { | ||||
// support for blob service URIs | |||||
let uri = fetchableMediaURI(inputURI); | |||||
// React Native always resolves Apple's assets-library:// and FBMediaKit's | // React Native always resolves Apple's assets-library:// and FBMediaKit's | ||||
// ph:// scheme as an image so that the Image component can render thumbnails | // ph:// scheme as an image so that the Image component can render thumbnails | ||||
// of videos. In order to force fetch() to return a blob of the video, we need | // of videos. In order to force fetch() to return a blob of the video, we need | ||||
// to use the ph-upload:// scheme. https://git.io/Jerlh | // to use the ph-upload:// scheme. https://git.io/Jerlh | ||||
let uri = inputURI; | |||||
if (uri.startsWith('assets-library://')) { | if (uri.startsWith('assets-library://')) { | ||||
const mediaNativeID = getMediaLibraryIdentifier(uri); | const mediaNativeID = getMediaLibraryIdentifier(uri); | ||||
if (mediaNativeID) { | if (mediaNativeID) { | ||||
uri = `ph-upload://${mediaNativeID}/L0/001`; | uri = `ph-upload://${mediaNativeID}/L0/001`; | ||||
} | } | ||||
} | } | ||||
if (uri.startsWith('ph://')) { | if (uri.startsWith('ph://')) { | ||||
uri = uri.replace(/^ph:/, 'ph-upload:'); | uri = uri.replace(/^ph:/, 'ph-upload:'); | ||||
} | } | ||||
return uri; | return uri; | ||||
} | } | ||||
export { getCompatibleMediaURI, getMediaLibraryIdentifier, getFetchableURI }; | export { getCompatibleMediaURI, getMediaLibraryIdentifier, getFetchableURI }; |