Chrome: Move Debug Logs From GitHub Gists to debuglogs.org

In anticipation of GitHub’s deprecation of anonymous gists, we are moving our
debug logs to https://debuglogs.org.

- [x] Publish debug logs to debuglogs.org:
  - ~~Using jQuery v2.1.1-pre results in S3 error about invalid form data
    indicating our jQuery version (added in 2014) doesn’t serialize
    `FormData` correctly.~~
  - [x] Using vanilla XHR ~~results in CORS error indicating our S3 bucket
    doesn’t CORS headers but upload succeeds nonetheless.~~
- [x] Add CORS headers to https://debuglogs.org
- [x] Add CORS headers to S3 bucket (incl. `POST` requests):
      https://s3.amazonaws.com/signal-debug-logs

**Sample log:** https://debuglogs.org/76bf1d7fd9b88ad061d91f79914230e45dc123bc8d169e073f10adb5c1999d4e
This commit is contained in:
Daniel Gasienica
2018-03-13 16:48:08 -04:00
3 changed files with 49 additions and 10 deletions

View File

@@ -698,7 +698,7 @@ sudo apt update && sudo apt install signal-desktop
</div>
<div class='nav'>
<div>
<a class='link debug-log'>{{ debugLogButton }}</a>
<a class='link submit-debug-log'>{{ debugLogButton }}</a>
</div>
</div>
</div>
@@ -717,7 +717,7 @@ sudo apt update && sudo apt install signal-desktop
</div>
<div class='nav'>
<div>
<a class='link debug-log'>{{ debugLogButton }}</a>
<a class='link submit-debug-log'>{{ debugLogButton }}</a>
</div>
</div>
</div>

View File

@@ -42,6 +42,7 @@
var MAX_MESSAGES = 2000;
var PHONE_REGEX = /\+\d{7,12}(\d{3})/g;
var DEBUGLOGS_BASE_URL = 'https://debuglogs.org';
var log = new DebugLog();
if (window.console) {
console._log = console.log;
@@ -60,13 +61,51 @@
if (log === undefined) {
log = console.get();
}
return new Promise(function(resolve) {
$.post('https://api.github.com/gists', textsecure.utils.jsonThing({
"files": { "debugLog.txt": { "content": log } }
})).then(function(response) {
console._log('Posted debug log to ', response.html_url);
resolve(response.html_url);
}).fail(resolve);
return new Promise(function(resolve, reject) {
$.get(DEBUGLOGS_BASE_URL).then(function (signedForm) {
var url = signedForm.url;
var fields = signedForm.fields;
var formData = new FormData();
// NOTE: Service expects `key` to come first:
formData.append('key', fields.key);
formData.append('Content-Type', 'text/plain');
for (var key in fields) {
if (key === 'key') {
continue;
}
var value = fields[key];
formData.append(key, value);
}
var contentBlob = new Blob([log], { type: 'text/plain' });
formData.append('file', contentBlob);
var publishedLogURL = DEBUGLOGS_BASE_URL + '/' + fields.key;
var request = new XMLHttpRequest();
request.open('POST', url);
request.onreadystatechange = function (event) {
if (request.readyState !== XMLHttpRequest.DONE) {
return;
}
if (request.status !== 204) {
return reject(
new Error('Failed to publish debug log. Status: ' +
request.statusText + ' (' + request.status + ')'
)
);
}
return resolve(publishedLogURL);
};
request.send(formData);
}).fail(function () {
reject(new Error('Failed to publish logs'));
});
});
};

View File

@@ -145,7 +145,7 @@
'click .start': 'onClickStart',
'click .installed': 'onClickInstalled',
'click .choose': 'onClickChoose',
'click .debug-log': 'onClickDebugLog',
'click .submit-debug-log': 'onClickDebugLog',
'click .cancel': 'onClickCancel',
},
initialize: function() {