11import firebase from 'firebase/app' ;
22
33async function syncDiagram ( currentItem ) {
4- const { id, title, js, imageBase64 } = currentItem ;
5- if ( ! js || ! title || ! imageBase64 ) {
6- console . warn ( 'Cannot sync diagram because of missing data' ) ;
7- return null ;
8- }
4+ const { id, title, js, imageBase64 } = currentItem ;
5+ if ( ! js || ! title || ! imageBase64 ) {
6+ throw Error ( 'Cannot sync diagram because of missing data' ) ;
7+ }
98
10- const token = await firebase . auth ( ) . currentUser . getIdToken ( true ) ;
9+ const token = await firebase . auth ( ) . currentUser . getIdToken ( true ) ;
1110
12- const data = {
13- token,
14- id,
15- imageBase64,
16- name : title ,
17- content : js ,
18- description : 'Shared diagram from https://app.zenuml.com' ,
19- } ;
20- console . log ( 'calling /sync-diagram with data:' , data )
21- try {
22- const response = await fetch ( '/sync-diagram' , {
23- method : 'POST' ,
24- body : JSON . stringify ( data ) ,
25- headers : { 'Content-Type' : 'application/json' } ,
26- } ) ;
27- const result = await response . json ( ) ;
28- console . log ( 'save to php app result: ' , result )
29- return result ;
30- } catch ( error ) {
31- console . warn ( 'Error when calling /sync-diagram' , error ) ;
32- return null ;
33- }
11+ const data = {
12+ token,
13+ id,
14+ imageBase64,
15+ name : title ,
16+ content : js ,
17+ description : 'Shared diagram from https://app.zenuml.com' ,
18+ } ;
19+ console . log ( 'calling /sync-diagram with data:' , data )
20+ try {
21+ const response = await fetch ( '/sync-diagram' , {
22+ method : 'POST' ,
23+ body : JSON . stringify ( data ) ,
24+ headers : { 'Content-Type' : 'application/json' } ,
25+ } ) ;
26+ const result = await response . json ( ) ;
27+ console . log ( 'save to php app result: ' , result )
28+ return result ;
29+ } catch ( error ) {
30+ console . warn ( 'Error when calling /sync-diagram' , error ) ;
31+ throw Error ( 'Error when calling /sync-diagram' ) ;
32+ }
3433}
3534
3635function getShareLink ( syncResult ) {
37- return `${ syncResult . page_share } ?v=${ syncResult . md5 } ` ;
36+ return `${ syncResult . page_share } ?v=${ syncResult . md5 } ` ;
3837}
3938
40- export { syncDiagram , getShareLink } ;
39+ export { syncDiagram , getShareLink } ;
0 commit comments