b1c454f779
- Upgrade eslint from v8 to v9.18.0 - Migrate from .eslintrc.js to eslint.config.mjs (flat config) - Upgrade typescript-eslint to v8.20.0 (unified package) - Replace eslint-plugin-import with eslint-plugin-import-x for flat config support - Add globals package for environment globals - Update eslint-plugin-bsky-internal with proper meta objects for ESLint v9 - Fix deprecated context.getScope() API usage - Update bskyembed to use flat config - Remove deprecated --ext flag from lint scripts - Configure rules to maintain previous behavior while using new ESLint version
78 lines
1.6 KiB
TypeScript
78 lines
1.6 KiB
TypeScript
import {
|
|
documentDirectory,
|
|
getInfoAsync,
|
|
readDirectoryAsync,
|
|
} from 'expo-file-system/legacy'
|
|
import {type ImagePickerResult} from 'expo-image-picker'
|
|
import ExpoImageCropTool, {
|
|
type OpenCropperOptions,
|
|
} from '@bsky.app/expo-image-crop-tool'
|
|
|
|
import {compressIfNeeded} from './manip'
|
|
import {type PickerImage} from './picker.shared'
|
|
|
|
async function getFile() {
|
|
const imagesDir = documentDirectory!
|
|
.split('/')
|
|
.slice(0, -6)
|
|
.concat(['Media', 'DCIM', '100APPLE'])
|
|
.join('/')
|
|
|
|
let files = await readDirectoryAsync(imagesDir)
|
|
files = files.filter(file => file.endsWith('.JPG'))
|
|
const file = `${imagesDir}/${files[0]}`
|
|
|
|
const fileInfo = await getInfoAsync(file)
|
|
|
|
if (!fileInfo.exists) {
|
|
throw new Error('Failed to get file info')
|
|
}
|
|
|
|
return await compressIfNeeded({
|
|
path: file,
|
|
mime: 'image/jpeg',
|
|
size: fileInfo.size,
|
|
width: 4288,
|
|
height: 2848,
|
|
})
|
|
}
|
|
|
|
export async function openPicker(): Promise<PickerImage[]> {
|
|
return [await getFile()]
|
|
}
|
|
|
|
export async function openUnifiedPicker(): Promise<ImagePickerResult> {
|
|
const file = await getFile()
|
|
|
|
return {
|
|
assets: [
|
|
{
|
|
type: 'image',
|
|
uri: file.path,
|
|
mimeType: file.mime,
|
|
...file,
|
|
},
|
|
],
|
|
canceled: false,
|
|
}
|
|
}
|
|
|
|
export async function openCamera(): Promise<PickerImage> {
|
|
return await getFile()
|
|
}
|
|
|
|
export async function openCropper(opts: OpenCropperOptions) {
|
|
const item = await ExpoImageCropTool.openCropperAsync({
|
|
...opts,
|
|
format: 'jpeg',
|
|
})
|
|
|
|
return {
|
|
path: item.path,
|
|
mime: item.mimeType,
|
|
size: item.size,
|
|
width: item.width,
|
|
height: item.height,
|
|
}
|
|
}
|