diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/media/manip.ts | 31 | ||||
-rw-r--r-- | src/lib/media/manip.web.ts | 7 |
2 files changed, 36 insertions, 2 deletions
diff --git a/src/lib/media/manip.ts b/src/lib/media/manip.ts index c35953703..2f6c25e83 100644 --- a/src/lib/media/manip.ts +++ b/src/lib/media/manip.ts @@ -5,6 +5,7 @@ import {Image} from 'react-native-image-crop-picker' import * as RNFS from 'react-native-fs' import uuid from 'react-native-uuid' import * as Sharing from 'expo-sharing' +import * as MediaLibrary from 'expo-media-library' import {Dimensions} from './types' import {isAndroid, isIOS} from 'platform/detection' @@ -75,7 +76,7 @@ export async function downloadAndResize(opts: DownloadAndResizeOpts) { } } -export async function saveImageModal({uri}: {uri: string}) { +export async function shareImageModal({uri}: {uri: string}) { if (!(await Sharing.isAvailableAsync())) { // TODO might need to give an error to the user in this case -prf return @@ -107,6 +108,34 @@ export async function saveImageModal({uri}: {uri: string}) { RNFS.unlink(imagePath) } +export async function saveImageToAlbum({ + uri, + album, +}: { + uri: string + album: string +}) { + // download the file to cache + // NOTE + // assuming PNG + // we're currently relying on the fact our CDN only serves pngs + // -prf + const downloadResponse = await RNFetchBlob.config({ + fileCache: true, + }).fetch('GET', uri) + let imagePath = downloadResponse.path() + imagePath = normalizePath(await moveToPermanentPath(imagePath, '.png'), true) + + // save to the album (creating as needed) + const assetRef = await MediaLibrary.createAssetAsync(imagePath) + const albumRef = await MediaLibrary.getAlbumAsync(album) + if (albumRef) { + await MediaLibrary.addAssetsToAlbumAsync(assetRef, albumRef) + } else { + await MediaLibrary.createAlbumAsync(album, assetRef) + } +} + export function getImageDim(path: string): Promise<Dimensions> { return new Promise((resolve, reject) => { RNImage.getSize( diff --git a/src/lib/media/manip.web.ts b/src/lib/media/manip.web.ts index 464802c32..914b05d2e 100644 --- a/src/lib/media/manip.web.ts +++ b/src/lib/media/manip.web.ts @@ -37,7 +37,12 @@ export async function downloadAndResize(opts: DownloadAndResizeOpts) { return await doResize(dataUri, opts) } -export async function saveImageModal(_opts: {uri: string}) { +export async function shareImageModal(_opts: {uri: string}) { + // TODO + throw new Error('TODO') +} + +export async function saveImageToAlbum(_opts: {uri: string; album: string}) { // TODO throw new Error('TODO') } |