jellyfin-web/dashboard-ui/apiclient/sync/multiserversync.js

52 lines
1.2 KiB
JavaScript
Raw Normal View History

2015-09-09 10:49:44 -07:00
(function (globalScope) {
function multiServerSync(connectionManager) {
2015-09-09 20:22:52 -07:00
var self = this;
2015-09-21 18:05:33 -07:00
self.sync = function (options) {
2015-09-09 10:49:44 -07:00
var deferred = DeferredBuilder.Deferred();
2015-09-27 08:00:57 -07:00
var servers = connectionManager.getSavedServers();
syncNext(servers, 0, options, deferred);
2015-09-09 10:49:44 -07:00
return deferred.promise();
};
2015-09-21 18:05:33 -07:00
function syncNext(servers, index, options, deferred) {
2015-09-09 10:49:44 -07:00
var length = servers.length;
if (index >= length) {
deferred.resolve();
return;
}
var server = servers[index];
Logger.log("Creating ServerSync to server: " + server.Id);
require(['serversync'], function () {
2015-09-21 18:05:33 -07:00
new MediaBrowser.ServerSync(connectionManager).sync(server, options).done(function () {
2015-09-09 10:49:44 -07:00
2015-09-21 18:05:33 -07:00
syncNext(servers, index + 1, options, deferred);
2015-09-09 10:49:44 -07:00
}).fail(function () {
2015-09-21 18:05:33 -07:00
syncNext(servers, index + 1, options, deferred);
2015-09-09 10:49:44 -07:00
});
});
}
}
if (!globalScope.MediaBrowser) {
globalScope.MediaBrowser = {};
}
globalScope.MediaBrowser.MultiServerSync = multiServerSync;
})(this);