Skip to content

Commit 4031324

Browse files
committed
clean up file-related code that's not required anymore
1 parent beaf94e commit 4031324

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

export-server/server.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const http = require('http');
2323
const path = require('path');
2424
const ssr = require('./ssr.js');
2525
const url = require('url');
26-
const { v4: uuidv4 } = require('uuid');
2726

2827
// Use hostname from environment variable HOST, if it is set.
2928
const hostname = process.env.HOST || 'localhost';
@@ -119,9 +118,8 @@ const server = http.createServer(function(req, res) {
119118
if (killed) {
120119
return;
121120
}
122-
// Render file with JSDOM.
123-
const filename = 'graph-' + uuidv4() + '.svg';
124-
const result = await ssr.render(body, filename, req.headers["x-image-width"], req.headers["x-image-height"]);
121+
// Render image with JSDOM.
122+
const result = await ssr.render(body, req.headers["x-image-width"], req.headers["x-image-height"]);
125123
if (result.success) {
126124
res.statusCode = 200; // 200 == OK
127125
res.setHeader('Content-Type', 'image/svg+xml');

export-server/ssr.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@
1818

1919
var fs = require('fs');
2020
const jsdom = require('jsdom');
21-
const { v4: uuidv4 } = require('uuid');
2221

2322
/* Renders JSON data for a Plotly.js plot into a SVG file.
2423
2524
Parameters:
2625
jsonData - (string) the JSON data required by Plotly.js
27-
filename - (string) desired output file name for the SVG file
28-
width - (number) width of the SVG file in pixels
29-
height - (number) height of the SVG file in pixels
26+
width - (number) width of the SVG image in pixels
27+
height - (number) height of the SVG image in pixels
3028
3129
Returns:
3230
object that contains two members:
@@ -35,24 +33,13 @@ const { v4: uuidv4 } = require('uuid');
3533
failure - (string) reason for render failure; only present after failed
3634
rendering, may be cryptic and is not necessarily human-friendly
3735
*/
38-
exports.render = async function(jsonData, filename, width, height) {
39-
const unique_id = uuidv4();
40-
41-
if (!filename) {
42-
filename = 'graph-' + unique_id + '.svg';
43-
}
36+
exports.render = async function(jsonData, width, height) {
4437
if (typeof jsonData !== 'string') {
4538
return {
4639
success: false,
4740
failure: 'json-not-a-string'
4841
};
4942
}
50-
if (typeof filename !== 'string') {
51-
return {
52-
success: false,
53-
failure: 'filename-not-a-string'
54-
};
55-
}
5643

5744
const parsed_width = parseInt(width, 10);
5845
if (isNaN(parsed_width) || parsed_width <= 0) {

0 commit comments

Comments
 (0)