From 3ab3e93a2865514420e7851a045256085620a0ca Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Mon, 5 Mar 2018 18:01:12 -0500 Subject: [PATCH] Upload debug logs to debuglogs.org --- js/logging.js | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/js/logging.js b/js/logging.js index d1961226f..6fedabc0c 100644 --- a/js/logging.js +++ b/js/logging.js @@ -2,12 +2,10 @@ /* eslint strict: ['error', 'never'] */ -/* global $: false */ -/* global textsecure: false */ - const electron = require('electron'); const bunyan = require('bunyan'); const _ = require('lodash'); +const superagent = require('superagent'); const ipc = electron.ipcRenderer; @@ -110,27 +108,25 @@ function fetch() { }); } -function publish(rawContent) { - const content = rawContent || fetch(); - - return new Promise((resolve) => { - const payload = textsecure.utils.jsonThing({ - files: { - 'debugLog.txt': { - content, - }, - }, - }); +const DEBUGLOGS_API_URL = 'https://debuglogs.org'; +const publish = async (content) => { + const credentialsResponse = await superagent.get(DEBUGLOGS_API_URL); + const { fields, url } = credentialsResponse.body; + const uploadRequest = superagent.post(url); + Object.entries(fields).forEach(([key, value]) => { + uploadRequest.field(key, value); + }); - // eslint-disable-next-line more/no-then - $.post('https://api.github.com/gists', payload) - .then((response) => { - console._log('Posted debug log to ', response.html_url); - resolve(response.html_url); - }) - .fail(resolve); + const contentBuffer = Buffer.from(content, 'utf8'); + uploadRequest.attach('file', contentBuffer, { + contentType: 'text/plain', + filename: 'signal-desktop-debug-log.txt', }); -} + + await uploadRequest; + + return `${DEBUGLOGS_API_URL}/${fields.key}`; +}; // A modern logging interface for the browser