Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function chooseMedia (opts, mediaTypes) {
if (!opts || typeof opts !== 'object') {
opts = {}
}
const { sizeType = [], sourceType = [], success, fail, complete } = opts
const options = {
mediaTypes,
quality: sizeType[0] === 'compressed' ? 0.7 : 1
}
const isCamera = sourceType[0] === 'camera'
const status = isCamera ? await askAsyncPermissions(Permissions.CAMERA) : await askAsyncPermissions(Permissions.CAMERA_ROLL)
if (status !== 'granted') {
const res = { errMsg: 'Permissions denied!' }
return Promise.reject(res)
}
let p
return new Promise((resolve, reject) => {
p = isCamera ? ImagePicker.launchCameraAsync(options) : ImagePicker.launchImageLibraryAsync(options)
p.then((resp) => {
const { uri } = resp
resp.path = uri
const res = {
tempFilePaths: [uri],
tempFiles: [resp]
}
success && success(res)