Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Bypass image compression on web if the original image is within post constraints

authored by

uwx and committed by tangled.org c77d85e1 0bd74eaf

+58
+58
src/state/gallery.ts
··· 204 204 return img 205 205 } 206 206 207 + async function bypassCompressionOnWeb( 208 + img: ComposerImage, 209 + ): Promise<PickerImage | undefined> { 210 + const source = img.transformed || img.source 211 + if ( 212 + source.width > POST_IMG_MAX.width || 213 + source.height > POST_IMG_MAX.height 214 + ) { 215 + return undefined 216 + } 217 + 218 + if ( 219 + ![ 220 + 'image/jpeg', 221 + 'image/png', 222 + 'image/webp', 223 + 'image/avif', 224 + 'image/gif', 225 + ].includes(source.mime) 226 + ) { 227 + return undefined 228 + } 229 + 230 + const path = source.path 231 + // convert path to data URI if it is not already 232 + if (!path.startsWith('data:')) { 233 + try { 234 + await fetch(path) 235 + const response = await fetch(path) 236 + const blob = await response.blob() 237 + if (blob.size > POST_IMG_MAX.size) { 238 + return undefined 239 + } 240 + // path = await blobToDataUri(blob) 241 + } catch (e) { 242 + // Fetch failed, likely due to CORS. Return undefined to trigger normal compression flow and error handling. 243 + return undefined 244 + } 245 + } else if (getDataUriSize(path) > POST_IMG_MAX.size) { 246 + return undefined 247 + } 248 + 249 + return { 250 + path: await moveIfNecessary(path), 251 + width: source.width, 252 + height: source.height, 253 + mime: source.mime, 254 + size: getDataUriSize(path), 255 + } 256 + } 257 + 207 258 export async function compressImage( 208 259 img: ComposerImage, 209 260 options?: { 210 261 highResolution?: boolean 211 262 }, 212 263 ): Promise<PickerImage> { 264 + if (IS_WEB) { 265 + const res = await bypassCompressionOnWeb(img) 266 + if (res) { 267 + return res 268 + } 269 + } 270 + 213 271 const source = img.transformed || img.source 214 272 const highResolution = options?.highResolution ?? false 215 273 let attempts = 0