Update the user agent for debug log requests

This commit is contained in:
Scott Nonnenberg 2018-07-18 20:00:10 -07:00
parent c517e4193b
commit b159a8d7c7
4 changed files with 14 additions and 22 deletions

View file

@ -1,9 +1,12 @@
/* eslint-env node */
/* global window */
const FormData = require('form-data');
const got = require('got');
const BASE_URL = 'https://debuglogs.org';
const VERSION = window.getVersion();
const USER_AGENT = `Signal Desktop ${VERSION}`;
// Workaround: Submitting `FormData` using native `FormData::submit` procedure
// as integration with `got` results in S3 error saying we havent set the
@ -22,7 +25,12 @@ const submitFormData = (form, url) =>
// upload :: String -> Promise URL
exports.upload = async content => {
const signedForm = await got.get(BASE_URL, { json: true });
const signedForm = await got.get(BASE_URL, {
json: true,
headers: {
'user-agent': USER_AGENT,
},
});
const { fields, url } = signedForm.body;
const form = new FormData();
@ -36,10 +44,11 @@ exports.upload = async content => {
const contentBuffer = Buffer.from(content, 'utf8');
const contentType = 'text/plain';
form.append('User-Agent', USER_AGENT);
form.append('Content-Type', contentType);
form.append('file', contentBuffer, {
contentType,
filename: 'signal-desktop-debug-log.txt',
filename: `signal-desktop-debug-log-${VERSION}.txt`,
});
// WORKAROUND: See comment on `submitFormData`: