mirror of
https://github.com/stablyai/orca.git
synced 2026-10-18 08:03:22 +00:00
- mobileDiffImageDataUri now distinguishes a true deletion (modified side absent) from a modify whose binary bytes arrived empty (relay/size-cap cases), returning null instead of the stale pre-change image - readWorkingDiffFile passes the file path to bufferToBlob so relay working-tree reads can detect previewable image extensions instead of always reporting empty binary content - add mobile-file-tab-doc.test.ts covering diff/image/binary/text resolution paths
37 lines
1.5 KiB
TypeScript
37 lines
1.5 KiB
TypeScript
import { buildImageDataUri } from '../../../src/shared/image-data-uri'
|
|
|
|
// A git.diff result for a binary file. The host (git.diff) already sends base64
|
|
// image bytes plus isImage/mimeType for previewable formats, so mobile can render
|
|
// image diffs instead of falling back to "Binary preview unavailable". The
|
|
// originalIsBinary/modifiedIsBinary flags tell a deletion (modified side absent)
|
|
// apart from a modify whose bytes the host couldn't inline (relay/size-capped).
|
|
export type MobileBinaryDiffResult = {
|
|
kind: 'binary'
|
|
originalContent?: string
|
|
modifiedContent?: string
|
|
originalIsBinary?: boolean
|
|
modifiedIsBinary?: boolean
|
|
isImage?: boolean
|
|
mimeType?: string
|
|
}
|
|
|
|
// Builds a data URI for a binary image diff, preferring the modified (post-change)
|
|
// bytes. Only falls back to the original for a genuine deletion — when the modified
|
|
// side is absent (not binary). Returns null for non-previewable binaries and when
|
|
// the modified side IS a binary image but arrives empty (e.g. a relay working-tree
|
|
// read or a >size-cap file), since showing the pre-change image there would be
|
|
// silently stale rather than the current content.
|
|
export function mobileDiffImageDataUri(result: MobileBinaryDiffResult): string | null {
|
|
if (result.isImage !== true) {
|
|
return null
|
|
}
|
|
const modified = result.modifiedContent || ''
|
|
if (modified) {
|
|
return buildImageDataUri(result.mimeType, modified)
|
|
}
|
|
if (result.modifiedIsBinary === true) {
|
|
return null
|
|
}
|
|
return buildImageDataUri(result.mimeType, result.originalContent || '')
|
|
}
|