Skip to content

Commit

Permalink
base64 encode data in template
Browse files Browse the repository at this point in the history
  • Loading branch information
hfxbse committed May 14, 2024
1 parent ba32de6 commit 421b92c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {readFileSync} from "fs";
async function writeGraphToFile(filename: string, graph: UserGraph) {
try {
writeFileSync(filename, JSON.stringify(graph, null, 2))
console.log(`Wrote graph into ${filename}.json.`)
console.log(`Wrote graph into ${filename}.`)
} catch (error) {
console.error({message: `Cannot write graph into ${filename}.json. Using stdout instead.`, error})
console.error({message: `Cannot write graph into ${filename}. Using stdout instead.`, error})
await new Promise(resolve => setTimeout(() => {
console.log(JSON.stringify(graph));
resolve(undefined);
Expand All @@ -37,10 +37,10 @@ async function generateVisualization({template, output, graph, title}: {

const result = readFileSync(template, {encoding: 'utf-8'})
.replace('REPLACE-ME-WITH-TITLE', title)
.replace('REPLACE-ME-WITH-USER-GRAPH', graph.replace(/"/g, '\\\"'));
.replace('REPLACE-ME-WITH-USER-GRAPH', btoa(encodeURIComponent(graph)));

writeFileSync(output, result)
console.log(`Created visualization for graph in ${output}.html.`)
console.log(`Created visualization for graph in ${output}.`)
}


Expand Down
2 changes: 1 addition & 1 deletion src/visualization/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ customElements.define('graph-toolbar', GraphToolbar)


window.addEventListener("DOMContentLoaded", () => {
const data = "REPLACE-ME-WITH-USER-GRAPH"
const data = decodeURIComponent(atob("REPLACE-ME-WITH-USER-GRAPH"))
const graph: UserGraph = JSON.parse(data)

const visualization = document.querySelector("user-graph") as UserGraphVisualization;
Expand Down

0 comments on commit 421b92c

Please sign in to comment.