Skip to content

Commit 29aae90

Browse files
Port updated
1 parent 95520a0 commit 29aae90

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

controllers/plantuml.js

+39-18
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,51 @@ var fs = require('fs'),
77
request = require('request');
88

99
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+
};
1113

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+
});
2645
} else {
27-
res.status(200).jsonp({});
46+
res.status(200).jsonp({text: 'http://www.plantuml.com/plantuml/img/'+encoded})
2847
}
2948
} else {
3049
res.status(200).jsonp({});
3150
}
32-
//request('http://www.plantuml.com/plantuml/img/'+encoded).pipe(res);
33-
};
51+
} else {
52+
res.status(200).jsonp({});
53+
}
54+
}
3455

3556
exports.generateSvg = function(req, res) {
3657
plantuml.useNailgun();

routes/all.js

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ exports.getRoutes = function(){
88
routes.route('/png')
99
.post(PlantCtrl.generatePng);
1010

11+
routes.route('/commands/png')
12+
.post(PlantCtrl.generateCommandPng);
13+
1114
routes.route('/svg')
1215
.post(PlantCtrl.generateSvg);
1316

0 commit comments

Comments
 (0)