diff --git a/server/job/impl/Cook/JobCookSIGenerateDownloads.ts b/server/job/impl/Cook/JobCookSIGenerateDownloads.ts index d3d1d10e..d5f15f26 100644 --- a/server/job/impl/Cook/JobCookSIGenerateDownloads.ts +++ b/server/job/impl/Cook/JobCookSIGenerateDownloads.ts @@ -1003,61 +1003,62 @@ export class JobCookSIGenerateDownloads extends JobCook { + const found: boolean = incomingFilenames.some(filename => filename.endsWith(suffix)); + if(found===false) + missingIncomingFiles.push(suffix); + }); + if(missingIncomingFiles.length>0) + return this.logError(`JobCookSIGenerateDownloads.verifyIncomingCookData failed to find ${missingIncomingFiles.length} expected files in Cook response (${missingIncomingFiles.join(', ')})`); + + // determine all incoming filenames are consistent + const incomingBaseName: string | null = this.extractBaseName(incomingFilenames); + if(!incomingBaseName) + return this.logError('JobCookSIGenerateDownloads.verifyIncomingCookData incoming filenames are inconsistent.'); - // get assets in Packrat Scene + // get all assets from scene. const sceneAssets: DBAPI.Asset[] | null = await DBAPI.Asset.fetchFromScene(sceneSource.idScene); if(!sceneAssets || sceneAssets.length == 0) return this.logError(`JobCookSIGenerateDownloads.verifyIncomingCookData cannot find any assets for the Packrat scene. (${sceneSource.fetchLogInfo()})`); const sceneAssetFilenames: string[] = sceneAssets.map(asset => asset.FileName); LOG.info(`JobCookSIGenerateDownloads.verifyIncomingCookData\n\t${H.Helpers.JSONStringify(sceneAssetFilenames)}\n\t${H.Helpers.JSONStringify(fileMap)}`,LOG.LS.eDEBUG); - // determine baseName from existing assets in the Packrat scene (error on diff) - const sceneBaseName: string | null = this.extractBaseName(sceneAssets.map(asset => asset.FileName)); - if(!sceneBaseName) - return this.logError(`JobCookSIGenerateDownloads.verifyIncomingCookData cannot extract base name. (${sceneSource.fetchLogInfo()})`); - - // get list of filenames from the incoming fileMap - const incomingAssetFilenames: string[] = [...fileMap.values()]; - - // define expected suffixes to look for in the system - // NOTE: need to update this list if si-generate-downloads returns new/different assets - const suffixes: string[] = ['-150k-4096_std.glb','-100k-2048_std_draco.glb','.svx.json','-100k-2048_std.usdz','-full_resolution-obj_std.zip','-150k-4096-gltf_std.zip','-150k-4096-obj_std.zip']; - const mismatches: string[] = []; - - // cycle through Scene assets comparing with incoming. - // if we have a file with the provided suffix in the Scene then check for a full name match with the incoming map - for(let i=0; i filename.endsWith(suffixes[i])); - if(found) - return this.logError(`CRITICAL: JobCookSIGenerateDownloads.verifyIncomingCookData found an incoming asset (${found}) that doesn't share the scene (id: ${sceneSource.idScene}) base name (${sceneBaseName}).`); - else { - LOG.info(`JobCookSIGenerateDownloads.verifyIncomingCookData didn't find ${filename}. Assuming it's new...`,LOG.LS.eDEBUG); - } - } + // cycle through returned downloads seeing if we have a similar file already in the scene + // if so, then we check to see if they have the same basename. If not, then we fail and the + // scene needs to be rebuilt. + const assetsToReplace: string[] = []; + for(let i=0; i filename.endsWith(s) ); + if(!suffix) + return this.logError(`JobCookSIGenerateDownloads.verifyIncomingCookData couldn't find suffix in verified filenames (${filename})`); + + // find the existing scene asset with the same suffix and check it's basename + const matchingAsset: DBAPI.Asset | undefined = sceneAssets.find(asset => asset.FileName.endsWith(suffix) ); + if(matchingAsset) + if(filename!=matchingAsset.FileName) + return this.logError(`JobCookSIGenerateDownloads.verifyIncomingCookData incoming download (${filename}) has different basename than existing asset (${matchingAsset.FileName})`); + else + assetsToReplace.push(filename); } - // if we have mismatches throw an error and dump out specifics - if(mismatches.length > 0) - return this.logError(`JobCookSIGenerateDownloads.verifyIncomingCookData couldn't find matching assets with '${sceneBaseName}' base name. (${mismatches.length}: ${incomingAssetFilenames.join('|')}`); - - LOG.info(`JobCookSIGenerateDownloads incoming Cook data verified. (${sceneSource.fetchLogInfo()} | baseName: ${sceneBaseName})`,LOG.LS.eJOB); + LOG.info(`JobCookSIGenerateDownloads incoming Cook data verified (${sceneSource.fetchLogInfo()} | new: ${incomingFilenames.length-assetsToReplace.length} | updated: ${assetsToReplace.length})`,LOG.LS.eJOB); return { success: true }; }