define([],function(){"use strict";returnfunction(connectionManager){functionperformSync(server,options){console.log("ServerSync.performSync to server: "+server.Id),options=options||{};varuploadPhotos=options.uploadPhotos!==!1;options.cameraUploadServers&&options.cameraUploadServers.indexOf(server.Id)===-1&&(uploadPhotos=!1);varpr=Promise.resolve();returnpr.then(function(){returnuploadPhotos?uploadContent(server,options):Promise.resolve()}).then(function(){returnsyncMedia(server,options)})}functionuploadContent(server,options){returnnewPromise(function(resolve,reject){require(["contentuploader"],function(contentuploader){uploader=newContentUploader(connectionManager),uploader.uploadImages(server).then(resolve,reject)})})}functionsyncMedia(server,options){returnnewPromise(function(resolve,reject){require(["mediasync"],function(MediaSync){varapiClient=connectionManager.getApiClient(server.Id);(newMediaSync).sync(apiClient,server,options).then(resolve,reject)})})}varself=this;self.sync=function(server,options){if(!server.AccessToken&&!server.ExchangeToken)returnconsole.log("Skipping sync to server "+server.Id+" because there is no saved authentication information."),Promise.resolve();varconnectionOptions={updateDateLastAccessed:!1,enableWebSocket:!1,reportCapabilities:!1,enableAutomaticBitrateDetection:!1};returnconnectionManager.connectToServer(server,connectionOptions).then(function(result){returnresult.State===MediaBrowser.ConnectionState.SignedIn?performSync(server,options):(console.log("Unable to connect to server id: "+server.Id),Promise.reject())},function(err){throwconsole.log("Unable to connect to server id: "+server.Id),err})}}});