Simplify the file sync code a bit
Just call Zotero.Sync.Storage.[ZFS/WebDAV] directly This probably breaks some things.
This commit is contained in:
parent
b298e7acbd
commit
f1aa68f82b
|
@ -291,7 +291,7 @@ function updateStorageSettings(enabled, protocol, skipWarnings) {
|
||||||
var sql = "INSERT OR IGNORE INTO settings VALUES (?,?,?)";
|
var sql = "INSERT OR IGNORE INTO settings VALUES (?,?,?)";
|
||||||
Zotero.DB.query(sql, ['storage', 'zfsPurge', 'user']);
|
Zotero.DB.query(sql, ['storage', 'zfsPurge', 'user']);
|
||||||
|
|
||||||
Zotero.Sync.Storage.purgeDeletedStorageFiles('zfs', function (success) {
|
Zotero.Sync.Storage.ZFS.purgeDeletedStorageFiles(function (success) {
|
||||||
if (success) {
|
if (success) {
|
||||||
ps.alert(
|
ps.alert(
|
||||||
null,
|
null,
|
||||||
|
@ -363,7 +363,7 @@ function verifyStorageServer() {
|
||||||
abortButton.hidden = false;
|
abortButton.hidden = false;
|
||||||
progressMeter.hidden = false;
|
progressMeter.hidden = false;
|
||||||
|
|
||||||
var requestHolder = Zotero.Sync.Storage.checkServer('WebDAV', function (uri, status, callback) {
|
var requestHolder = Zotero.Sync.Storage.WebDAV.checkServer(function (uri, status, callback) {
|
||||||
verifyButton.hidden = false;
|
verifyButton.hidden = false;
|
||||||
abortButton.hidden = true;
|
abortButton.hidden = true;
|
||||||
progressMeter.hidden = true;
|
progressMeter.hidden = true;
|
||||||
|
@ -388,7 +388,7 @@ function verifyStorageServer() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(uri, status, window);
|
Zotero.Sync.Storage.WebDAV.checkServerCallback(uri, status, window);
|
||||||
});
|
});
|
||||||
|
|
||||||
abortButton.onclick = function () {
|
abortButton.onclick = function () {
|
||||||
|
|
|
@ -157,7 +157,7 @@ To add a new preference:
|
||||||
|
|
||||||
<prefpane id="zotero-prefpane-sync"
|
<prefpane id="zotero-prefpane-sync"
|
||||||
label="&zotero.preferences.prefpane.sync;"
|
label="&zotero.preferences.prefpane.sync;"
|
||||||
onpaneload="document.getElementById('sync-password').value = Zotero.Sync.Server.password; document.getElementById('storage-password').value = Zotero.Sync.Storage.password;"
|
onpaneload="document.getElementById('sync-password').value = Zotero.Sync.Server.password; var pass = Zotero.Sync.Storage.WebDAV.password; if (pass) { document.getElementById('storage-password').value = pass; }"
|
||||||
image="chrome://zotero/skin/prefs-sync.png"
|
image="chrome://zotero/skin/prefs-sync.png"
|
||||||
helpTopic="sync">
|
helpTopic="sync">
|
||||||
<preferences>
|
<preferences>
|
||||||
|
@ -283,7 +283,7 @@ To add a new preference:
|
||||||
preference="pref-storage-username"
|
preference="pref-storage-username"
|
||||||
onkeypress="if (Zotero.isMac && event.keyCode == 13) { this.blur(); setTimeout(verifyStorageServer, 1); }"
|
onkeypress="if (Zotero.isMac && event.keyCode == 13) { this.blur(); setTimeout(verifyStorageServer, 1); }"
|
||||||
onsynctopreference="unverifyStorageServer();"
|
onsynctopreference="unverifyStorageServer();"
|
||||||
onchange="var pass = document.getElementById('storage-password'); if (pass.value) { Zotero.Sync.Storage.Session.WebDAV.prototype.password = pass.value; }"/>
|
onchange="var pass = document.getElementById('storage-password'); if (pass.value) { Zotero.Sync.Storage.WebDAV.password = pass.value; }"/>
|
||||||
</hbox>
|
</hbox>
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
|
@ -292,7 +292,7 @@ To add a new preference:
|
||||||
<textbox id="storage-password" flex="0" type="password"
|
<textbox id="storage-password" flex="0" type="password"
|
||||||
onkeypress="if (Zotero.isMac && event.keyCode == 13) { this.blur(); setTimeout(verifyStorageServer, 1); }"
|
onkeypress="if (Zotero.isMac && event.keyCode == 13) { this.blur(); setTimeout(verifyStorageServer, 1); }"
|
||||||
oninput="unverifyStorageServer()"
|
oninput="unverifyStorageServer()"
|
||||||
onchange="Zotero.Sync.Storage.Session.WebDAV.prototype.password = this.value"/>
|
onchange="Zotero.Sync.Storage.WebDAV.password = this.value;"/>
|
||||||
</hbox>
|
</hbox>
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
|
|
|
@ -252,9 +252,13 @@ Zotero.Relations = new function () {
|
||||||
}
|
}
|
||||||
relation.libraryID = parseInt(libraryID);
|
relation.libraryID = parseInt(libraryID);
|
||||||
}
|
}
|
||||||
relation.subject = _getFirstChildContent(relationNode, 'subject');
|
|
||||||
relation.predicate = _getFirstChildContent(relationNode, 'predicate');
|
var elems = Zotero.Utilities.xpath(relationNode, 'subject');
|
||||||
relation.object = _getFirstChildContent(relationNode, 'object');
|
relation.subject = elems.length ? elems[0].textContent : "";
|
||||||
|
var elems = Zotero.Utilities.xpath(relationNode, 'predicate');
|
||||||
|
relation.predicate = elems.length ? elems[0].textContent : "";
|
||||||
|
var elems = Zotero.Utilities.xpath(relationNode, 'object');
|
||||||
|
relation.object = elems.length ? elems[0].textContent : "";
|
||||||
return relation;
|
return relation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,41 +87,41 @@ Zotero.Sync.Storage = new function () {
|
||||||
//
|
//
|
||||||
// Public methods
|
// Public methods
|
||||||
//
|
//
|
||||||
this.sync = function (moduleName, observer) {
|
this.sync = function (modeName, observer) {
|
||||||
var module = getModuleFromName(moduleName);
|
var mode = getModeFromName(modeName);
|
||||||
|
|
||||||
if (!observer) {
|
if (!observer) {
|
||||||
throw new Error("Observer not provided");
|
throw new Error("Observer not provided");
|
||||||
}
|
}
|
||||||
registerDefaultObserver(moduleName);
|
registerDefaultObserver(modeName);
|
||||||
Zotero.Sync.Storage.EventManager.registerObserver(observer, true, moduleName);
|
Zotero.Sync.Storage.EventManager.registerObserver(observer, true, modeName);
|
||||||
|
|
||||||
if (!module.active) {
|
if (!mode.active) {
|
||||||
if (!module.enabled) {
|
if (!mode.enabled) {
|
||||||
Zotero.debug(module.name + " file sync is not enabled");
|
Zotero.debug(mode.name + " file sync is not enabled");
|
||||||
Zotero.Sync.Storage.EventManager.skip();
|
Zotero.Sync.Storage.EventManager.skip();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.debug(module.name + " file sync is not active");
|
Zotero.debug(mode.name + " file sync is not active");
|
||||||
|
|
||||||
// Try to verify server now if it hasn't been
|
// Try to verify server now if it hasn't been
|
||||||
if (!module.verified) {
|
if (!mode.verified) {
|
||||||
module.checkServer(function (uri, status) {
|
mode.checkServer(function (uri, status) {
|
||||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||||
.getService(Components.interfaces.nsIWindowMediator);
|
.getService(Components.interfaces.nsIWindowMediator);
|
||||||
var lastWin = wm.getMostRecentWindow("navigator:browser");
|
var lastWin = wm.getMostRecentWindow("navigator:browser");
|
||||||
|
|
||||||
var success = module.checkServerCallback(uri, status, lastWin, true);
|
var success = mode.checkServerCallback(uri, status, lastWin, true);
|
||||||
if (success) {
|
if (success) {
|
||||||
Zotero.debug(module.name + " file sync is successfully set up");
|
Zotero.debug(mode.name + " file sync is successfully set up");
|
||||||
Zotero.Sync.Storage.sync(module.name);
|
Zotero.Sync.Storage.sync(mode.name);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Zotero.debug(module.name + " verification failed");
|
Zotero.debug(mode.name + " verification failed");
|
||||||
|
|
||||||
var e = new Zotero.Error(
|
var e = new Zotero.Error(
|
||||||
Zotero.getString('sync.storage.error.verificationFailed', module.name),
|
Zotero.getString('sync.storage.error.verificationFailed', mode.name),
|
||||||
0,
|
0,
|
||||||
{
|
{
|
||||||
dialogButtonText: Zotero.getString('sync.openSyncPreferences'),
|
dialogButtonText: Zotero.getString('sync.openSyncPreferences'),
|
||||||
|
@ -141,8 +141,8 @@ Zotero.Sync.Storage = new function () {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!module.includeUserFiles && !module.includeGroupFiles) {
|
if (!mode.includeUserFiles && !mode.includeGroupFiles) {
|
||||||
Zotero.debug("No libraries are enabled for " + module.name + " syncing");
|
Zotero.debug("No libraries are enabled for " + mode.name + " syncing");
|
||||||
Zotero.Sync.Storage.EventManager.skip();
|
Zotero.Sync.Storage.EventManager.skip();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ Zotero.Sync.Storage = new function () {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.debug("Beginning " + module.name + " file sync");
|
Zotero.debug("Beginning " + mode.name + " file sync");
|
||||||
_syncInProgress = true;
|
_syncInProgress = true;
|
||||||
_changesMade = false;
|
_changesMade = false;
|
||||||
|
|
||||||
|
@ -161,8 +161,8 @@ Zotero.Sync.Storage = new function () {
|
||||||
Zotero.Sync.Storage.checkForUpdatedFiles(
|
Zotero.Sync.Storage.checkForUpdatedFiles(
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
module.includeUserFiles && Zotero.Sync.Storage.downloadOnSync(),
|
mode.includeUserFiles && Zotero.Sync.Storage.downloadOnSync(),
|
||||||
module.includeGroupFiles && Zotero.Sync.Storage.downloadOnSync('groups')
|
mode.includeGroupFiles && Zotero.Sync.Storage.downloadOnSync('groups')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
@ -171,14 +171,14 @@ Zotero.Sync.Storage = new function () {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
module.getLastSyncTime(function (lastSyncTime) {
|
mode.getLastSyncTime(function (lastSyncTime) {
|
||||||
// Register the observers again to make sure they're active when we
|
// Register the observers again to make sure they're active when we
|
||||||
// start the queues. (They'll only be registered once.) Observers are
|
// start the queues. (They'll only be registered once.) Observers are
|
||||||
// cleared when all queues finish, so without this another sync
|
// cleared when all queues finish, so without this another sync
|
||||||
// process (e.g., on-demand download) could finish and clear all
|
// process (e.g., on-demand download) could finish and clear all
|
||||||
// observers while getLastSyncTime() is running.
|
// observers while getLastSyncTime() is running.
|
||||||
registerDefaultObserver(moduleName);
|
registerDefaultObserver(modeName);
|
||||||
Zotero.Sync.Storage.EventManager.registerObserver(observer, true, moduleName);
|
Zotero.Sync.Storage.EventManager.registerObserver(observer, true, modeName);
|
||||||
|
|
||||||
var download = true;
|
var download = true;
|
||||||
|
|
||||||
|
@ -186,17 +186,17 @@ Zotero.Sync.Storage = new function () {
|
||||||
var force = !!Zotero.DB.valueQuery(sql, Zotero.Sync.Storage.SYNC_STATE_FORCE_DOWNLOAD);
|
var force = !!Zotero.DB.valueQuery(sql, Zotero.Sync.Storage.SYNC_STATE_FORCE_DOWNLOAD);
|
||||||
|
|
||||||
if (!force && lastSyncTime) {
|
if (!force && lastSyncTime) {
|
||||||
var sql = "SELECT version FROM version WHERE schema='storage_" + moduleName + "'";
|
var sql = "SELECT version FROM version WHERE schema='storage_" + modeName + "'";
|
||||||
var version = Zotero.DB.valueQuery(sql);
|
var version = Zotero.DB.valueQuery(sql);
|
||||||
if (version == lastSyncTime) {
|
if (version == lastSyncTime) {
|
||||||
Zotero.debug("Last " + module.name + " sync time hasn't changed -- skipping file download step");
|
Zotero.debug("Last " + mode.name + " sync time hasn't changed -- skipping file download step");
|
||||||
download = false;
|
download = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var activeDown = download ? _downloadFiles(module) : false;
|
var activeDown = download ? _downloadFiles(mode) : false;
|
||||||
var activeUp = _uploadFiles(module);
|
var activeUp = _uploadFiles(mode);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
Zotero.Sync.Storage.EventManager.error(e);
|
Zotero.Sync.Storage.EventManager.error(e);
|
||||||
|
@ -620,9 +620,9 @@ Zotero.Sync.Storage = new function () {
|
||||||
*/
|
*/
|
||||||
this.downloadFile = function (item, requestCallbacks) {
|
this.downloadFile = function (item, requestCallbacks) {
|
||||||
var itemID = item.id;
|
var itemID = item.id;
|
||||||
var module = getModuleFromLibrary(item.libraryID);
|
var mode = getModeFromLibrary(item.libraryID);
|
||||||
|
|
||||||
if (!module || !module.active) {
|
if (!mode || !mode.active) {
|
||||||
Zotero.debug("File syncing is not active for item's library -- skipping download");
|
Zotero.debug("File syncing is not active for item's library -- skipping download");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -681,7 +681,7 @@ Zotero.Sync.Storage = new function () {
|
||||||
requestCallbacks = {};
|
requestCallbacks = {};
|
||||||
}
|
}
|
||||||
var onStart = function (request) {
|
var onStart = function (request) {
|
||||||
module.downloadFile(request);
|
mode.downloadFile(request);
|
||||||
};
|
};
|
||||||
requestCallbacks.onStart = requestCallbacks.onStart
|
requestCallbacks.onStart = requestCallbacks.onStart
|
||||||
? [onStart, requestCallbacks.onStart]
|
? [onStart, requestCallbacks.onStart]
|
||||||
|
@ -699,7 +699,7 @@ Zotero.Sync.Storage = new function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
module.cacheCredentials(function () {
|
mode.cacheCredentials(function () {
|
||||||
run();
|
run();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -820,8 +820,7 @@ Zotero.Sync.Storage = new function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.checkServer = function (moduleName, callback) {
|
this.checkServer = function (modeName, callback) {
|
||||||
var module = getModuleFromName(moduleName);
|
|
||||||
Zotero.Sync.Storage.EventManager.registerObserver({
|
Zotero.Sync.Storage.EventManager.registerObserver({
|
||||||
onSuccess: function () {},
|
onSuccess: function () {},
|
||||||
onError: function (e) {
|
onError: function (e) {
|
||||||
|
@ -833,47 +832,16 @@ Zotero.Sync.Storage = new function () {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}, false, "checkServer");
|
}, false, "checkServer");
|
||||||
return module.checkServer(function (uri, status) {
|
|
||||||
|
var mode = getModeFromName(modeName);
|
||||||
|
return mode.checkServer(function (uri, status) {
|
||||||
callback(uri, status, function () {
|
callback(uri, status, function () {
|
||||||
module.checkServerCallback(uri, status);
|
mode.checkServerCallback(uri, status);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.purgeDeletedStorageFiles = function (moduleName, callback) {
|
|
||||||
var module = getModuleFromName(moduleName);
|
|
||||||
if (!module.active) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Zotero.Sync.Storage.EventManager.registerObserver({
|
|
||||||
onError: function (e) {
|
|
||||||
error(e);
|
|
||||||
}
|
|
||||||
}, false, "purgeDeletedStorageFiles");
|
|
||||||
module.purgeDeletedStorageFiles(callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
this.purgeOrphanedStorageFiles = function (moduleName, callback) {
|
|
||||||
var module = getModuleFromName(moduleName);
|
|
||||||
if (!module.active) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Zotero.Sync.Storage.EventManager.registerObserver({
|
|
||||||
onError: function (e) {
|
|
||||||
error(e);
|
|
||||||
}
|
|
||||||
}, false, "purgeOrphanedStorageFiles");
|
|
||||||
module.purgeOrphanedStorageFiles(callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
this.isActive = function (moduleName) {
|
|
||||||
return getModuleFromName(moduleName).active;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
this.resetAllSyncStates = function (syncState, includeUserFiles, includeGroupFiles) {
|
this.resetAllSyncStates = function (syncState, includeUserFiles, includeGroupFiles) {
|
||||||
if (!includeUserFiles && !includeGroupFiles) {
|
if (!includeUserFiles && !includeGroupFiles) {
|
||||||
includeUserFiles = true;
|
includeUserFiles = true;
|
||||||
|
@ -922,12 +890,12 @@ Zotero.Sync.Storage = new function () {
|
||||||
//
|
//
|
||||||
// Private methods
|
// Private methods
|
||||||
//
|
//
|
||||||
function getModuleFromName(moduleName) {
|
function getModeFromName(modeName) {
|
||||||
return new Zotero.Sync.Storage.Module(moduleName);
|
return Zotero.Sync.Storage[modeName];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getModuleFromLibrary(libraryID) {
|
function getModeFromLibrary(libraryID) {
|
||||||
if (libraryID === undefined) {
|
if (libraryID === undefined) {
|
||||||
throw new Error("libraryID not provided");
|
throw new Error("libraryID not provided");
|
||||||
}
|
}
|
||||||
|
@ -942,10 +910,10 @@ Zotero.Sync.Storage = new function () {
|
||||||
var protocol = Zotero.Prefs.get('sync.storage.protocol');
|
var protocol = Zotero.Prefs.get('sync.storage.protocol');
|
||||||
switch (protocol) {
|
switch (protocol) {
|
||||||
case 'zotero':
|
case 'zotero':
|
||||||
return getModuleFromName('ZFS');
|
return getModeFromName('ZFS');
|
||||||
|
|
||||||
case 'webdav':
|
case 'webdav':
|
||||||
return getModuleFromName('WebDAV');
|
return getModeFromName('WebDAV');
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Error("Invalid storage protocol '" + protocol + "'");
|
throw new Error("Invalid storage protocol '" + protocol + "'");
|
||||||
|
@ -958,7 +926,7 @@ Zotero.Sync.Storage = new function () {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return getModuleFromName('ZFS');
|
return getModeFromName('ZFS');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -968,13 +936,13 @@ Zotero.Sync.Storage = new function () {
|
||||||
*
|
*
|
||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
*/
|
*/
|
||||||
function _downloadFiles(module) {
|
function _downloadFiles(mode) {
|
||||||
if (!_syncInProgress) {
|
if (!_syncInProgress) {
|
||||||
_syncInProgress = true;
|
_syncInProgress = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var includeUserFiles = module.includeUserFiles && Zotero.Sync.Storage.downloadOnSync();
|
var includeUserFiles = mode.includeUserFiles && Zotero.Sync.Storage.downloadOnSync();
|
||||||
var includeGroupFiles = module.includeGroupFiles && Zotero.Sync.Storage.downloadOnSync('groups');
|
var includeGroupFiles = mode.includeGroupFiles && Zotero.Sync.Storage.downloadOnSync('groups');
|
||||||
|
|
||||||
if (!includeUserFiles && !includeGroupFiles) {
|
if (!includeUserFiles && !includeGroupFiles) {
|
||||||
Zotero.debug("No libraries are enabled for on-sync downloading");
|
Zotero.debug("No libraries are enabled for on-sync downloading");
|
||||||
|
@ -1005,7 +973,7 @@ Zotero.Sync.Storage = new function () {
|
||||||
item.libraryID + '/' + item.key,
|
item.libraryID + '/' + item.key,
|
||||||
{
|
{
|
||||||
onStart: function (request) {
|
onStart: function (request) {
|
||||||
module.downloadFile(request);
|
mode.downloadFile(request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -1021,12 +989,12 @@ Zotero.Sync.Storage = new function () {
|
||||||
*
|
*
|
||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
*/
|
*/
|
||||||
function _uploadFiles(module) {
|
function _uploadFiles(mode) {
|
||||||
if (!_syncInProgress) {
|
if (!_syncInProgress) {
|
||||||
_syncInProgress = true;
|
_syncInProgress = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var uploadFileIDs = _getFilesToUpload(module.includeUserFiles, module.includeGroupFiles);
|
var uploadFileIDs = _getFilesToUpload(mode.includeUserFiles, mode.includeGroupFiles);
|
||||||
if (!uploadFileIDs) {
|
if (!uploadFileIDs) {
|
||||||
Zotero.debug("No files to upload");
|
Zotero.debug("No files to upload");
|
||||||
return false;
|
return false;
|
||||||
|
@ -1044,7 +1012,7 @@ Zotero.Sync.Storage = new function () {
|
||||||
item.libraryID + '/' + item.key,
|
item.libraryID + '/' + item.key,
|
||||||
{
|
{
|
||||||
onStart: function (request) {
|
onStart: function (request) {
|
||||||
module.uploadFile(request);
|
mode.uploadFile(request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -1688,7 +1656,7 @@ Zotero.Sync.Storage = new function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function registerDefaultObserver(moduleName) {
|
function registerDefaultObserver(modeName) {
|
||||||
var finish = function (cancelled, skipSuccessFile) {
|
var finish = function (cancelled, skipSuccessFile) {
|
||||||
// Upload success file when done
|
// Upload success file when done
|
||||||
if (!_resyncOnFinish && !skipSuccessFile) {
|
if (!_resyncOnFinish && !skipSuccessFile) {
|
||||||
|
@ -1698,20 +1666,20 @@ Zotero.Sync.Storage = new function () {
|
||||||
var uploadQueue = Zotero.Sync.Storage.QueueManager.get('upload', true);
|
var uploadQueue = Zotero.Sync.Storage.QueueManager.get('upload', true);
|
||||||
var useLastSyncTime = !uploadQueue || (!cancelled && uploadQueue.lastTotalRequests == 0);
|
var useLastSyncTime = !uploadQueue || (!cancelled && uploadQueue.lastTotalRequests == 0);
|
||||||
|
|
||||||
getModuleFromName(moduleName).setLastSyncTime(function () {
|
getModeFromName(modeName).setLastSyncTime(function () {
|
||||||
finish(cancelled, true);
|
finish(cancelled, true);
|
||||||
}, useLastSyncTime);
|
}, useLastSyncTime);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.debug(moduleName + " sync is complete");
|
Zotero.debug(modeName + " sync is complete");
|
||||||
|
|
||||||
_syncInProgress = false;
|
_syncInProgress = false;
|
||||||
|
|
||||||
if (_resyncOnFinish) {
|
if (_resyncOnFinish) {
|
||||||
Zotero.debug("Force-resyncing items in conflict");
|
Zotero.debug("Force-resyncing items in conflict");
|
||||||
_resyncOnFinish = false;
|
_resyncOnFinish = false;
|
||||||
Zotero.Sync.Storage.sync(moduleName);
|
Zotero.Sync.Storage.sync(modeName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,7 @@ Zotero.Sync.Storage.EventManager = (function () {
|
||||||
var queues = Zotero.Sync.Storage.QueueManager.getAll();
|
var queues = Zotero.Sync.Storage.QueueManager.getAll();
|
||||||
for each(var queue in queues) {
|
for each(var queue in queues) {
|
||||||
if (queue.isRunning()) {
|
if (queue.isRunning()) {
|
||||||
Zotero.debug(queue[0].toUpperCase() + queue.substr(1)
|
Zotero.debug(queue.name[0].toUpperCase() + queue.name.substr(1)
|
||||||
+ " queue not empty -- not clearing storage sync event observers");
|
+ " queue not empty -- not clearing storage sync event observers");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
184
chrome/content/zotero/xpcom/storage/mode.js
Normal file
184
chrome/content/zotero/xpcom/storage/mode.js
Normal file
|
@ -0,0 +1,184 @@
|
||||||
|
/*
|
||||||
|
***** BEGIN LICENSE BLOCK *****
|
||||||
|
|
||||||
|
Copyright © 2009 Center for History and New Media
|
||||||
|
George Mason University, Fairfax, Virginia, USA
|
||||||
|
http://zotero.org
|
||||||
|
|
||||||
|
This file is part of Zotero.
|
||||||
|
|
||||||
|
Zotero is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Zotero is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
***** END LICENSE BLOCK *****
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
Zotero.Sync.Storage.Mode = function () {};
|
||||||
|
|
||||||
|
Zotero.Sync.Storage.Mode.prototype.__defineGetter__('enabled', function () {
|
||||||
|
try {
|
||||||
|
return this._enabled;
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.Sync.Storage.EventManager.error(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Zotero.Sync.Storage.Mode.prototype.__defineGetter__('verified', function () {
|
||||||
|
try {
|
||||||
|
return this._verified;
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.Sync.Storage.EventManager.error(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Zotero.Sync.Storage.Mode.prototype.__defineGetter__('active', function () {
|
||||||
|
try {
|
||||||
|
return this._enabled && this._verified && this._initFromPrefs();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.Sync.Storage.EventManager.error(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Zotero.Sync.Storage.Mode.prototype.__defineGetter__('username', function () {
|
||||||
|
try {
|
||||||
|
return this._username;
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.Sync.Storage.EventManager.error(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Zotero.Sync.Storage.Mode.prototype.__defineGetter__('password', function () {
|
||||||
|
try {
|
||||||
|
return this._password;
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.Sync.Storage.EventManager.error(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Zotero.Sync.Storage.Mode.prototype.__defineSetter__('password', function (val) {
|
||||||
|
try {
|
||||||
|
this._password = val;
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.Sync.Storage.EventManager.error(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Zotero.Sync.Storage.Mode.prototype.init = function () {
|
||||||
|
try {
|
||||||
|
return this._init();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.Sync.Storage.EventManager.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Zotero.Sync.Storage.Mode.prototype.initFromPrefs = function () {
|
||||||
|
try {
|
||||||
|
return this._initFromPrefs();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.Sync.Storage.EventManager.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Zotero.Sync.Storage.Mode.prototype.sync = function (observer) {
|
||||||
|
Zotero.Sync.Storage.sync(this.name, observer);
|
||||||
|
}
|
||||||
|
|
||||||
|
Zotero.Sync.Storage.Mode.prototype.downloadFile = function (request) {
|
||||||
|
try {
|
||||||
|
this._downloadFile(request);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.Sync.Storage.EventManager.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Zotero.Sync.Storage.Mode.prototype.uploadFile = function (request) {
|
||||||
|
try {
|
||||||
|
this._uploadFile(request);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.Sync.Storage.EventManager.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Zotero.Sync.Storage.Mode.prototype.getLastSyncTime = function (callback) {
|
||||||
|
try {
|
||||||
|
this._getLastSyncTime(callback);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.Sync.Storage.EventManager.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Zotero.Sync.Storage.Mode.prototype.setLastSyncTime = function (callback, useLastSyncTime) {
|
||||||
|
try {
|
||||||
|
this._setLastSyncTime(callback, useLastSyncTime);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.Sync.Storage.EventManager.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Zotero.Sync.Storage.Mode.prototype.checkServer = function (callback) {
|
||||||
|
try {
|
||||||
|
return this._checkServer(callback);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.Sync.Storage.EventManager.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Zotero.Sync.Storage.Mode.prototype.checkServerCallback = function (uri, status, window, skipSuccessMessage) {
|
||||||
|
try {
|
||||||
|
return this._checkServerCallback(uri, status, window, skipSuccessMessage);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.Sync.Storage.EventManager.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Zotero.Sync.Storage.Mode.prototype.cacheCredentials = function (callback) {
|
||||||
|
try {
|
||||||
|
return this._cacheCredentials(callback);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.Sync.Storage.EventManager.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Zotero.Sync.Storage.Mode.prototype.purgeDeletedStorageFiles = function (callback) {
|
||||||
|
try {
|
||||||
|
this._purgeDeletedStorageFiles(callback);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.Sync.Storage.EventManager.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Zotero.Sync.Storage.Mode.prototype.purgeOrphanedStorageFiles = function (callback) {
|
||||||
|
try {
|
||||||
|
this._purgeOrphanedStorageFiles(callback);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.Sync.Storage.EventManager.error(e);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,198 +0,0 @@
|
||||||
/*
|
|
||||||
***** BEGIN LICENSE BLOCK *****
|
|
||||||
|
|
||||||
Copyright © 2009 Center for History and New Media
|
|
||||||
George Mason University, Fairfax, Virginia, USA
|
|
||||||
http://zotero.org
|
|
||||||
|
|
||||||
This file is part of Zotero.
|
|
||||||
|
|
||||||
Zotero is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
Zotero is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
***** END LICENSE BLOCK *****
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module = function (moduleName) {
|
|
||||||
switch (moduleName) {
|
|
||||||
case 'ZFS':
|
|
||||||
this._module = Zotero.Sync.Storage.Module.ZFS;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'WebDAV':
|
|
||||||
this._module = Zotero.Sync.Storage.Module.WebDAV;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw ("Invalid storage session module '" + moduleName + "'");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module.prototype.__defineGetter__('name', function () this._module.name);
|
|
||||||
Zotero.Sync.Storage.Module.prototype.__defineGetter__('includeUserFiles', function () this._module.includeUserFiles);
|
|
||||||
Zotero.Sync.Storage.Module.prototype.__defineGetter__('includeGroupFiles', function () this._module.includeGroupFiles);
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module.prototype.__defineGetter__('enabled', function () {
|
|
||||||
try {
|
|
||||||
return this._module.enabled;
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
Zotero.Sync.Storage.EventManager.error(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module.prototype.__defineGetter__('verified', function () {
|
|
||||||
try {
|
|
||||||
return this._module.verified;
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
Zotero.Sync.Storage.EventManager.error(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module.prototype.__defineGetter__('active', function () {
|
|
||||||
try {
|
|
||||||
return this._module.enabled && this._module.initFromPrefs() && this._module.verified;
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
Zotero.Sync.Storage.EventManager.error(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module.prototype.__defineGetter__('username', function () {
|
|
||||||
try {
|
|
||||||
return this._module.username;
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
Zotero.Sync.Storage.EventManager.error(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module.prototype.__defineGetter__('password', function () {
|
|
||||||
try {
|
|
||||||
return this._module.password;
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
Zotero.Sync.Storage.EventManager.error(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module.prototype.__defineSetter__('password', function (val) {
|
|
||||||
try {
|
|
||||||
this._module.password = val;
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
Zotero.Sync.Storage.EventManager.error(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module.prototype.init = function () {
|
|
||||||
try {
|
|
||||||
return this._module.init();
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
Zotero.Sync.Storage.EventManager.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module.prototype.initFromPrefs = function () {
|
|
||||||
try {
|
|
||||||
return this._module.initFromPrefs();
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
Zotero.Sync.Storage.EventManager.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module.prototype.downloadFile = function (request) {
|
|
||||||
try {
|
|
||||||
this._module.downloadFile(request);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
Zotero.Sync.Storage.EventManager.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module.prototype.uploadFile = function (request) {
|
|
||||||
try {
|
|
||||||
this._module.uploadFile(request);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
Zotero.Sync.Storage.EventManager.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module.prototype.getLastSyncTime = function (callback) {
|
|
||||||
try {
|
|
||||||
this._module.getLastSyncTime(callback);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
Zotero.Sync.Storage.EventManager.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module.prototype.setLastSyncTime = function (callback, useLastSyncTime) {
|
|
||||||
try {
|
|
||||||
this._module.setLastSyncTime(callback, useLastSyncTime);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
Zotero.Sync.Storage.EventManager.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module.prototype.checkServer = function (callback) {
|
|
||||||
try {
|
|
||||||
return this._module.checkServer(callback);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
Zotero.Sync.Storage.EventManager.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module.prototype.checkServerCallback = function (uri, status, window, skipSuccessMessage) {
|
|
||||||
try {
|
|
||||||
return this._module.checkServerCallback(uri, status, window, skipSuccessMessage);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
Zotero.Sync.Storage.EventManager.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module.prototype.cacheCredentials = function (callback) {
|
|
||||||
try {
|
|
||||||
return this._module.cacheCredentials(callback);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
Zotero.Sync.Storage.EventManager.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module.prototype.purgeDeletedStorageFiles = function (callback) {
|
|
||||||
try {
|
|
||||||
this._module.purgeDeletedStorageFiles(callback);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
Zotero.Sync.Storage.EventManager.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module.prototype.purgeOrphanedStorageFiles = function (callback) {
|
|
||||||
try {
|
|
||||||
this._module.purgeOrphanedStorageFiles(callback);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
Zotero.Sync.Storage.EventManager.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -24,7 +24,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module.WebDAV = (function () {
|
Zotero.Sync.Storage.WebDAV = (function () {
|
||||||
// TEMP
|
// TEMP
|
||||||
// TODO: localize
|
// TODO: localize
|
||||||
var _defaultError = "A WebDAV file sync error occurred. Please try syncing again.\n\nIf you receive this message repeatedly, check your WebDAV server settings in the Sync pane of the Zotero preferences.";
|
var _defaultError = "A WebDAV file sync error occurred. Please try syncing again.\n\nIf you receive this message repeatedly, check your WebDAV server settings in the Sync pane of the Zotero preferences.";
|
||||||
|
@ -387,7 +387,7 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
* Create a Zotero directory on the storage server
|
* Create a Zotero directory on the storage server
|
||||||
*/
|
*/
|
||||||
function createServerDirectory(callback) {
|
function createServerDirectory(callback) {
|
||||||
var uri = Zotero.Sync.Storage.Module.WebDAV.rootURI;
|
var uri = Zotero.Sync.Storage.WebDAV.rootURI;
|
||||||
Zotero.HTTP.WebDAV.doMkCol(uri, function (req) {
|
Zotero.HTTP.WebDAV.doMkCol(uri, function (req) {
|
||||||
Zotero.debug(req.responseText);
|
Zotero.debug(req.responseText);
|
||||||
Zotero.debug(req.status);
|
Zotero.debug(req.status);
|
||||||
|
@ -429,7 +429,7 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
* @return {nsIURI} URI of file on storage server
|
* @return {nsIURI} URI of file on storage server
|
||||||
*/
|
*/
|
||||||
function getItemURI(item) {
|
function getItemURI(item) {
|
||||||
var uri = Zotero.Sync.Storage.Module.WebDAV.rootURI;
|
var uri = Zotero.Sync.Storage.WebDAV.rootURI;
|
||||||
uri.spec = uri.spec + item.key + '.zip';
|
uri.spec = uri.spec + item.key + '.zip';
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
@ -443,7 +443,7 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
* @return {nsIURI} URI of property file on storage server
|
* @return {nsIURI} URI of property file on storage server
|
||||||
*/
|
*/
|
||||||
function getItemPropertyURI(item) {
|
function getItemPropertyURI(item) {
|
||||||
var uri = Zotero.Sync.Storage.Module.WebDAV.rootURI;
|
var uri = Zotero.Sync.Storage.WebDAV.rootURI;
|
||||||
uri.spec = uri.spec + item.key + '.prop';
|
uri.spec = uri.spec + item.key + '.prop';
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
@ -670,31 +670,37 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return {
|
//
|
||||||
name: "WebDAV",
|
// Public methods (called via Zotero.Sync.Storage.WebDAV)
|
||||||
|
//
|
||||||
|
var obj = new Zotero.Sync.Storage.Mode;
|
||||||
|
obj.name = "WebDAV";
|
||||||
|
|
||||||
get includeUserFiles() {
|
Object.defineProperty(obj, "includeUserFiles", {
|
||||||
|
get: function () {
|
||||||
return Zotero.Prefs.get("sync.storage.enabled") && Zotero.Prefs.get("sync.storage.protocol") == 'webdav';
|
return Zotero.Prefs.get("sync.storage.enabled") && Zotero.Prefs.get("sync.storage.protocol") == 'webdav';
|
||||||
},
|
}
|
||||||
includeGroupItems: false,
|
});
|
||||||
|
obj.includeGroupItems = false;
|
||||||
|
|
||||||
get enabled() {
|
Object.defineProperty(obj, "_enabled", {
|
||||||
return this.includeUserFiles;
|
get: function () this.includeUserFiles
|
||||||
},
|
});
|
||||||
|
|
||||||
get verified() {
|
Object.defineProperty(obj, "_verified", {
|
||||||
return Zotero.Prefs.get("sync.storage.verified");
|
get: function () Zotero.Prefs.get("sync.storage.verified")
|
||||||
},
|
});
|
||||||
|
|
||||||
get username() {
|
Object.defineProperty(obj, "_username", {
|
||||||
return Zotero.Prefs.get('sync.storage.username');
|
get: function () Zotero.Prefs.get('sync.storage.username')
|
||||||
},
|
});
|
||||||
|
|
||||||
get password() {
|
Object.defineProperty(obj, "_password", {
|
||||||
var username = this.username;
|
get: function () {
|
||||||
|
var username = this._username;
|
||||||
|
|
||||||
if (!username) {
|
if (!username) {
|
||||||
Zotero.debug('Username not set before getting Zotero.Sync.Storage.Module.WebDAV.password');
|
Zotero.debug('Username not set before getting Zotero.Sync.Storage.WebDAV.password');
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -713,10 +719,10 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
|
|
||||||
set password(password) {
|
set: function (password) {
|
||||||
var username = this.username;
|
var username = this._username;
|
||||||
if (!username) {
|
if (!username) {
|
||||||
Zotero.debug('Username not set before setting Zotero.Sync.Server.Module.WebDAV.password');
|
Zotero.debug('Username not set before setting Zotero.Sync.Server.Mode.WebDAV.password');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -740,24 +746,28 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
null, username, password, "", "");
|
null, username, password, "", "");
|
||||||
loginManager.addLogin(loginInfo);
|
loginManager.addLogin(loginInfo);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
});
|
||||||
|
|
||||||
get rootURI() {
|
Object.defineProperty(obj, "rootURI", {
|
||||||
|
get: function () {
|
||||||
if (!_rootURI) {
|
if (!_rootURI) {
|
||||||
throw new Error("Root URI not initialized");
|
throw new Error("Root URI not initialized");
|
||||||
}
|
}
|
||||||
return _rootURI.clone();
|
return _rootURI.clone();
|
||||||
},
|
}
|
||||||
|
});
|
||||||
|
|
||||||
get parentURI() {
|
Object.defineProperty(obj, "parentURI", {
|
||||||
|
get: function () {
|
||||||
if (!_parentURI) {
|
if (!_parentURI) {
|
||||||
throw new Error("Parent URI not initialized");
|
throw new Error("Parent URI not initialized");
|
||||||
}
|
}
|
||||||
return _parentURI.clone();
|
return _parentURI.clone();
|
||||||
},
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
obj._init = function (url, dir, username, password) {
|
||||||
init: function (url, dir, username, password) {
|
|
||||||
if (!url) {
|
if (!url) {
|
||||||
var msg = "WebDAV URL not provided";
|
var msg = "WebDAV URL not provided";
|
||||||
Zotero.debug(msg);
|
Zotero.debug(msg);
|
||||||
|
@ -803,10 +813,10 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
uri.spec += "zotero/";
|
uri.spec += "zotero/";
|
||||||
_rootURI = uri;
|
_rootURI = uri;
|
||||||
return true;
|
return true;
|
||||||
},
|
};
|
||||||
|
|
||||||
|
|
||||||
initFromPrefs: function () {
|
obj._initFromPrefs = function () {
|
||||||
var scheme = Zotero.Prefs.get('sync.storage.scheme');
|
var scheme = Zotero.Prefs.get('sync.storage.scheme');
|
||||||
switch (scheme) {
|
switch (scheme) {
|
||||||
case 'http':
|
case 'http':
|
||||||
|
@ -824,11 +834,11 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
|
|
||||||
url = scheme + '://' + url;
|
url = scheme + '://' + url;
|
||||||
var dir = "zotero";
|
var dir = "zotero";
|
||||||
var username = this.username;
|
var username = this._username;
|
||||||
var password = this.password;
|
var password = this._password;
|
||||||
|
|
||||||
return this.init(url, dir, username, password);
|
return this._init(url, dir, username, password);
|
||||||
},
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -836,7 +846,7 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
*
|
*
|
||||||
* @param {Zotero.Sync.Storage.Request} [request]
|
* @param {Zotero.Sync.Storage.Request} [request]
|
||||||
*/
|
*/
|
||||||
downloadFile: function (request) {
|
obj._downloadFile = function (request) {
|
||||||
var item = Zotero.Sync.Storage.getItemFromRequestName(request.name);
|
var item = Zotero.Sync.Storage.getItemFromRequestName(request.name);
|
||||||
if (!item) {
|
if (!item) {
|
||||||
throw new Error("Item '" + request.name + "' not found");
|
throw new Error("Item '" + request.name + "' not found");
|
||||||
|
@ -910,7 +920,7 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
else if (status != 200) {
|
else if (status != 200) {
|
||||||
var msg = "Unexpected status code " + status
|
var msg = "Unexpected status code " + status
|
||||||
+ " for request " + data.request.name
|
+ " for request " + data.request.name
|
||||||
+ " in Zotero.Sync.Storage.Module.WebDAV.downloadFile()";
|
+ " in Zotero.Sync.Storage.WebDAV.downloadFile()";
|
||||||
Zotero.debug(msg, 1);
|
Zotero.debug(msg, 1);
|
||||||
Components.utils.reportError(msg);
|
Components.utils.reportError(msg);
|
||||||
Zotero.Sync.Storage.EventManager.error(_defaultError);
|
Zotero.Sync.Storage.EventManager.error(_defaultError);
|
||||||
|
@ -958,18 +968,18 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
request.error(e);
|
request.error(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
|
||||||
|
|
||||||
uploadFile: function (request) {
|
obj._uploadFile = function (request) {
|
||||||
Zotero.Sync.Storage.createUploadFile(request, function (data) { processUploadFile(data); });
|
Zotero.Sync.Storage.createUploadFile(request, function (data) { processUploadFile(data); });
|
||||||
},
|
};
|
||||||
|
|
||||||
|
|
||||||
getLastSyncTime: function (callback) {
|
obj._getLastSyncTime = function (callback) {
|
||||||
// Cache the credentials at the root URI
|
// Cache the credentials at the root URI
|
||||||
var self = this;
|
var self = this;
|
||||||
this.cacheCredentials(function () {
|
this._cacheCredentials(function () {
|
||||||
try {
|
try {
|
||||||
var uri = this.rootURI;
|
var uri = this.rootURI;
|
||||||
var successFileURI = uri.clone();
|
var successFileURI = uri.clone();
|
||||||
|
@ -989,7 +999,7 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
|
|
||||||
if (req.status != 200 && req.status != 404) {
|
if (req.status != 200 && req.status != 404) {
|
||||||
var msg = "Unexpected status code " + req.status + " for HEAD request "
|
var msg = "Unexpected status code " + req.status + " for HEAD request "
|
||||||
+ "in Zotero.Sync.Storage.Module.WebDAV.getLastSyncTime()";
|
+ "in Zotero.Sync.Storage.WebDAV.getLastSyncTime()";
|
||||||
Zotero.debug(msg, 1);
|
Zotero.debug(msg, 1);
|
||||||
Components.utils.reportError(msg);
|
Components.utils.reportError(msg);
|
||||||
Zotero.Sync.Storage.EventManager.error(_defaultError);
|
Zotero.Sync.Storage.EventManager.error(_defaultError);
|
||||||
|
@ -1021,10 +1031,10 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
Zotero.Sync.Storage.EventManager.error(_defaultError);
|
Zotero.Sync.Storage.EventManager.error(_defaultError);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
|
||||||
|
|
||||||
setLastSyncTime: function (callback) {
|
obj._setLastSyncTime = function (callback) {
|
||||||
try {
|
try {
|
||||||
var uri = this.rootURI;
|
var uri = this.rootURI;
|
||||||
var successFileURI = uri.clone();
|
var successFileURI = uri.clone();
|
||||||
|
@ -1066,10 +1076,10 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
|
||||||
|
|
||||||
cacheCredentials: function (callback) {
|
obj._cacheCredentials = function (callback) {
|
||||||
if (_cachedCredentials) {
|
if (_cachedCredentials) {
|
||||||
Zotero.debug("Credentials are already cached");
|
Zotero.debug("Credentials are already cached");
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
@ -1083,7 +1093,7 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
|
|
||||||
if (req.status != 200) {
|
if (req.status != 200) {
|
||||||
var msg = "Unexpected status code " + req.status + " for OPTIONS request "
|
var msg = "Unexpected status code " + req.status + " for OPTIONS request "
|
||||||
+ "in Zotero.Sync.Storage.Module.WebDAV.getLastSyncTime()";
|
+ "in Zotero.Sync.Storage.WebDAV.getLastSyncTime()";
|
||||||
Zotero.debug(msg, 1);
|
Zotero.debug(msg, 1);
|
||||||
Components.utils.reportError(msg);
|
Components.utils.reportError(msg);
|
||||||
Zotero.Sync.Storage.EventManager.error(_defaultErrorRestart);
|
Zotero.Sync.Storage.EventManager.error(_defaultErrorRestart);
|
||||||
|
@ -1093,15 +1103,15 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
},
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Function} callback Function to pass URI and result value to
|
* @param {Function} callback Function to pass URI and result value to
|
||||||
* @param {Object} errorCallbacks
|
* @param {Object} errorCallbacks
|
||||||
*/
|
*/
|
||||||
checkServer: function (callback) {
|
obj._checkServer = function (callback) {
|
||||||
this.initFromPrefs();
|
this._initFromPrefs();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var parentURI = this.parentURI;
|
var parentURI = this.parentURI;
|
||||||
|
@ -1218,10 +1228,7 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
switch (req.status) {
|
switch (req.status) {
|
||||||
case 200: // IIS 5.1 and Sakai return 200
|
case 200: // IIS 5.1 and Sakai return 200
|
||||||
case 204:
|
case 204:
|
||||||
callback(
|
callback(uri, Zotero.Sync.Storage.SUCCESS);
|
||||||
uri,
|
|
||||||
Zotero.Sync.Storage.SUCCESS
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case 401:
|
case 401:
|
||||||
|
@ -1308,7 +1315,7 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
|
|
||||||
// Zotero directory wasn't found, so see if at least
|
// Zotero directory wasn't found, so see if at least
|
||||||
// the parent directory exists
|
// the parent directory exists
|
||||||
Zotero.HTTP.WebDAV.doProp("PROPFIND", this.parentURI, xmlstr,
|
Zotero.HTTP.WebDAV.doProp("PROPFIND", parentURI, xmlstr,
|
||||||
function (req) {
|
function (req) {
|
||||||
Zotero.debug(req.responseText);
|
Zotero.debug(req.responseText);
|
||||||
Zotero.debug(req.status);
|
Zotero.debug(req.status);
|
||||||
|
@ -1356,10 +1363,10 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
|
|
||||||
requestHolder.request = request;
|
requestHolder.request = request;
|
||||||
return requestHolder;
|
return requestHolder;
|
||||||
},
|
};
|
||||||
|
|
||||||
|
|
||||||
checkServerCallback: function (uri, status, window, skipSuccessMessage) {
|
obj._checkServerCallback = function (uri, status, window, skipSuccessMessage) {
|
||||||
var promptService =
|
var promptService =
|
||||||
Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
|
Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
|
||||||
createInstance(Components.interfaces.nsIPromptService);
|
createInstance(Components.interfaces.nsIPromptService);
|
||||||
|
@ -1498,7 +1505,7 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
promptService.alert(window, errorTitle, errorMessage);
|
promptService.alert(window, errorTitle, errorMessage);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1507,8 +1514,8 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
*
|
*
|
||||||
* @param {Function} callback Passed number of files deleted
|
* @param {Function} callback Passed number of files deleted
|
||||||
*/
|
*/
|
||||||
purgeDeletedStorageFiles: function (callback) {
|
obj._purgeDeletedStorageFiles = function (callback) {
|
||||||
if (!this.active) {
|
if (!this._active) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1554,7 +1561,7 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
|
|
||||||
Zotero.Sync.Storage.EventManager.success();
|
Zotero.Sync.Storage.EventManager.success();
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1562,10 +1569,10 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
*
|
*
|
||||||
* @param {Function} callback
|
* @param {Function} callback
|
||||||
*/
|
*/
|
||||||
purgeOrphanedStorageFiles: function (callback) {
|
obj._purgeOrphanedStorageFiles = function (callback) {
|
||||||
const daysBeforeSyncTime = 1;
|
const daysBeforeSyncTime = 1;
|
||||||
|
|
||||||
if (!this.active) {
|
if (!this._active) {
|
||||||
Zotero.Sync.Storage.EventManager.skip();
|
Zotero.Sync.Storage.EventManager.skip();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1689,6 +1696,7 @@ Zotero.Sync.Storage.Module.WebDAV = (function () {
|
||||||
Zotero.Sync.Storage.EventManager.success();
|
Zotero.Sync.Storage.EventManager.success();
|
||||||
});
|
});
|
||||||
}, { Depth: 1 });
|
}, { Depth: 1 });
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return obj;
|
||||||
}());
|
}());
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
Zotero.Sync.Storage.Module.ZFS = (function () {
|
Zotero.Sync.Storage.ZFS = (function () {
|
||||||
var _rootURI;
|
var _rootURI;
|
||||||
var _userURI;
|
var _userURI;
|
||||||
var _cachedCredentials = false;
|
var _cachedCredentials = false;
|
||||||
|
@ -40,7 +40,7 @@ Zotero.Sync.Storage.Module.ZFS = (function () {
|
||||||
var uri = getItemInfoURI(item);
|
var uri = getItemInfoURI(item);
|
||||||
|
|
||||||
Zotero.HTTP.doGet(uri, function (req) {
|
Zotero.HTTP.doGet(uri, function (req) {
|
||||||
var funcName = "Zotero.Sync.Storage.Module.ZFS.getStorageFileInfo()";
|
var funcName = "Zotero.Sync.Storage.ZFS.getStorageFileInfo()";
|
||||||
|
|
||||||
if (req.status == 404) {
|
if (req.status == 404) {
|
||||||
callback(item, false);
|
callback(item, false);
|
||||||
|
@ -237,7 +237,7 @@ Zotero.Sync.Storage.Module.ZFS = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.HTTP.doPost(uri, body, function (req) {
|
Zotero.HTTP.doPost(uri, body, function (req) {
|
||||||
var funcName = "Zotero.Sync.Storage.Module.ZFS.getFileUploadParameters()";
|
var funcName = "Zotero.Sync.Storage.ZFS.getFileUploadParameters()";
|
||||||
|
|
||||||
if (req.status == 413) {
|
if (req.status == 413) {
|
||||||
var retry = req.getResponseHeader('Retry-After');
|
var retry = req.getResponseHeader('Retry-After');
|
||||||
|
@ -597,7 +597,7 @@ Zotero.Sync.Storage.Module.ZFS = (function () {
|
||||||
* @return {nsIURI} URI of file on storage server
|
* @return {nsIURI} URI of file on storage server
|
||||||
*/
|
*/
|
||||||
function getItemURI(item) {
|
function getItemURI(item) {
|
||||||
var uri = Zotero.Sync.Storage.Module.ZFS.rootURI;
|
var uri = Zotero.Sync.Storage.ZFS.rootURI;
|
||||||
// Be sure to mirror parameter changes to getItemInfoURI() below
|
// Be sure to mirror parameter changes to getItemInfoURI() below
|
||||||
uri.spec += Zotero.URI.getItemPath(item) + '/file?auth=1&iskey=1&version=1';
|
uri.spec += Zotero.URI.getItemPath(item) + '/file?auth=1&iskey=1&version=1';
|
||||||
return uri;
|
return uri;
|
||||||
|
@ -612,7 +612,7 @@ Zotero.Sync.Storage.Module.ZFS = (function () {
|
||||||
* @return {nsIURI} URI of file on storage server with info flag
|
* @return {nsIURI} URI of file on storage server with info flag
|
||||||
*/
|
*/
|
||||||
function getItemInfoURI(item) {
|
function getItemInfoURI(item) {
|
||||||
var uri = Zotero.Sync.Storage.Module.ZFS.rootURI;
|
var uri = Zotero.Sync.Storage.ZFS.rootURI;
|
||||||
uri.spec += Zotero.URI.getItemPath(item) + '/file?auth=1&iskey=1&version=1&info=1';
|
uri.spec += Zotero.URI.getItemPath(item) + '/file?auth=1&iskey=1&version=1&info=1';
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
@ -631,41 +631,50 @@ Zotero.Sync.Storage.Module.ZFS = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return {
|
//
|
||||||
name: "ZFS",
|
// Public methods (called via Zotero.Sync.Storage.ZFS)
|
||||||
|
//
|
||||||
|
var obj = new Zotero.Sync.Storage.Mode;
|
||||||
|
obj.name = "ZFS";
|
||||||
|
|
||||||
get includeUserFiles() {
|
Object.defineProperty(obj, "includeUserFiles", {
|
||||||
|
get: function () {
|
||||||
return Zotero.Prefs.get("sync.storage.enabled") && Zotero.Prefs.get("sync.storage.protocol") == 'zotero';
|
return Zotero.Prefs.get("sync.storage.enabled") && Zotero.Prefs.get("sync.storage.protocol") == 'zotero';
|
||||||
},
|
}
|
||||||
|
});
|
||||||
|
|
||||||
get includeGroupFiles() {
|
Object.defineProperty(obj, "includeGroupFiles", {
|
||||||
|
get: function () {
|
||||||
return Zotero.Prefs.get("sync.storage.groups.enabled");
|
return Zotero.Prefs.get("sync.storage.groups.enabled");
|
||||||
},
|
}
|
||||||
|
});
|
||||||
|
|
||||||
get enabled() {
|
Object.defineProperty(obj, "_enabled", {
|
||||||
return this.includeUserFiles || this.includeGroupFiles;
|
get: function () this.includeUserFiles || this.includeGroupFiles
|
||||||
},
|
});
|
||||||
|
|
||||||
get verified() {
|
obj._verified = true;
|
||||||
return true;
|
|
||||||
},
|
|
||||||
|
|
||||||
get rootURI() {
|
Object.defineProperty(obj, "rootURI", {
|
||||||
|
get: function () {
|
||||||
if (!_rootURI) {
|
if (!_rootURI) {
|
||||||
throw ("Root URI not initialized in Zotero.Sync.Storage.ZFS.rootURI");
|
throw ("Root URI not initialized in Zotero.Sync.Storage.ZFS.rootURI");
|
||||||
}
|
}
|
||||||
return _rootURI.clone();
|
return _rootURI.clone();
|
||||||
},
|
}
|
||||||
|
});
|
||||||
|
|
||||||
get userURI() {
|
Object.defineProperty(obj, "userURI", {
|
||||||
|
get: function () {
|
||||||
if (!_userURI) {
|
if (!_userURI) {
|
||||||
throw ("User URI not initialized in Zotero.Sync.Storage.ZFS.userURI");
|
throw ("User URI not initialized in Zotero.Sync.Storage.ZFS.userURI");
|
||||||
}
|
}
|
||||||
return _userURI.clone();
|
return _userURI.clone();
|
||||||
},
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
init: function (url, username, password) {
|
obj._init = function (url, username, password) {
|
||||||
var ios = Components.classes["@mozilla.org/network/io-service;1"].
|
var ios = Components.classes["@mozilla.org/network/io-service;1"].
|
||||||
getService(Components.interfaces.nsIIOService);
|
getService(Components.interfaces.nsIIOService);
|
||||||
try {
|
try {
|
||||||
|
@ -687,15 +696,15 @@ Zotero.Sync.Storage.Module.ZFS = (function () {
|
||||||
_userURI = uri;
|
_userURI = uri;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},
|
};
|
||||||
|
|
||||||
|
|
||||||
initFromPrefs: function () {
|
obj._initFromPrefs = function () {
|
||||||
var url = ZOTERO_CONFIG.API_URL;
|
var url = ZOTERO_CONFIG.API_URL;
|
||||||
var username = Zotero.Sync.Server.username;
|
var username = Zotero.Sync.Server.username;
|
||||||
var password = Zotero.Sync.Server.password;
|
var password = Zotero.Sync.Server.password;
|
||||||
return this.init(url, username, password);
|
return this._init(url, username, password);
|
||||||
},
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -703,7 +712,7 @@ Zotero.Sync.Storage.Module.ZFS = (function () {
|
||||||
*
|
*
|
||||||
* @param {Zotero.Sync.Storage.Request} [request]
|
* @param {Zotero.Sync.Storage.Request} [request]
|
||||||
*/
|
*/
|
||||||
downloadFile: function (request) {
|
obj._downloadFile = function (request) {
|
||||||
var item = Zotero.Sync.Storage.getItemFromRequestName(request.name);
|
var item = Zotero.Sync.Storage.getItemFromRequestName(request.name);
|
||||||
if (!item) {
|
if (!item) {
|
||||||
throw new Error("Item '" + request.name + "' not found");
|
throw new Error("Item '" + request.name + "' not found");
|
||||||
|
@ -807,7 +816,7 @@ Zotero.Sync.Storage.Module.ZFS = (function () {
|
||||||
if (status != 200) {
|
if (status != 200) {
|
||||||
var msg = "Unexpected status code " + status
|
var msg = "Unexpected status code " + status
|
||||||
+ " for request " + data.request.name
|
+ " for request " + data.request.name
|
||||||
+ " in Zotero.Sync.Storage.Module.ZFS.downloadFile()";
|
+ " in Zotero.Sync.Storage.ZFS.downloadFile()";
|
||||||
Zotero.debug(msg, 1);
|
Zotero.debug(msg, 1);
|
||||||
Components.utils.reportError(msg);
|
Components.utils.reportError(msg);
|
||||||
Zotero.Sync.Storage.EventManager.error(Zotero.Sync.Storage.defaultError);
|
Zotero.Sync.Storage.EventManager.error(Zotero.Sync.Storage.defaultError);
|
||||||
|
@ -858,10 +867,10 @@ Zotero.Sync.Storage.Module.ZFS = (function () {
|
||||||
Zotero.Sync.Storage.EventManager.error(e);
|
Zotero.Sync.Storage.EventManager.error(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
|
||||||
|
|
||||||
uploadFile: function (request) {
|
obj._uploadFile = function (request) {
|
||||||
var item = Zotero.Sync.Storage.getItemFromRequestName(request.name);
|
var item = Zotero.Sync.Storage.getItemFromRequestName(request.name);
|
||||||
if (Zotero.Attachments.getNumFiles(item) > 1) {
|
if (Zotero.Attachments.getNumFiles(item) > 1) {
|
||||||
Zotero.Sync.Storage.createUploadFile(request, function (data) { processUploadFile(data); });
|
Zotero.Sync.Storage.createUploadFile(request, function (data) { processUploadFile(data); });
|
||||||
|
@ -869,17 +878,17 @@ Zotero.Sync.Storage.Module.ZFS = (function () {
|
||||||
else {
|
else {
|
||||||
processUploadFile({ request: request });
|
processUploadFile({ request: request });
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
|
||||||
|
|
||||||
getLastSyncTime: function (callback) {
|
obj._getLastSyncTime = function (callback) {
|
||||||
var uri = this.userURI;
|
var uri = this.userURI;
|
||||||
var successFileURI = uri.clone();
|
var successFileURI = uri.clone();
|
||||||
successFileURI.spec += "laststoragesync?auth=1";
|
successFileURI.spec += "laststoragesync?auth=1";
|
||||||
|
|
||||||
// Cache the credentials at the root
|
// Cache the credentials at the root
|
||||||
var self = this;
|
var self = this;
|
||||||
this.cacheCredentials(function () {
|
this._cacheCredentials(function () {
|
||||||
Zotero.HTTP.doGet(successFileURI, function (req) {
|
Zotero.HTTP.doGet(successFileURI, function (req) {
|
||||||
if (req.responseText) {
|
if (req.responseText) {
|
||||||
Zotero.debug(req.responseText);
|
Zotero.debug(req.responseText);
|
||||||
|
@ -911,10 +920,10 @@ Zotero.Sync.Storage.Module.ZFS = (function () {
|
||||||
callback(ts);
|
callback(ts);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
|
||||||
|
|
||||||
setLastSyncTime: function (callback, useLastSyncTime) {
|
obj._setLastSyncTime = function (callback, useLastSyncTime) {
|
||||||
if (useLastSyncTime) {
|
if (useLastSyncTime) {
|
||||||
if (!_lastSyncTime) {
|
if (!_lastSyncTime) {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
|
@ -965,10 +974,10 @@ Zotero.Sync.Storage.Module.ZFS = (function () {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
|
||||||
|
|
||||||
cacheCredentials: function (callback) {
|
obj._cacheCredentials = function (callback) {
|
||||||
if (_cachedCredentials) {
|
if (_cachedCredentials) {
|
||||||
Zotero.debug("Credentials are already cached");
|
Zotero.debug("Credentials are already cached");
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
@ -988,7 +997,7 @@ Zotero.Sync.Storage.Module.ZFS = (function () {
|
||||||
}
|
}
|
||||||
else if (req.status != 200) {
|
else if (req.status != 200) {
|
||||||
var msg = "Unexpected status code " + req.status + " caching "
|
var msg = "Unexpected status code " + req.status + " caching "
|
||||||
+ "authentication credentials in Zotero.Sync.Storage.Module.ZFS.cacheCredentials()";
|
+ "authentication credentials in Zotero.Sync.Storage.ZFS.cacheCredentials()";
|
||||||
Zotero.debug(msg, 1);
|
Zotero.debug(msg, 1);
|
||||||
Components.utils.reportError(msg);
|
Components.utils.reportError(msg);
|
||||||
Zotero.Sync.Storage.EventManager.error(Zotero.Sync.Storage.defaultErrorRestart);
|
Zotero.Sync.Storage.EventManager.error(Zotero.Sync.Storage.defaultErrorRestart);
|
||||||
|
@ -998,13 +1007,13 @@ Zotero.Sync.Storage.Module.ZFS = (function () {
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
},
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all synced files from the server
|
* Remove all synced files from the server
|
||||||
*/
|
*/
|
||||||
purgeDeletedStorageFiles: function (callback) {
|
obj._purgeDeletedStorageFiles = function (callback) {
|
||||||
// If we don't have a user id we've never synced and don't need to bother
|
// If we don't have a user id we've never synced and don't need to bother
|
||||||
if (!Zotero.userID) {
|
if (!Zotero.userID) {
|
||||||
Zotero.Sync.Storage.EventManager.skip();
|
Zotero.Sync.Storage.EventManager.skip();
|
||||||
|
@ -1060,6 +1069,7 @@ Zotero.Sync.Storage.Module.ZFS = (function () {
|
||||||
|
|
||||||
Zotero.Sync.Storage.EventManager.success();
|
Zotero.Sync.Storage.EventManager.success();
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
return obj;
|
||||||
}());
|
}());
|
||||||
|
|
|
@ -421,7 +421,7 @@ Zotero.Sync.EventListener = new function () {
|
||||||
var sql = "REPLACE INTO syncDeleteLog VALUES (?, ?, ?, ?)";
|
var sql = "REPLACE INTO syncDeleteLog VALUES (?, ?, ?, ?)";
|
||||||
var syncStatement = Zotero.DB.getStatement(sql);
|
var syncStatement = Zotero.DB.getStatement(sql);
|
||||||
|
|
||||||
if (isItem && Zotero.Sync.Storage.isActive('WebDAV')) {
|
if (isItem && Zotero.Sync.Storage.WebDAV.active) {
|
||||||
var storageEnabled = true;
|
var storageEnabled = true;
|
||||||
var sql = "INSERT INTO storageDeleteLog VALUES (?, ?, ?)";
|
var sql = "INSERT INTO storageDeleteLog VALUES (?, ?, ?)";
|
||||||
var storageStatement = Zotero.DB.getStatement(sql);
|
var storageStatement = Zotero.DB.getStatement(sql);
|
||||||
|
@ -559,7 +559,7 @@ Zotero.Sync.Runner = new function () {
|
||||||
Zotero.Sync.Runner.setSyncStatus(Zotero.getString('sync.status.syncingFiles'));
|
Zotero.Sync.Runner.setSyncStatus(Zotero.getString('sync.status.syncingFiles'));
|
||||||
|
|
||||||
var zfsSync = function (skipSyncNeeded) {
|
var zfsSync = function (skipSyncNeeded) {
|
||||||
Zotero.Sync.Storage.sync('ZFS', {
|
Zotero.Sync.Storage.ZFS.sync({
|
||||||
// ZFS success
|
// ZFS success
|
||||||
onSuccess: function () {
|
onSuccess: function () {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
@ -593,7 +593,7 @@ Zotero.Sync.Runner = new function () {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
Zotero.Sync.Storage.sync('WebDAV', {
|
Zotero.Sync.Storage.WebDAV.sync({
|
||||||
// WebDAV success
|
// WebDAV success
|
||||||
onSuccess: function () {
|
onSuccess: function () {
|
||||||
zfsSync(true);
|
zfsSync(true);
|
||||||
|
|
|
@ -1801,12 +1801,12 @@ const ZOTERO_CONFIG = {
|
||||||
Zotero.Relations.purge();
|
Zotero.Relations.purge();
|
||||||
|
|
||||||
if (!skipStoragePurge && Math.random() < 1/10) {
|
if (!skipStoragePurge && Math.random() < 1/10) {
|
||||||
Zotero.Sync.Storage.purgeDeletedStorageFiles('ZFS');
|
Zotero.Sync.Storage.ZFS.purgeDeletedStorageFiles();
|
||||||
Zotero.Sync.Storage.purgeDeletedStorageFiles('WebDAV');
|
Zotero.Sync.Storage.WebDAV.purgeDeletedStorageFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skipStoragePurge) {
|
if (!skipStoragePurge) {
|
||||||
Zotero.Sync.Storage.purgeOrphanedStorageFiles('WebDAV');
|
Zotero.Sync.Storage.WebDAV.purgeOrphanedStorageFiles();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,7 @@ const xpcomFilesLocal = [
|
||||||
'storage/queueManager',
|
'storage/queueManager',
|
||||||
'storage/queue',
|
'storage/queue',
|
||||||
'storage/request',
|
'storage/request',
|
||||||
'storage/module',
|
'storage/mode',
|
||||||
'storage/zfs',
|
'storage/zfs',
|
||||||
'storage/webdav',
|
'storage/webdav',
|
||||||
'timeline',
|
'timeline',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user