Bluesky app fork with some witchin' additions 💫 witchsky.app
bluesky fork client
117
fork

Configure Feed

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

Fix RN does not allow Blob from ArrayBuffer

authored by

uwx and committed by
Tangled
caa14e93 3413cb31

+7 -26
+7 -26
src/state/gallery.ts
··· 13 13 } from 'expo-image-manipulator' 14 14 import {type BlobRef} from '@atproto/api' 15 15 import {transformExif} from '@uwx/exif-be-gone-web' 16 - import {toByteArray} from 'base64-js' 16 + import {toByteArray, fromByteArray} from 'base64-js' 17 17 import {nanoid} from 'nanoid/non-secure' 18 18 19 19 import {POST_IMG_MAX} from '#/lib/constants' ··· 216 216 return toByteArray(base64) 217 217 } 218 218 219 - function toArrayBuffer(uint8: Uint8Array) { 220 - if (uint8.buffer instanceof ArrayBuffer) { 221 - if ( 222 - uint8.byteOffset === 0 && 223 - uint8.byteLength === uint8.buffer.byteLength 224 - ) { 225 - return uint8.buffer 226 - } 227 - 228 - return uint8.buffer.slice( 229 - uint8.byteOffset, 230 - uint8.byteOffset + uint8.byteLength, 231 - ) 232 - } 233 - 234 - // Fallback for environments where Uint8Array.buffer is not an ArrayBuffer 235 - const buffer = new ArrayBuffer(uint8.length) 236 - const view = new Uint8Array(buffer) 237 - view.set(uint8) 238 - return buffer 239 - } 240 - 241 219 const source = img.transformed || img.source 242 220 if ( 243 221 source.width > POST_IMG_MAX.width || ··· 291 269 return undefined 292 270 } 293 271 294 - const dataUri = await blobToDataUri( 295 - new Blob([toArrayBuffer(data)], {type: source.mime}), 296 - ) 272 + const dataUri = arrayBufferToDataUri(data, source.mime) 297 273 return { 298 274 path: dataUri, 299 275 width: source.width, ··· 459 435 reader.onerror = () => reject(reader.error) 460 436 reader.readAsDataURL(blob) 461 437 }) 438 + } 439 + 440 + function arrayBufferToDataUri(buffer: Uint8Array | ArrayBufferLike, mime: string): string { 441 + const base64 = fromByteArray(buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer)) 442 + return `data:${mime};base64,${base64}` 462 443 } 463 444 464 445 /** Purge files that were created to accomodate image manipulation */