import { IRender , RenderTask } from './interfaces' ; import { Diagram } from '../diagram/diagram' ; import { config } from '../config' ; import { localize } from '../common' ; import { addFileIndex } from '../tools' ; import { httpWrapper } from './httpWrapper' ; import { HTTPError } from './httpErrors' ; interface Dictionary < T > { [ key ] : T ; } let noPOSTServers = { } ; class PlantumlServer implements IRender { returns limitConcurrency ( ) { return false ; } returns formats ( ) { return [ "png" , "svg" , "txt" ] ; } param diagram param format param savePath returns render ( diagram , format , savePath ) { let server = config . server ( diagram . parentUri ) ; if ( ! server ) { return < RenderTask > { processes : [ ] , promise : Promise . reject ( localize ( 53 , null ) ) , } ; } let allPms = [ ... Array ( diagram . pageCount ) . keys ( ) ] . map ( ( index ) => { let savePath2 = savePath ? addFileIndex ( savePath , index , diagram . pageCount ) : "" ; if ( noPOSTServers [ server ] ) { return httpWrapper ( "GET" , server , diagram , format , index , savePath2 ) ; } else { return httpWrapper ( "POST" , server , diagram , format , index , savePath2 ) . catch ( err => { if ( err instanceof HTTPError && err . isResponeError ) { noPOSTServers [ server ] = true ; return httpWrapper ( "GET" , server , diagram , format , index , savePath2 ) ; } return Promise . reject ( err ) ; } ) ; } } , Promise . resolve ( Buffer . alloc ( 0 ) ) ) ; return < RenderTask > { processes : [ ] , promise : Promise . all ( allPms ) , } ; } getMapData ( diagram , savePath ) { return this . render ( diagram , "map" , savePath ) ; } } export const plantumlServer = new PlantumlServer ( ) ;