Bluesky app fork with some witchin' additions 💫

Android - add fallbacks when saving image to gallery (#9293)

* add fallback paths when saving image to gallery

* `debug` -> `info`

authored by samuel.fm and committed by

GitHub e3f59674 900e569e

+34 -2
+34 -2
src/lib/media/manip.ts
··· 114 114 // as the starting image, or put it directly into the album 115 115 const album = await MediaLibrary.getAlbumAsync(ALBUM_NAME) 116 116 if (album) { 117 - // if album exists, put the image straight in there 118 - await MediaLibrary.createAssetAsync(imagePath, album) 117 + // try and migrate if needed 118 + try { 119 + if (await MediaLibrary.albumNeedsMigrationAsync(album)) { 120 + await MediaLibrary.migrateAlbumIfNeededAsync(album) 121 + } 122 + } catch (err) { 123 + logger.info('Attempted and failed to migrate album', { 124 + safeMessage: err, 125 + }) 126 + } 127 + 128 + try { 129 + // if album exists, put the image straight in there 130 + await MediaLibrary.createAssetAsync(imagePath, album) 131 + } catch (err) { 132 + logger.info('Failed to create asset', {safeMessage: err}) 133 + // however, it's possible that we don't have write permission to the album 134 + // try making a new one! 135 + try { 136 + await MediaLibrary.createAlbumAsync( 137 + ALBUM_NAME, 138 + undefined, 139 + undefined, 140 + imagePath, 141 + ) 142 + } catch (err2) { 143 + logger.info('Failed to create asset in a fresh album', { 144 + safeMessage: err2, 145 + }) 146 + // ... and if all else fails, just put it in DCIM 147 + await MediaLibrary.createAssetAsync(imagePath) 148 + } 149 + } 119 150 } else { 120 151 // otherwise, create album with asset (albums must always have at least one asset) 121 152 await MediaLibrary.createAlbumAsync( ··· 132 163 logger.error(err instanceof Error ? err : String(err), { 133 164 message: 'Failed to save image to media library', 134 165 }) 166 + throw err 135 167 } finally { 136 168 safeDeleteAsync(imagePath) 137 169 }