@@ -24,7 +24,6 @@ type AssetRecord = {
2424 parent_uid ?: string ;
2525 title ?: string ;
2626 description ?: string ;
27- locale ?: string ;
2827} ;
2928
3029type UploadJob = {
@@ -195,10 +194,6 @@ export default class ImportAssets extends CSAssetsImportAdapter {
195194 let uploadFail = 0 ;
196195 let missingFiles = 0 ;
197196
198- // Master uid (old → new). The first locale seen for a uid creates the asset; later locales of the
199- // same uid are localized onto that new uid so multi-locale assets keep one asset with per-locale files.
200- const uidToNewUid = new Map < string , string > ( ) ;
201-
202197 await forEachChunkRecordsFromFs < AssetRecord > (
203198 assetFs ,
204199 {
@@ -219,10 +214,7 @@ export default class ImportAssets extends CSAssetsImportAdapter {
219214 for ( const asset of assetChunk ) {
220215 const oldUid = asset . uid ;
221216 const filename = asset . filename ?? asset . file_name ?? 'asset' ;
222- // Locale-scoped path mirrors the export layout (files/<uid>/<locale>/<filename>).
223- const filePath = asset . locale
224- ? pResolve ( assetsDir , 'files' , oldUid , asset . locale , filename )
225- : pResolve ( assetsDir , 'files' , oldUid , filename ) ;
217+ const filePath = pResolve ( assetsDir , 'files' , oldUid , filename ) ;
226218
227219 if ( ! existsSync ( filePath ) ) {
228220 missingFiles += 1 ;
@@ -243,62 +235,22 @@ export default class ImportAssets extends CSAssetsImportAdapter {
243235 this . importContext . context ,
244236 ) ;
245237
246- // Group by old uid so a uid's locales upload as master-then-localize (sequential within a
247- // group); different uids still upload concurrently.
248- const jobsByUid = new Map < string , UploadJob [ ] > ( ) ;
249- for ( const job of uploadJobs ) {
250- const group = jobsByUid . get ( job . oldUid ) ;
251- if ( group ) group . push ( job ) ;
252- else jobsByUid . set ( job . oldUid , [ job ] ) ;
253- }
254-
255- await runInBatches ( [ ...jobsByUid . values ( ) ] , this . uploadAssetsBatchConcurrency , async ( group ) => {
256- // If the master row's create fails, its remaining locales can't be localized — skip them.
257- let masterFailed = false ;
258- for ( const { asset, filePath, mappedParentUid, oldUid } of group ) {
238+ await runInBatches (
239+ uploadJobs ,
240+ this . uploadAssetsBatchConcurrency ,
241+ async ( { asset, filePath, mappedParentUid, oldUid } ) => {
259242 const filename = asset . filename ?? asset . file_name ?? 'asset' ;
260- const masterNewUid = uidToNewUid . get ( oldUid ) ;
261- // Master (first row for this uid) failed earlier → can't localize onto it; skip its locales.
262- if ( ! masterNewUid && masterFailed ) {
263- uploadFail += 1 ;
264- this . tick ( false , `asset: ${ filename } ` , 'Skipped: master asset upload failed' ) ;
265- log . error (
266- `Skipped locale ${ asset . locale ?? 'n/a' } of asset ${ oldUid } — master upload failed` ,
267- this . importContext . context ,
268- ) ;
269- continue ;
270- }
271243 try {
272- if ( ! masterNewUid ) {
273- // First locale for this uid → create the asset.
274- const { asset : created } = await this . uploadAsset ( newSpaceUid , filePath , {
275- title : asset . title ?? filename ,
276- description : asset . description ,
277- parent_uid : mappedParentUid ,
278- } ) ;
279- uidToNewUid . set ( oldUid , created . uid ) ;
280- uidMap [ oldUid ] = created . uid ;
281- if ( asset . url && created . url ) urlMap [ asset . url ] = created . url ;
282- this . tick ( true , `asset: ${ filename } ` , null ) ;
283- uploadOk += 1 ;
284- log . debug ( `Uploaded asset ${ oldUid } → ${ created . uid } (${ filePath } )` , this . importContext . context ) ;
285- } else {
286- // Additional locale → localize onto the asset created from the master row.
287- const { asset : localized } = await this . localizeAsset (
288- newSpaceUid ,
289- masterNewUid ,
290- asset . locale as string ,
291- filePath ,
292- { title : asset . title ?? filename , description : asset . description , parent_uid : mappedParentUid } ,
293- ) ;
294- if ( asset . url && localized . url ) urlMap [ asset . url ] = localized . url ;
295- this . tick ( true , `asset: ${ filename } (${ asset . locale } )` , null ) ;
296- uploadOk += 1 ;
297- log . debug (
298- `Localized asset ${ oldUid } → ${ masterNewUid } for locale ${ asset . locale } (${ filePath } )` ,
299- this . importContext . context ,
300- ) ;
301- }
244+ const { asset : created } = await this . uploadAsset ( newSpaceUid , filePath , {
245+ title : asset . title ?? filename ,
246+ description : asset . description ,
247+ parent_uid : mappedParentUid ,
248+ } ) ;
249+ uidMap [ oldUid ] = created . uid ;
250+ if ( asset . url && created . url ) urlMap [ asset . url ] = created . url ;
251+ this . tick ( true , `asset: ${ filename } ` , null ) ;
252+ uploadOk += 1 ;
253+ log . debug ( `Uploaded asset ${ oldUid } → ${ created . uid } (${ filePath } )` , this . importContext . context ) ;
302254 } catch ( e ) {
303255 uploadFail += 1 ;
304256 this . tick (
@@ -307,19 +259,12 @@ export default class ImportAssets extends CSAssetsImportAdapter {
307259 ( e as Error ) ?. message ?? PROCESS_STATUS [ PROCESS_NAMES . AM_IMPORT_ASSETS ] . FAILED ,
308260 ) ;
309261 log . error (
310- `${
311- masterNewUid
312- ? `Failed to localize asset ${ oldUid } for locale ${ asset . locale } `
313- : `Failed to upload asset ${ oldUid } `
314- } : ${ ( e as Error ) ?. message ?? String ( e ) } `,
262+ `Failed to upload asset ${ oldUid } : ${ ( e as Error ) ?. message ?? String ( e ) } ` ,
315263 this . importContext . context ,
316264 ) ;
317- // Master create failed → skip this uid's remaining locale rows instead of re-attempting
318- // them as new masters (which would duplicate the asset with the wrong default locale).
319- if ( ! masterNewUid ) masterFailed = true ;
320265 }
321- }
322- } ) ;
266+ } ,
267+ ) ;
323268 } ,
324269 ) ;
325270
0 commit comments