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
26 lines
886 B
TypeScript
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 }
|
|
}
|
|
}
|