@@ -350,6 +350,8 @@ export async function* commitIter(params: CommitParams): AsyncGenerator<CommitPr
350350 if ( useXet && json . transfer !== "xet" ) {
351351 useXet = false ;
352352 }
353+ let xetRefreshWriteTokenUrl : string | undefined ;
354+ let xetSessionId : string | undefined ;
353355
354356 if ( useXet ) {
355357 // First get all the files that are already uploaded out of the way
@@ -374,6 +376,17 @@ export async function* commitIter(params: CommitParams): AsyncGenerator<CommitPr
374376 progress : 1 ,
375377 state : "uploading" ,
376378 } ;
379+ } else {
380+ xetRefreshWriteTokenUrl = obj . actions . upload . href ;
381+ // Also, obj.actions.upload.header: {
382+ // X-Xet-Cas-Url: string;
383+ // X-Xet-Access-Token: string;
384+ // X-Xet-Token-Expiration: string;
385+ // X-Xet-Session-Id: string;
386+ // }
387+ const headers = new Headers ( obj . actions . upload . header ) ;
388+ xetSessionId = headers . get ( "X-Xet-Session-Id" ) ?? undefined ;
389+ // todo: use other data, like x-xet-cas-url, ...
377390 }
378391 }
379392 const source = ( async function * ( ) {
@@ -383,44 +396,49 @@ export async function* commitIter(params: CommitParams): AsyncGenerator<CommitPr
383396 continue ;
384397 }
385398 abortSignal ?. throwIfAborted ( ) ;
386-
387- // todo: load writeTokenUrl from obj.actions.upload.header or obj.actions.upload.href
388399 yield { content : op . content , path : op . path , sha256 : obj . oid } ;
389400 }
390401 } ) ( ) ;
391- const sources = splitAsyncGenerator ( source , 5 ) ;
392- yield * eventToGenerator ( ( yieldCallback , returnCallback , rejectCallback ) =>
393- Promise . all (
394- sources . map ( async function ( source ) {
395- for await ( const event of uploadShards ( source , {
396- fetch : params . fetch ,
397- accessToken,
398- hubUrl : params . hubUrl ?? HUB_URL ,
399- repo : repoId ,
400- // todo: maybe leave empty if PR?
401- rev : params . branch ?? "main" ,
402- isPullRequest : params . isPullRequest ,
403- yieldCallback : ( event ) => yieldCallback ( { ...event , state : "uploading" } ) ,
404- } ) ) {
405- if ( event . event === "file" ) {
406- yieldCallback ( {
407- event : "fileProgress" as const ,
408- path : event . path ,
409- progress : 1 ,
410- state : "uploading" as const ,
411- } ) ;
412- } else if ( event . event === "fileProgress" ) {
413- yieldCallback ( {
414- event : "fileProgress" as const ,
415- path : event . path ,
416- progress : event . progress ,
417- state : "uploading" as const ,
418- } ) ;
402+ if ( xetRefreshWriteTokenUrl ) {
403+ const xetRefreshWriteTokenUrlFixed = xetRefreshWriteTokenUrl ;
404+ const sources = splitAsyncGenerator ( source , 5 ) ;
405+ yield * eventToGenerator ( ( yieldCallback , returnCallback , rejectCallback ) =>
406+ Promise . all (
407+ sources . map ( async function ( source ) {
408+ for await ( const event of uploadShards ( source , {
409+ fetch : params . fetch ,
410+ accessToken,
411+ hubUrl : params . hubUrl ?? HUB_URL ,
412+ repo : repoId ,
413+ xetRefreshWriteTokenUrl : xetRefreshWriteTokenUrlFixed ,
414+ xetSessionId,
415+ // todo: maybe leave empty if PR?
416+ rev : params . branch ?? "main" ,
417+ isPullRequest : params . isPullRequest ,
418+ yieldCallback : ( event ) => yieldCallback ( { ...event , state : "uploading" } ) ,
419+ } ) ) {
420+ if ( event . event === "file" ) {
421+ yieldCallback ( {
422+ event : "fileProgress" as const ,
423+ path : event . path ,
424+ progress : 1 ,
425+ state : "uploading" as const ,
426+ } ) ;
427+ } else if ( event . event === "fileProgress" ) {
428+ yieldCallback ( {
429+ event : "fileProgress" as const ,
430+ path : event . path ,
431+ progress : event . progress ,
432+ state : "uploading" as const ,
433+ } ) ;
434+ }
419435 }
420- }
421- } )
422- ) . then ( ( ) => returnCallback ( undefined ) , rejectCallback )
423- ) ;
436+ } )
437+ ) . then ( ( ) => returnCallback ( undefined ) , rejectCallback )
438+ ) ;
439+ } else {
440+ // No LFS file to upload
441+ }
424442 } else {
425443 yield * eventToGenerator < CommitProgressEvent , void > ( ( yieldCallback , returnCallback , rejectCallback ) => {
426444 return promisesQueueStreaming (
0 commit comments