fix: replace SHA comparison with file size for LFS compatibility + add NoChangesModal

Git LFS stores pointer files whose SHA differs from the actual blob SHA,
causing false-positive diffs on every upload. Switching to file size
comparison resolves this for LFS-enabled repos.

Also replaces the inline error message with a dedicated NoChangesModal
when no differences are detected, offering cancel (reset) or modify
(close modal) actions.
This commit is contained in:
Tom Boullay
2026-04-14 14:39:19 +02:00
parent f9e15d5e1f
commit 91eaa5d186
5 changed files with 97 additions and 35 deletions
+8 -8
View File
@@ -5,7 +5,7 @@ import { existsSync } from 'fs'
import { validateUploadSecret } from '@/lib/auth'
import { parseMultiUpload } from '@/lib/parse-upload'
import { compressWithBlender } from '@/lib/blender'
import { computeGitBlobSha, getRemoteFolder, pushAllToGitHub } from '@/lib/github'
import { getRemoteFolder, pushAllToGitHub } from '@/lib/github'
import { buildCommitMessage } from '@/lib/commit-message'
import { TMP_DIR } from '@/lib/constants'
import type { FileChange } from '@/lib/types'
@@ -84,13 +84,13 @@ export async function POST(req: NextRequest) {
})
}
// --- Detect existing files and compare SHA to classify changes ---
// --- Detect existing files and compare size to classify changes (LFS-compatible) ---
const folderPath = `public/models/${destination}/${folderName}`
let remoteFileMap: Map<string, string>
let remoteFileMap: Map<string, number>
try {
const remote = await getRemoteFolder(folderPath)
remoteFileMap = new Map(remote.files.map((f) => [f.name.toLowerCase(), f.sha]))
remoteFileMap = new Map(remote.files.map((f) => [f.name.toLowerCase(), f.size]))
} catch {
remoteFileMap = new Map()
}
@@ -103,13 +103,13 @@ export async function POST(req: NextRequest) {
for (const f of filesToPush) {
const filename = f.path.split('/').pop() ?? ''
const localSha = computeGitBlobSha(Buffer.from(f.contentBase64, 'base64'))
const remoteSha = remoteFileMap.get(filename.toLowerCase())
const localSize = Buffer.from(f.contentBase64, 'base64').length
const remoteSize = remoteFileMap.get(filename.toLowerCase())
if (!remoteSha) {
if (remoteSize === undefined) {
fileChanges.set(filename.toLowerCase(), 'new')
changedFilesToPush.push(f)
} else if (remoteSha !== localSha) {
} else if (remoteSize !== localSize) {
fileChanges.set(filename.toLowerCase(), 'changed')
changedFilesToPush.push(f)
} else {