Upload debug logs to debuglogs.org

This commit is contained in:
Daniel Gasienica 2018-03-05 18:01:12 -05:00
parent bd5f3bd73a
commit 3ab3e93a28

View file

@ -2,12 +2,10 @@
/* eslint strict: ['error', 'never'] */ /* eslint strict: ['error', 'never'] */
/* global $: false */
/* global textsecure: false */
const electron = require('electron'); const electron = require('electron');
const bunyan = require('bunyan'); const bunyan = require('bunyan');
const _ = require('lodash'); const _ = require('lodash');
const superagent = require('superagent');
const ipc = electron.ipcRenderer; const ipc = electron.ipcRenderer;
@ -110,27 +108,25 @@ function fetch() {
}); });
} }
function publish(rawContent) { const DEBUGLOGS_API_URL = 'https://debuglogs.org';
const content = rawContent || fetch(); const publish = async (content) => {
const credentialsResponse = await superagent.get(DEBUGLOGS_API_URL);
return new Promise((resolve) => { const { fields, url } = credentialsResponse.body;
const payload = textsecure.utils.jsonThing({ const uploadRequest = superagent.post(url);
files: { Object.entries(fields).forEach(([key, value]) => {
'debugLog.txt': { uploadRequest.field(key, value);
content,
},
},
});
// 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 // A modern logging interface for the browser