Use multipart-form encoding for rageshake uploads (#3646)
This is a more sensible encoding for uploading logfiles, and will allow us to compress the logfiles in future. browser-request doesn't give us enough flexibility to do this properly, so we use XMLHttpRequest directly.
This commit is contained in:
parent
062cf47290
commit
a34b5abc82
|
@ -15,12 +15,19 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import q from "q";
|
import q from "q";
|
||||||
import request from "browser-request";
|
|
||||||
|
|
||||||
import PlatformPeg from 'matrix-react-sdk/lib/PlatformPeg';
|
import PlatformPeg from 'matrix-react-sdk/lib/PlatformPeg';
|
||||||
|
|
||||||
import rageshake from './rageshake'
|
import rageshake from './rageshake'
|
||||||
|
|
||||||
|
|
||||||
|
// polyfill textencoder if necessary
|
||||||
|
import * as TextEncodingUtf8 from 'text-encoding-utf-8';
|
||||||
|
let TextEncoder = window.TextEncoder;
|
||||||
|
if (!TextEncoder) {
|
||||||
|
TextEncoder = TextEncodingUtf8.TextEncoder;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a bug report.
|
* Send a bug report.
|
||||||
* @param {string} bugReportEndpoint HTTP url to send the report to
|
* @param {string} bugReportEndpoint HTTP url to send the report to
|
||||||
|
@ -49,36 +56,44 @@ export default async function sendBugReport(bugReportEndpoint, opts) {
|
||||||
|
|
||||||
console.log("Sending bug report.");
|
console.log("Sending bug report.");
|
||||||
|
|
||||||
let logs = [];
|
const body = new FormData();
|
||||||
|
body.append('text', opts.userText || "User did not supply any additional text.");
|
||||||
|
body.append('app', 'riot-web');
|
||||||
|
body.append('version', version);
|
||||||
|
body.append('user_agent', userAgent);
|
||||||
|
|
||||||
if (opts.sendLogs) {
|
if (opts.sendLogs) {
|
||||||
logs = await rageshake.getLogsForReport();
|
const logs = await rageshake.getLogsForReport();
|
||||||
|
for (let entry of logs) {
|
||||||
|
// encode as UTF-8
|
||||||
|
const buf = new TextEncoder().encode(entry.lines);
|
||||||
|
|
||||||
|
body.append('log', new Blob([buf]), entry.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await q.Promise((resolve, reject) => {
|
await _submitReport(bugReportEndpoint, body);
|
||||||
request({
|
}
|
||||||
method: "POST",
|
|
||||||
url: bugReportEndpoint,
|
function _submitReport(endpoint, body) {
|
||||||
body: {
|
const deferred = q.defer();
|
||||||
logs: logs,
|
|
||||||
text: (
|
const req = new XMLHttpRequest();
|
||||||
opts.userText || "User did not supply any additional text."
|
req.open("POST", endpoint);
|
||||||
),
|
req.timeout = 5 * 60 * 1000;
|
||||||
app: 'riot-web',
|
req.onreadystatechange = function() {
|
||||||
version: version,
|
if (req.readyState === XMLHttpRequest.DONE) {
|
||||||
user_agent: userAgent,
|
on_done();
|
||||||
},
|
}
|
||||||
json: true,
|
};
|
||||||
timeout: 5 * 60 * 1000,
|
req.send(body);
|
||||||
}, (err, res) => {
|
return deferred.promise;
|
||||||
if (err) {
|
|
||||||
reject(err);
|
function on_done() {
|
||||||
return;
|
if (req.status < 200 || req.status >= 400) {
|
||||||
}
|
deferred.reject(new Error(`HTTP ${req.status}`));
|
||||||
if (res.status < 200 || res.status >= 400) {
|
return;
|
||||||
reject(new Error(`HTTP ${res.status}`));
|
}
|
||||||
return;
|
deferred.resolve();
|
||||||
}
|
}
|
||||||
resolve();
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue