From 5bdb2aae384af5a9cb49d59d34eb9dc61f293873 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Tue, 11 Jun 2024 15:14:26 -0600 Subject: [PATCH] Remove json2csv --- index.js | 14 ++++++++++++-- package-lock.json | 20 -------------------- package.json | 1 - 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/index.js b/index.js index 8fe4cdd..7dbae24 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,6 @@ const embeds = require("./embeds.json") const axios = require('axios'); const ping = require("ping") var commandsBase = require("./commands.json") -const json2csv = require("json2csv"); const ssh2 = require('ssh2') const sshConn = new ssh2.Client(); // find first file in .ssh local to the script @@ -46,6 +45,15 @@ const mariadb = require('mariadb'); const pool = mariadb.createPool(config.mariadb); const cdrPool = mariadb.createPool(config.cdrdb); + +const json2csv = (obj) => { + let csv = ""; + for (let key in obj) { + csv += `${key},${obj[key]}\n`; + } + return csv; +} + // Some functions for FreePBX @@ -1324,7 +1332,9 @@ dcClient.on('interactionCreate', async interaction => { } else { // Generate the CSV const fields = ["calldate", "src", "dst", "duration", "disposition", "recordingfile"]; - const csv = json2csv.parse(result); + // put fields at the top of the csv + result.unshift(fields); + const csv = json2csv(result); const buffer = Buffer.from(csv, 'utf-8'); const attachment = new MessageAttachment(buffer, 'cdr.csv'); interaction.editReply({ diff --git a/package-lock.json b/package-lock.json index ea24f8d..de567f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,6 @@ "colors": "^1.4.0", "discord.js": "^14.7.1", "freepbx-graphql-client": "^0.1.1", - "json2csv": "github:juanjoDiaz/json2csv", "mariadb": "^3.2.0", "ping": "^0.4.4", "sqlite3": "^5.1.4", @@ -829,25 +828,6 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "optional": true }, - "node_modules/json2csv": { - "version": "7.0.6", - "resolved": "git+ssh://git@github.com/juanjoDiaz/json2csv.git#8c7895c11321410968893519fe86a60d98269ed0", - "license": "MIT", - "workspaces": [ - "packages/cli", - "packages/formatters", - "packages/node", - "packages/plainjs", - "packages/test-helpers", - "packages/transforms", - "packages/whatwg", - "packages/test-performance" - ], - "engines": { - "node": ">=14.17.0", - "npm": ">=7.0.0" - } - }, "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", diff --git a/package.json b/package.json index fa7bf75..715f7af 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,6 @@ "colors": "^1.4.0", "discord.js": "^14.7.1", "freepbx-graphql-client": "^0.1.1", - "json2csv": "github:juanjoDiaz/json2csv", "mariadb": "^3.2.0", "ping": "^0.4.4", "sqlite3": "^5.1.4",