-
-
Save juananpe/b9730a04bc76ad54604f9a7ac657cc36 to your computer and use it in GitHub Desktop.
parsing a HAR file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const contents = fs.readFileSync("/tmp/discordapp.com.har"); | |
const jsonContent = JSON.parse(contents); | |
let mensajes = {}; | |
jsonContent.log.entries.forEach(entry => { | |
if (entry.request.method == "POST") { | |
if (entry.request.postData && entry.request.postData.text.includes("content")) { | |
let id = JSON.parse(entry.response.content.text).id; | |
let text = JSON.parse(entry.request.postData.text).content; | |
mensajes[id] = text; | |
} | |
} else if (entry.request.method == "PATCH" || entry.request.method == "DELETE") { | |
let id = entry.request.url.split("messages/")[1]; | |
let text = entry.request.postData? JSON.parse(entry.request.postData.text).content : ""; | |
mensajes[id] = text; | |
}}); | |
console.log(Object.keys(mensajes).map( key => mensajes[key]).join("")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment