Bluesky app fork with some witchin' additions 馃挮
at main 77 lines 1.7 kB view raw
1import { 2 documentDirectory, 3 getInfoAsync, 4 readDirectoryAsync, 5} from 'expo-file-system/legacy' 6import {type ImagePickerResult} from 'expo-image-picker' 7import ExpoImageCropTool, { 8 type OpenCropperOptions, 9} from '@bsky.app/expo-image-crop-tool' 10 11import {compressIfNeeded} from './manip' 12import {type PickerImage} from './picker.shared' 13 14async function getFile() { 15 const imagesDir = documentDirectory! 16 .split('/') 17 .slice(0, -6) 18 .concat(['Media', 'DCIM', '100APPLE']) 19 .join('/') 20 21 let files = await readDirectoryAsync(imagesDir) 22 files = files.filter(file => file.endsWith('.JPG')) 23 const file = `${imagesDir}/${files[0]}` 24 25 const fileInfo = await getInfoAsync(file) 26 27 if (!fileInfo.exists) { 28 throw new Error('Failed to get file info') 29 } 30 31 return await compressIfNeeded({ 32 path: file, 33 mime: 'image/jpeg', 34 size: fileInfo.size, 35 width: 4288, 36 height: 2848, 37 }) 38} 39 40export async function openPicker(): Promise<PickerImage[]> { 41 return [await getFile()] 42} 43 44export async function openUnifiedPicker(): Promise<ImagePickerResult> { 45 const file = await getFile() 46 47 return { 48 assets: [ 49 { 50 type: 'image', 51 uri: file.path, 52 mimeType: file.mime, 53 ...file, 54 }, 55 ], 56 canceled: false, 57 } 58} 59 60export async function openCamera(): Promise<PickerImage> { 61 return await getFile() 62} 63 64export async function openCropper(opts: OpenCropperOptions) { 65 const item = await ExpoImageCropTool.openCropperAsync({ 66 ...opts, 67 format: 'jpeg', 68 }) 69 70 return { 71 path: item.path, 72 mime: item.mimeType, 73 size: item.size, 74 width: item.width, 75 height: item.height, 76 } 77}