|
|
@@ -1459,120 +1459,67 @@ DriveClient.prototype.saveFile = function(file, revision, success, errFn, noChec
|
|
|
try
|
|
|
{
|
|
|
file.saveDelay = new Date().getTime() - t0;
|
|
|
- file.saveLevel = 11;
|
|
|
-
|
|
|
- if (resp == null)
|
|
|
- {
|
|
|
- error({message: mxResources.get('errorSavingFile') + ': Empty response'});
|
|
|
- }
|
|
|
- else
|
|
|
+ file.saveLevel = null;
|
|
|
+ success(resp, savedData);
|
|
|
+
|
|
|
+ if (prevDesc != null)
|
|
|
{
|
|
|
- // Checks if modified time is in the future and head revision has changed
|
|
|
- var delta = new Date(resp.modifiedDate).getTime() - new Date(mod0).getTime();
|
|
|
-
|
|
|
- if (delta <= 0 || etag0 == resp.etag || (revision && head0 == resp.headRevisionId))
|
|
|
+ // Pins previous revision
|
|
|
+ this.executeRequest({
|
|
|
+ url: '/files/' + prevDesc.id + '/revisions/' + prevDesc.headRevisionId + '?supportsAllDrives=true'
|
|
|
+ }, mxUtils.bind(this, mxUtils.bind(this, function(resp)
|
|
|
{
|
|
|
- file.saveLevel = 12;
|
|
|
- var reasons = [];
|
|
|
-
|
|
|
- if (delta <= 0)
|
|
|
- {
|
|
|
- reasons.push('invalid modified time');
|
|
|
- }
|
|
|
-
|
|
|
- if (etag0 == resp.etag)
|
|
|
- {
|
|
|
- reasons.push('stale etag');
|
|
|
- }
|
|
|
+ resp.pinned = true;
|
|
|
|
|
|
- if (revision && head0 == resp.headRevisionId)
|
|
|
- {
|
|
|
- reasons.push('stale revision');
|
|
|
- }
|
|
|
-
|
|
|
- var temp = reasons.join(', ');
|
|
|
- error({message: mxResources.get('errorSavingFile') + ': ' + temp}, resp);
|
|
|
-
|
|
|
- // Logs failed save
|
|
|
- try
|
|
|
- {
|
|
|
- EditorUi.logError('Critical: Error saving to Google Drive ' + file.desc.id,
|
|
|
- null, 'from-' + head0 + '.' + mod0 + '-' + this.ui.hashValue(etag0) +
|
|
|
- '-to-' + resp.headRevisionId + '.' + resp.modifiedDate + '-' +
|
|
|
- this.ui.hashValue(resp.etag) + ((temp.length > 0) ? '-errors-' + temp : ''),
|
|
|
- 'user-' + ((this.user != null) ? this.user.id : 'nouser') +
|
|
|
- ((file.sync != null) ? '-client_' + file.sync.clientId : '-nosync'));
|
|
|
- }
|
|
|
- catch (e)
|
|
|
- {
|
|
|
- // ignore
|
|
|
- }
|
|
|
+ this.executeRequest({
|
|
|
+ url: '/files/' + prevDesc.id + '/revisions/' + prevDesc.headRevisionId,
|
|
|
+ method: 'PUT',
|
|
|
+ params: resp
|
|
|
+ });
|
|
|
+ })));
|
|
|
+
|
|
|
+ // Logs conversion
|
|
|
+ try
|
|
|
+ {
|
|
|
+ EditorUi.logEvent({category: file.convertedFrom + '-CONVERT-FILE-' + file.getHash(),
|
|
|
+ action: 'from_' + prevDesc.id + '.' + prevDesc.headRevisionId +
|
|
|
+ '-to_' + file.desc.id + '.' + file.desc.headRevisionId,
|
|
|
+ label: (this.user != null) ? ('user_' + this.user.id) : 'nouser' +
|
|
|
+ ((file.sync != null) ? '-client_' + file.sync.clientId : 'nosync')});
|
|
|
}
|
|
|
- else
|
|
|
+ catch (e)
|
|
|
{
|
|
|
- file.saveLevel = null;
|
|
|
- success(resp, savedData);
|
|
|
-
|
|
|
- if (prevDesc != null)
|
|
|
- {
|
|
|
- // Pins previous revision
|
|
|
- this.executeRequest({
|
|
|
- url: '/files/' + prevDesc.id + '/revisions/' + prevDesc.headRevisionId + '?supportsAllDrives=true'
|
|
|
- }, mxUtils.bind(this, mxUtils.bind(this, function(resp)
|
|
|
- {
|
|
|
- resp.pinned = true;
|
|
|
-
|
|
|
- this.executeRequest({
|
|
|
- url: '/files/' + prevDesc.id + '/revisions/' + prevDesc.headRevisionId,
|
|
|
- method: 'PUT',
|
|
|
- params: resp
|
|
|
- });
|
|
|
- })));
|
|
|
-
|
|
|
- // Logs conversion
|
|
|
- try
|
|
|
- {
|
|
|
- EditorUi.logEvent({category: file.convertedFrom + '-CONVERT-FILE-' + file.getHash(),
|
|
|
- action: 'from_' + prevDesc.id + '.' + prevDesc.headRevisionId +
|
|
|
- '-to_' + file.desc.id + '.' + file.desc.headRevisionId,
|
|
|
- label: (this.user != null) ? ('user_' + this.user.id) : 'nouser' +
|
|
|
- ((file.sync != null) ? '-client_' + file.sync.clientId : 'nosync')});
|
|
|
- }
|
|
|
- catch (e)
|
|
|
- {
|
|
|
- // ignore
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Logs successful save
|
|
|
-// try
|
|
|
-// {
|
|
|
-// EditorUi.logEvent({category: 'SUCCESS-SAVE-FILE-' + file.getHash() +
|
|
|
-// '-rev0_' + head0 + '-mod0_' + mod0,
|
|
|
-// action: 'rev-' + resp.headRevisionId +
|
|
|
-// '-mod_' + resp.modifiedDate + '-size_' + file.getSize() +
|
|
|
-// '-mime_' + file.desc.mimeType +
|
|
|
-// ((this.ui.editor.autosave) ? '' : '-nosave') +
|
|
|
-// ((file.isAutosave()) ? '' : '-noauto') +
|
|
|
-// ((file.changeListenerEnabled) ? '' : '-nolisten') +
|
|
|
-// ((file.inConflictState) ? '-conflict' : '') +
|
|
|
-// ((file.invalidChecksum) ? '-invalid' : ''),
|
|
|
-// label: ((this.user != null) ? ('user_' + this.user.id) : 'nouser') +
|
|
|
-// ((file.sync != null) ? ('-client_' + file.sync.clientId) : '-nosync')});
|
|
|
-// }
|
|
|
-// catch (e)
|
|
|
-// {
|
|
|
-// // ignore
|
|
|
-// }
|
|
|
+ // ignore
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // Logs successful save
|
|
|
+ // try
|
|
|
+ // {
|
|
|
+ // EditorUi.logEvent({category: 'SUCCESS-SAVE-FILE-' + file.getHash() +
|
|
|
+ // '-rev0_' + head0 + '-mod0_' + mod0,
|
|
|
+ // action: 'rev-' + resp.headRevisionId +
|
|
|
+ // '-mod_' + resp.modifiedDate + '-size_' + file.getSize() +
|
|
|
+ // '-mime_' + file.desc.mimeType +
|
|
|
+ // ((this.ui.editor.autosave) ? '' : '-nosave') +
|
|
|
+ // ((file.isAutosave()) ? '' : '-noauto') +
|
|
|
+ // ((file.changeListenerEnabled) ? '' : '-nolisten') +
|
|
|
+ // ((file.inConflictState) ? '-conflict' : '') +
|
|
|
+ // ((file.invalidChecksum) ? '-invalid' : ''),
|
|
|
+ // label: ((this.user != null) ? ('user_' + this.user.id) : 'nouser') +
|
|
|
+ // ((file.sync != null) ? ('-client_' + file.sync.clientId) : '-nosync')});
|
|
|
+ // }
|
|
|
+ // catch (e)
|
|
|
+ // {
|
|
|
+ // // ignore
|
|
|
+ // }
|
|
|
}
|
|
|
catch (e)
|
|
|
{
|
|
|
criticalError(e);
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
var doExecuteRequest = mxUtils.bind(this, function(data, binary)
|
|
|
{
|
|
|
file.saveLevel = 4;
|
|
|
@@ -1622,7 +1569,81 @@ DriveClient.prototype.saveFile = function(file, revision, success, errFn, noChec
|
|
|
|
|
|
if (acceptResponse)
|
|
|
{
|
|
|
- wrapper(resp);
|
|
|
+ // Checks if modified time is in the future and etag and head revision have changed
|
|
|
+ var delta = (resp != null) ? new Date(resp.modifiedDate).getTime() - new Date(mod0).getTime() : 0;
|
|
|
+
|
|
|
+ if (delta <= 0 || etag0 == resp.etag || (revision && head0 == resp.headRevisionId))
|
|
|
+ {
|
|
|
+ var reasons = [];
|
|
|
+
|
|
|
+ if (resp == null)
|
|
|
+ {
|
|
|
+ reasons.push('Empty response');
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (delta <= 0)
|
|
|
+ {
|
|
|
+ reasons.push('Invalid modified time');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (etag0 == resp.etag)
|
|
|
+ {
|
|
|
+ reasons.push('Stale etag');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (revision && head0 == resp.headRevisionId)
|
|
|
+ {
|
|
|
+ reasons.push('Stale revision');
|
|
|
+ }
|
|
|
+
|
|
|
+ // Updates etag for retry
|
|
|
+ etag = resp.etag;
|
|
|
+ }
|
|
|
+
|
|
|
+ var temp = reasons.join(', ');
|
|
|
+
|
|
|
+ if (retryCount < this.staleEtagMaxRetries)
|
|
|
+ {
|
|
|
+ retryCount++;
|
|
|
+ var jitter = 1 + 0.1 * (Math.random() - 0.5);
|
|
|
+ var delay = Math.round(retryCount * 2 * this.coolOff * jitter);
|
|
|
+ window.setTimeout(doExecuteSave, delay);
|
|
|
+
|
|
|
+ if (urlParams['test'] == '1')
|
|
|
+ {
|
|
|
+ EditorUi.debug('DriveClient: Invalid response',
|
|
|
+ 'retry', retryCount, 'delay', delay, 'rev',
|
|
|
+ (resp != null) ? resp.headRevisionId : 'null',
|
|
|
+ 'errors', temp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ file.saveLevel = 12;
|
|
|
+ error({message: mxResources.get('error') + ': ' + temp}, resp);
|
|
|
+
|
|
|
+ // Logs failed save
|
|
|
+ try
|
|
|
+ {
|
|
|
+ EditorUi.logError('Critical: Saving to Google Drive failed ' + file.desc.id,
|
|
|
+ null, 'from-' + head0 + '.' + mod0 + '-' + this.ui.hashValue(etag0) +
|
|
|
+ '-to-' + resp.headRevisionId + '.' + resp.modifiedDate + '-' +
|
|
|
+ this.ui.hashValue(resp.etag) + ((temp.length > 0) ? '-errors-' + temp : ''),
|
|
|
+ 'user-' + ((this.user != null) ? this.user.id : 'nouser') +
|
|
|
+ ((file.sync != null) ? '-client_' + file.sync.clientId : '-nosync') +
|
|
|
+ '-retries-' + retryCount);
|
|
|
+ }
|
|
|
+ catch (e)
|
|
|
+ {
|
|
|
+ // ignore
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ wrapper(resp);
|
|
|
+ }
|
|
|
}
|
|
|
}), mxUtils.bind(this, function(err)
|
|
|
{
|
|
|
@@ -1657,7 +1678,7 @@ DriveClient.prototype.saveFile = function(file, revision, success, errFn, noChec
|
|
|
{
|
|
|
retryCount++;
|
|
|
var jitter = 1 + 0.1 * (Math.random() - 0.5);
|
|
|
- var delay = retryCount * 2 * this.coolOff * jitter;
|
|
|
+ var delay = Math.round(retryCount * 2 * this.coolOff * jitter);
|
|
|
window.setTimeout(executeSave, delay);
|
|
|
|
|
|
if (urlParams['test'] == '1')
|
|
|
@@ -2352,18 +2373,27 @@ DriveClient.prototype.pickFolder = function(fn, force)
|
|
|
{
|
|
|
showPicker();
|
|
|
}
|
|
|
- else
|
|
|
+ else if (this.ui.spinner.spin(document.body, mxResources.get('authorizing')))
|
|
|
{
|
|
|
this.execute(mxUtils.bind(this, function()
|
|
|
{
|
|
|
- this.ui.confirm(mxResources.get('useRootFolder'), mxUtils.bind(this, function()
|
|
|
+ try
|
|
|
{
|
|
|
- this.folderPickerCallback({action: google.picker.Action.PICKED,
|
|
|
- docs: [{type: 'folder', id: 'root'}]});
|
|
|
- }), mxUtils.bind(this, function()
|
|
|
+ this.ui.spinner.stop();
|
|
|
+
|
|
|
+ this.ui.confirm(mxResources.get('useRootFolder'), mxUtils.bind(this, function()
|
|
|
+ {
|
|
|
+ this.folderPickerCallback({action: google.picker.Action.PICKED,
|
|
|
+ docs: [{type: 'folder', id: 'root'}]});
|
|
|
+ }), mxUtils.bind(this, function()
|
|
|
+ {
|
|
|
+ showPicker();
|
|
|
+ }), mxResources.get('yes'), mxResources.get('noPickFolder') + '...', true);
|
|
|
+ }
|
|
|
+ catch (e)
|
|
|
{
|
|
|
- showPicker();
|
|
|
- }), mxResources.get('yes'), mxResources.get('noPickFolder') + '...', true);
|
|
|
+ this.ui.handleError(e);
|
|
|
+ }
|
|
|
}));
|
|
|
}
|
|
|
};
|