@@ -20,6 +20,7 @@ import type {
2020 ProposedSitePath ,
2121 QuitSitesBehavior ,
2222 PullSiteProgress ,
23+ PushImportProgress ,
2324 SelectedSiteFolder ,
2425 SiteDetails ,
2526 Snapshot ,
@@ -65,6 +66,11 @@ type SnapshotSseOutput =
6566 | { kind : 'success' ; operationId : string }
6667 | { kind : 'output' | 'error' ; operationId : string } ;
6768
69+ type PushProgressSseOutput = PushImportProgress & {
70+ siteId : string ;
71+ remoteSiteId : number ;
72+ } ;
73+
6874type PullProgressSseOutput = PullSiteProgress & {
6975 siteId : string ;
7076 remoteSiteId : number ;
@@ -78,6 +84,7 @@ type ServerEvent =
7884 | { channel : 'placement' ; payload : AiSessionPlacementUpdatedEvent }
7985 | { channel : 'snapshot' ; payload : SnapshotSseOutput }
8086 | { channel : 'sync-pull' ; payload : PullProgressSseOutput }
87+ | { channel : 'sync-push' ; payload : PushProgressSseOutput }
8188 | { channel : 'import' ; payload : ImportSseOutput }
8289 | { channel : 'sync-connect' ; payload : { remoteSiteId : number ; studioSiteId : string } } ;
8390
@@ -102,6 +109,7 @@ export function createLocalConnector( { apiBaseUrl }: LocalConnectorOptions ): C
102109 const placementListeners = new Set < ( event : AiSessionPlacementUpdatedEvent ) => void > ( ) ;
103110 const snapshotListeners = new Set < ( output : SnapshotSseOutput ) => void > ( ) ;
104111 const pullProgressListeners = new Set < ( output : PullProgressSseOutput ) => void > ( ) ;
112+ const pushProgressListeners = new Set < ( output : PushProgressSseOutput ) => void > ( ) ;
105113 const importListeners = new Set < ( output : ImportSseOutput ) => void > ( ) ;
106114 const syncConnectListeners = new Set <
107115 ( event : { remoteSiteId : number ; studioSiteId : string } ) => void
@@ -226,6 +234,8 @@ export function createLocalConnector( { apiBaseUrl }: LocalConnectorOptions ): C
226234 snapshotListeners . forEach ( ( listener ) => listener ( parsed . payload ) ) ;
227235 } else if ( parsed . channel === 'sync-pull' ) {
228236 pullProgressListeners . forEach ( ( listener ) => listener ( parsed . payload ) ) ;
237+ } else if ( parsed . channel === 'sync-push' ) {
238+ pushProgressListeners . forEach ( ( listener ) => listener ( parsed . payload ) ) ;
229239 } else if ( parsed . channel === 'import' ) {
230240 importListeners . forEach ( ( listener ) => listener ( parsed . payload ) ) ;
231241 } else if ( parsed . channel === 'sync-connect' ) {
@@ -573,11 +583,23 @@ export function createLocalConnector( { apiBaseUrl }: LocalConnectorOptions ): C
573583 method : 'POST' ,
574584 } ) ;
575585 } ,
576- async pushSiteToLive ( siteId , remoteSiteId , options ) {
577- await api ( `/sites/${ encodeURIComponent ( siteId ) } /push` , {
578- method : 'POST' ,
579- body : JSON . stringify ( { remoteSiteId, options } ) ,
580- } ) ;
586+ async pushSiteToLive ( siteId , remoteSiteId , options , onImportProgress ) {
587+ const listener = ( output : PushProgressSseOutput ) => {
588+ if ( output . siteId === siteId ) {
589+ onImportProgress ?.( { status : output . status , progress : output . progress } ) ;
590+ }
591+ } ;
592+ if ( onImportProgress ) {
593+ pushProgressListeners . add ( listener ) ;
594+ }
595+ try {
596+ await api ( `/sites/${ encodeURIComponent ( siteId ) } /push` , {
597+ method : 'POST' ,
598+ body : JSON . stringify ( { remoteSiteId, options } ) ,
599+ } ) ;
600+ } finally {
601+ pushProgressListeners . delete ( listener ) ;
602+ }
581603 } ,
582604 async pullSiteFromLive ( siteId , remoteSiteId , onProgress , options ) {
583605 const listener = ( output : PullProgressSseOutput ) => {
0 commit comments