Use hash instead of UUID

This commit is contained in:
RMidhunSuresh 2022-04-12 20:15:14 +05:30
parent 36782fb4fe
commit 25a8521efc

View file

@ -16,7 +16,14 @@ limitations under the License.
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
const {randomUUID} = require('crypto'); const xxhash = require('xxhashjs');
function createHash(content) {
const hasher = new xxhash.h32(0);
hasher.update(content);
return hasher.digest();
}
/** /**
* Builds a new svg with the colors replaced and returns its location. * Builds a new svg with the colors replaced and returns its location.
* @param {string} svgLocation The location of the input svg file * @param {string} svgLocation The location of the input svg file
@ -31,8 +38,7 @@ module.exports.buildColorizedSVG = function (svgLocation, primaryColor, secondar
throw new Error("svg-colorizer made no color replacements! The input svg should only contain colors #ff00ff (primary, case-sensitive) and #00ffff (secondary, case-sensitive)."); throw new Error("svg-colorizer made no color replacements! The input svg should only contain colors #ff00ff (primary, case-sensitive) and #00ffff (secondary, case-sensitive).");
} }
const fileName = svgLocation.match(/.+\/(.+\.svg)/)[1]; const fileName = svgLocation.match(/.+\/(.+\.svg)/)[1];
// give unique names so that this svg does not replace other versions of the same svg const outputName = `${fileName.substring(0, fileName.length - 4)}-${createHash(coloredSVGCode)}.svg`;
const outputName = `${fileName.substring(0, fileName.length - 4)}-${randomUUID()}.svg`;
const outputPath = path.resolve(__dirname, "../../.tmp"); const outputPath = path.resolve(__dirname, "../../.tmp");
try { try {
fs.mkdirSync(outputPath); fs.mkdirSync(outputPath);