Skip to content

Commit d8a2070

Browse files
committed
use UUIDs instead of millisecond timestamp for file name
1 parent 08c1c75 commit d8a2070

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

export-server/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"author": "Dirk Stolle <striezel-dev@web.de>",
2222
"license": "GPL-3.0",
2323
"dependencies": {
24-
"phantomjs-prebuilt": "^2.1.16"
24+
"phantomjs-prebuilt": "^2.1.16",
25+
"uuid": "^3.4.0"
2526
}
2627
}

export-server/phantomize.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Plotly.js offline image export server with Node.js
3-
Copyright (C) 2018 Dirk Stolle
3+
Copyright (C) 2018, 2021 Dirk Stolle
44
55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -21,7 +21,7 @@
2121
var child_process = require('child_process');
2222
var fs = require('fs');
2323
const paths = require('./paths.js');
24-
24+
const uuidv4 = require('uuid/v4');
2525

2626
/* Renders JSON data for a Plotly.js plot into a PNG file.
2727
@@ -38,8 +38,10 @@ const paths = require('./paths.js');
3838
rendering, may be cryptic and is not necessarily human-friendly
3939
*/
4040
exports.render = function(jsonData, filename) {
41+
const unique_id = uuidv4();
42+
4143
if (!filename) {
42-
filename = 'phantom-render-' + Date.now() + '.png';
44+
filename = 'phantom-render-' + unique_id + '.png';
4345
}
4446
if (typeof jsonData !== 'string') {
4547
return {
@@ -54,7 +56,7 @@ exports.render = function(jsonData, filename) {
5456
};
5557
}
5658

57-
const plotDataFile = 'plot-data-' + Date.now() + '.json';
59+
const plotDataFile = 'plot-data-' + unique_id + '.json';
5860
fs.writeFileSync(plotDataFile, jsonData, {mode: 0o644, flag: 'w'});
5961

6062
console.log("Starting PhantomJS ...\n(This might take one or two seconds.)");

export-server/server.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Plotly.js offline image export server with Node.js
3-
Copyright (C) 2018, 2020 Dirk Stolle
3+
Copyright (C) 2018, 2020, 2021 Dirk Stolle
44
55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -24,6 +24,7 @@ const path = require('path');
2424
const paths = require('./paths.js');
2525
const phantomize = require('./phantomize.js');
2626
const url = require('url');
27+
const uuidv4 = require('uuid/v4');
2728

2829
const hostname = 'localhost';
2930
const port = 3000;
@@ -178,7 +179,7 @@ const server = http.createServer(function(req, res) {
178179
return;
179180
}
180181
// Render file with PhantomJS.
181-
const filename = 'graph-' + Date.now() + '.png';
182+
const filename = 'graph-' + uuidv4() + '.png';
182183
const result = phantomize.render(body, filename);
183184
if (result.success) {
184185
res.statusCode = 200; // 200 == OK

0 commit comments

Comments
 (0)