From 4eaf150adba0f431c3981b2fb049e31a5d883eec Mon Sep 17 00:00:00 2001 From: "xan.lol" Date: Sun, 9 Aug 2026 18:52:23 -0700 Subject: [PATCH] redrafting posts with image galleries that WORKS --- src/lib/api/index.ts | 6 ++++++ src/lib/api/resolve-gallery.ts | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/lib/api/resolve-gallery.ts diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts index 3f1c99eb7..192ba3df4 100644 --- a/src/lib/api/index.ts +++ b/src/lib/api/index.ts @@ -48,6 +48,7 @@ import { import {IS_IOS, IS_WEB} from '#/env' import * as bsky from '#/types/bsky' import {createGIFDescription} from '../gif-alt-text' +import {reuseGalleryImageBlob} from './resolve-gallery' import {uploadBlob} from './upload-blob' export {uploadBlob} @@ -421,6 +422,11 @@ async function resolveMedia( onStateChange?.(t`Uploading images...`) const items: $Typed[] = await Promise.all( imagesDraft.map(async (image, i) => { + const reusedImage = reuseGalleryImageBlob(image) + if (reusedImage) { + logger.debug(`Reusing existing blob for gallery image #${i}`) + return reusedImage + } logger.debug(`Compressing image #${i}`) const {path, width, height, mime} = await compressImage( image, diff --git a/src/lib/api/resolve-gallery.ts b/src/lib/api/resolve-gallery.ts new file mode 100644 index 000000000..0e178065b --- /dev/null +++ b/src/lib/api/resolve-gallery.ts @@ -0,0 +1,22 @@ +import {type $Typed, type AppBskyEmbedGallery} from '@atproto/api' + +import {type ComposerImage} from '#/state/gallery' + +/** Reuses the original blob when an untouched gallery image is redrafted. */ +export function reuseGalleryImageBlob( + image: ComposerImage, +): $Typed | undefined { + if (!image.blobRef) { + return undefined + } + + return { + $type: 'app.bsky.embed.gallery#image', + image: image.blobRef, + alt: image.alt, + aspectRatio: { + width: image.source.width, + height: image.source.height, + }, + } +} -- 2.51.2