@@ -7,30 +7,51 @@ var fs = require('fs'),
7
7
request = require ( 'request' ) ;
8
8
9
9
exports . generatePng = function ( req , res ) {
10
- console . log ( "Trying to generate an UML image." )
10
+ generate ( res , req , false )
11
+ //request('http://www.plantuml.com/plantuml/img/'+encoded).pipe(res);
12
+ } ;
11
13
12
- plantuml . useNailgun ( ) ;
13
- entities = new Entities ( ) ;
14
- res . set ( 'Content-Type' , 'image/png' ) ;
15
- var text = req . body . text ;
16
- console . log ( "body " + req . body . text ) ;
17
- console . log ( "params " + req . params . text ) ;
18
- splited = text . split ( "```" ) ;
19
- if ( splited . length > 1 ) {
20
- code = splited [ 1 ] ;
21
- if ( code . includes ( "@startuml" ) ) {
22
- console . log ( entities . decode ( code ) ) ;
23
- var encoded = plantumlEncoder . encode ( entities . decode ( code ) ) ;
24
- console . log ( 'http://www.plantuml.com/plantuml/img/' + encoded ) ;
25
- res . status ( 200 ) . jsonp ( { text : 'http://www.plantuml.com/plantuml/img/' + encoded } )
14
+ exports . generatePng = function ( req , res ) {
15
+ generate ( res , req , true )
16
+ //request('http://www.plantuml.com/plantuml/img/'+encoded).pipe(res);
17
+ } ;
18
+
19
+ function generate ( res , req , command ) {
20
+ console . log ( "Trying to generate an UML image." )
21
+
22
+ plantuml . useNailgun ( ) ;
23
+ entities = new Entities ( ) ;
24
+ res . set ( 'Content-Type' , 'image/png' ) ;
25
+ var text = req . body . text ;
26
+ console . log ( "body " + req . body . text ) ;
27
+ console . log ( "params " + req . params . text ) ;
28
+ splited = text . split ( "```" ) ;
29
+ if ( splited . length > 1 ) {
30
+ code = splited [ 1 ] ;
31
+ if ( code . includes ( "@startuml" ) ) {
32
+ console . log ( entities . decode ( code ) ) ;
33
+ var encoded = plantumlEncoder . encode ( entities . decode ( code ) ) ;
34
+ console . log ( 'http://www.plantuml.com/plantuml/img/' + encoded ) ;
35
+ if ( command ) {
36
+ res . status ( 200 ) . jsonp ( { text :
37
+ attachments : [
38
+ {
39
+ text : "Optional text that appears within the attachment" ,
40
+ image_url : "http://www.plantuml.com/plantuml/img/" + encoded ,
41
+ footer : "Generated UML"
42
+ }
43
+ ]
44
+ } ) ;
26
45
} else {
27
- res . status ( 200 ) . jsonp ( { } ) ;
46
+ res . status ( 200 ) . jsonp ( { text : 'http://www.plantuml.com/plantuml/img/' + encoded } )
28
47
}
29
48
} else {
30
49
res . status ( 200 ) . jsonp ( { } ) ;
31
50
}
32
- //request('http://www.plantuml.com/plantuml/img/'+encoded).pipe(res);
33
- } ;
51
+ } else {
52
+ res . status ( 200 ) . jsonp ( { } ) ;
53
+ }
54
+ }
34
55
35
56
exports . generateSvg = function ( req , res ) {
36
57
plantuml . useNailgun ( ) ;
0 commit comments