From 054b54f96d6a107b5f5fde185e3feae786eb05e2 Mon Sep 17 00:00:00 2001 From: Martin Riedel Date: Wed, 21 Jun 2017 21:08:30 +0200 Subject: [PATCH] Fixed httpExporter for multipage diagrams (regression from https://github.com/qjebbs/vscode-plantuml/commit/1043bb159be13e9ec570b5b8b863d1fd21e43de2) --- package.json | 5 +++ src/config.ts | 4 +++ src/httpExporter.ts | 76 +++++++++++++++++++++++++++------------------ 3 files changed, 54 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 59749bf..721d55a 100644 --- a/package.json +++ b/package.json @@ -235,6 +235,11 @@ "default": "http://www.plantuml.com/plantuml", "description": "Plantuml server to generate UML diagrams on-the-fly." }, + "plantuml.urlServerIndexParameter": { + "type": "string", + "default": "", + "description": "Optional index parameter name for multipage diagrams. (e.g. uri?idx=${n})" + }, "plantuml.urlFormat": { "type": "string", "default": "", diff --git a/src/config.ts b/src/config.ts index 3ccdf60..beaf19c 100644 --- a/src/config.ts +++ b/src/config.ts @@ -92,6 +92,10 @@ class ConfigReader { return this._read('urlServer') || "http://www.plantuml.com/plantuml"; } + get urlServerIndexParameter(): string { + return this._read('urlServerIndexParameter'); + } + get urlFormat(): string { return this._read('urlFormat'); } diff --git a/src/httpExporter.ts b/src/httpExporter.ts index 3eb2132..3ab8f9d 100644 --- a/src/httpExporter.ts +++ b/src/httpExporter.ts @@ -1,5 +1,3 @@ -'use strict'; - import * as vscode from 'vscode'; import { Diagram, Diagrams } from './diagram'; @@ -7,7 +5,7 @@ import { config } from './config'; import { urlMaker } from './urlMaker'; import { ExportError, ExportTask } from './exporter'; import { localize } from './planuml'; - +const request = require('request'); class HttpExporter { @@ -23,37 +21,53 @@ class HttpExporter { } private doExport(diagram: Diagram, format: string): ExportTask { - let pURL = urlMaker.makeURL(diagram, config.urlServer, format, null); - var request = require('request'); - // console.log("Exporting preview image from %s", pURL.url); - let pms = new Promise((resolve, reject) => { + let allPms = [...Array(diagram.pageCount).keys()].map( + (index) => { - request( - { method: 'GET' - , uri: pURL.url - , encoding: null // for byte encoding. Otherwise string. - , gzip: true - } - , function (error, response, body) { - if (!error && response.statusCode === 200) { - resolve(body); - } else { - let stderror; - if (!error) { - stderror = "Unexpected Statuscode: " - + response.statusCode + "\n" - + "for GET " + pURL.url; - } else { - stderror = error.message; - body = new Buffer(""); - } - stderror = localize(10, null, diagram.title, stderror); - reject({ error: stderror, out: body }); + let requestUrl = urlMaker.makeURL(diagram, config.urlServer, format, null).url; + if (config.urlServerIndexParameter) { + requestUrl += "?" + config.urlServerIndexParameter + "=" + index; } - }) - }); - return { promise: pms }; + + let pms = new Promise((resolve, reject) => { + + request( + { method: 'GET' + , uri: requestUrl + , encoding: null // for byte encoding. Otherwise string. + , gzip: true + } + , function (error, response, body) { + if (!error && response.statusCode === 200) { + resolve(body); + } else { + let stderror; + if (!error) { + stderror = "Unexpected Statuscode: " + + response.statusCode + "\n" + + "for GET " + requestUrl; + } else { + stderror = error.message; + body = new Buffer(""); + } + stderror = localize(10, null, diagram.title, stderror); + reject({ error: stderror, out: body }); + } + }) + }); + return pms; + + }, + Promise.resolve(new Buffer("")) + ); + + + + return { + processes: null, + promise: Promise.all(allPms), + } } }