Use consistent User-Agent when uploading debug logs
This commit is contained in:
parent
d0146a1613
commit
8ccf402497
9 changed files with 331 additions and 138 deletions
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2017-2020 Signal Messenger, LLC
|
||||
// Copyright 2017-2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
/* eslint-env node */
|
||||
|
@ -8,7 +8,7 @@
|
|||
const electron = require('electron');
|
||||
const _ = require('lodash');
|
||||
|
||||
const debuglogs = require('./modules/debuglogs');
|
||||
const { uploadDebugLogs } = require('../ts/logging/debuglogs');
|
||||
const Privacy = require('./modules/privacy');
|
||||
const { createBatcher } = require('../ts/util/batcher');
|
||||
|
||||
|
@ -97,7 +97,7 @@ function fetch() {
|
|||
});
|
||||
}
|
||||
|
||||
const publish = debuglogs.upload;
|
||||
const publish = uploadDebugLogs;
|
||||
|
||||
// A modern logging interface for the browser
|
||||
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
// Copyright 2018-2020 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
/* eslint-env node */
|
||||
/* global window */
|
||||
|
||||
const FormData = require('form-data');
|
||||
const got = require('got');
|
||||
const pify = require('pify');
|
||||
const { gzip } = require('zlib');
|
||||
|
||||
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 haven’t set the
|
||||
// `Content-Length` header:
|
||||
// https://github.com/sindresorhus/got/pull/466
|
||||
const submitFormData = (form, url) =>
|
||||
new Promise((resolve, reject) => {
|
||||
form.submit(url, (error, response) => {
|
||||
if (error) {
|
||||
return reject(error);
|
||||
}
|
||||
|
||||
const { statusCode } = response;
|
||||
if (statusCode !== 204) {
|
||||
return reject(
|
||||
new Error(`Failed to upload to S3, got status ${statusCode}`)
|
||||
);
|
||||
}
|
||||
|
||||
return resolve();
|
||||
});
|
||||
});
|
||||
|
||||
// upload :: String -> Promise URL
|
||||
exports.upload = async content => {
|
||||
const signedForm = await got.get(BASE_URL, {
|
||||
json: true,
|
||||
headers: {
|
||||
'user-agent': USER_AGENT,
|
||||
},
|
||||
});
|
||||
if (!signedForm.body) {
|
||||
throw new Error('Failed to retrieve token');
|
||||
}
|
||||
const { fields, url } = signedForm.body;
|
||||
|
||||
const form = new FormData();
|
||||
// The API expects `key` to be the first field:
|
||||
form.append('key', fields.key);
|
||||
Object.entries(fields)
|
||||
.filter(([key]) => key !== 'key')
|
||||
.forEach(([key, value]) => {
|
||||
form.append(key, value);
|
||||
});
|
||||
|
||||
const contentBuffer = await pify(gzip)(Buffer.from(content, 'utf8'));
|
||||
const contentType = 'application/gzip';
|
||||
form.append('Content-Type', contentType);
|
||||
form.append('file', contentBuffer, {
|
||||
contentType,
|
||||
filename: `signal-desktop-debug-log-${VERSION}.txt.gz`,
|
||||
});
|
||||
|
||||
window.log.info('Debug log upload starting...');
|
||||
// WORKAROUND: See comment on `submitFormData`:
|
||||
// await got.post(url, { body: form });
|
||||
await submitFormData(form, url);
|
||||
window.log.info('Debug log upload complete.');
|
||||
|
||||
return `${BASE_URL}/${fields.key}`;
|
||||
};
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2015-2020 Signal Messenger, LLC
|
||||
// Copyright 2015-2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
/* global i18n: false */
|
||||
|
@ -73,7 +73,10 @@
|
|||
this.$('.result').addClass('loading');
|
||||
|
||||
try {
|
||||
const publishedLogURL = await window.log.publish(text);
|
||||
const publishedLogURL = await window.log.publish(
|
||||
text,
|
||||
window.getVersion()
|
||||
);
|
||||
const view = new Whisper.DebugLogLinkView({
|
||||
url: publishedLogURL,
|
||||
el: this.$('.result'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue