fix: skip model size comparison in diff check (Blender compression changes size)
Models are always re-pushed server-side since Draco compression changes the file size, making client/remote size comparison unreliable. Textures are still compared by size (not compressed, reliable). Client-side diff now only flags models as 'new' if absent from remote, and never as 'changed' (server handles the actual push decision).
This commit is contained in:
+23
-11
@@ -7,7 +7,7 @@ import { parseMultiUpload } from '@/lib/parse-upload'
|
||||
import { compressWithBlender } from '@/lib/blender'
|
||||
import { getRemoteFolder, pushAllToGitHub } from '@/lib/github'
|
||||
import { buildCommitMessage } from '@/lib/commit-message'
|
||||
import { TMP_DIR } from '@/lib/constants'
|
||||
import { TMP_DIR, MODEL_EXTENSIONS } from '@/lib/constants'
|
||||
import type { FileChange } from '@/lib/types'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
@@ -84,7 +84,9 @@ export async function POST(req: NextRequest) {
|
||||
})
|
||||
}
|
||||
|
||||
// --- Detect existing files and compare size to classify changes (LFS-compatible) ---
|
||||
// --- Detect existing files and classify changes ---
|
||||
// Models: always re-push (compression changes size, can't compare with LFS remote)
|
||||
// Textures: compare by size (not compressed, reliable)
|
||||
const folderPath = `public/models/${destination}/${folderName}`
|
||||
let remoteFileMap: Map<string, number>
|
||||
|
||||
@@ -97,23 +99,33 @@ export async function POST(req: NextRequest) {
|
||||
|
||||
const isReplace = remoteFileMap.size > 0
|
||||
|
||||
// Classify each file: changed, new, or unchanged
|
||||
const fileChanges = new Map<string, FileChange>()
|
||||
const changedFilesToPush: { path: string; contentBase64: string }[] = []
|
||||
|
||||
for (const f of filesToPush) {
|
||||
const filename = f.path.split('/').pop() ?? ''
|
||||
const localSize = Buffer.from(f.contentBase64, 'base64').length
|
||||
const remoteSize = remoteFileMap.get(filename.toLowerCase())
|
||||
const ext = filename.slice(filename.lastIndexOf('.')).toLowerCase()
|
||||
const isModel = MODEL_EXTENSIONS.has(ext)
|
||||
|
||||
if (remoteSize === undefined) {
|
||||
fileChanges.set(filename.toLowerCase(), 'new')
|
||||
changedFilesToPush.push(f)
|
||||
} else if (remoteSize !== localSize) {
|
||||
fileChanges.set(filename.toLowerCase(), 'changed')
|
||||
if (isModel) {
|
||||
// Model: always re-push since compression makes size comparison unreliable
|
||||
const remoteSize = remoteFileMap.get(filename.toLowerCase())
|
||||
fileChanges.set(filename.toLowerCase(), remoteSize === undefined ? 'new' : 'changed')
|
||||
changedFilesToPush.push(f)
|
||||
} else {
|
||||
fileChanges.set(filename.toLowerCase(), 'unchanged')
|
||||
// Texture: compare by size
|
||||
const localSize = Buffer.from(f.contentBase64, 'base64').length
|
||||
const remoteSize = remoteFileMap.get(filename.toLowerCase())
|
||||
|
||||
if (remoteSize === undefined) {
|
||||
fileChanges.set(filename.toLowerCase(), 'new')
|
||||
changedFilesToPush.push(f)
|
||||
} else if (remoteSize !== localSize) {
|
||||
fileChanges.set(filename.toLowerCase(), 'changed')
|
||||
changedFilesToPush.push(f)
|
||||
} else {
|
||||
fileChanges.set(filename.toLowerCase(), 'unchanged')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user