Files
orca/src/relay/git-working-file-read.ts
T
Jinjing 115b87efe4 Fix stale binary image fallback for empty modified diffs and relay reads
- 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
2026-07-16 16:46:59 -07:00

26 lines
886 B
TypeScript

import { readFile, stat } from 'node:fs/promises'
import { bufferToBlob } from './git-handler-utils'
const MAX_RELAY_DIFF_WORKING_FILE_BYTES = 10 * 1024 * 1024
export async function readWorkingDiffFile(
absPath: string
): Promise<{ content: string; isBinary: boolean }> {
try {
const fileStat = await stat(absPath)
if (!fileStat.isFile()) {
return { content: '', isBinary: false }
}
if (fileStat.size > MAX_RELAY_DIFF_WORKING_FILE_BYTES) {
// Why: mirror local git diff reads, which cap blob transfer at 10MB.
return { content: '', isBinary: true }
}
const buffer = await readFile(absPath)
// Why: bufferToBlob needs the path's extension to know an image is
// previewable; omitting it made every relay-side binary diff empty.
return bufferToBlob(buffer, absPath)
} catch {
return { content: '', isBinary: false }
}
}