mirror of
https://github.com/zotero/zotero.git
synced 2026-10-04 02:31:47 +00:00
Add a debug flag to prompt or throw on an attempted sync upload
extensions.zotero.sync.debugUploadPolicy = {1, 2}
1 to prompt, 2 to throw
This can be used to test sync functionality without altering the server
state unexpectedly. When prompting, the request body, if any, is logged
to debug output.
This commit is contained in:
parent
98cd96eb01
commit
92ec1324dc
2 changed files with 19 additions and 2 deletions
|
|
@ -36,6 +36,7 @@ Zotero.Sync.APIClient = function (options) {
|
|||
this.apiVersion = options.apiVersion;
|
||||
this.apiKey = options.apiKey;
|
||||
this.caller = options.caller;
|
||||
this.debugUploadPolicy = Zotero.Prefs.get('sync.debugUploadPolicy');
|
||||
|
||||
this.failureDelayIntervals = [2500, 5000, 10000, 20000, 40000, 60000, 120000, 240000, 300000];
|
||||
this.failureDelayMax = 60 * 60 * 1000; // 1 hour
|
||||
|
|
@ -573,6 +574,23 @@ Zotero.Sync.APIClient.prototype = {
|
|||
if (!this.apiKey && !options.noAPIKey) {
|
||||
throw new Error('API key not set');
|
||||
}
|
||||
|
||||
if (Zotero.HTTP.isWriteMethod(method) && this.debugUploadPolicy) {
|
||||
// Confirm uploads when extensions.zotero.sync.debugUploadPolicy is 1
|
||||
if (this.debugUploadPolicy === 1) {
|
||||
if (options.body) {
|
||||
Zotero.debug(options.body);
|
||||
}
|
||||
if (!Services.prompt.confirm(null, "Allow Upload?", `Allow ${method} to ${uri}?`)) {
|
||||
throw new Error(method + " request denied");
|
||||
}
|
||||
}
|
||||
// Deny uploads when extensions.zotero.sync.debugUploadPolicy is 2
|
||||
else if (this.debugUploadPolicy === 2) {
|
||||
throw new Error(`Can't make ${method} request in read-only mode`);
|
||||
}
|
||||
}
|
||||
|
||||
let opts = {}
|
||||
Object.assign(opts, options);
|
||||
opts.headers = this.getHeaders(options.headers);
|
||||
|
|
|
|||
|
|
@ -64,7 +64,6 @@ Zotero.Sync.Runner_Module = function (options = {}) {
|
|||
var _currentLastSyncLabel;
|
||||
var _errors = [];
|
||||
|
||||
|
||||
this.getAPIClient = function (options = {}) {
|
||||
return new Zotero.Sync.APIClient({
|
||||
baseURL: this.baseURL,
|
||||
|
|
@ -113,7 +112,7 @@ Zotero.Sync.Runner_Module = function (options = {}) {
|
|||
}
|
||||
|
||||
this.updateIcons('animate');
|
||||
|
||||
|
||||
let client = this.getAPIClient({ apiKey });
|
||||
let keyInfo = yield this.checkAccess(client, options);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue