@ -1525,7 +1525,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato
this . serverSalt = serverSalt ;
this . serverSalt = serverSalt ;
this . upload = options . up load || false ;
this . upload = options . fileUpload || options . fileDown load || false ;
this . updateSession ( ) ;
this . updateSession ( ) ;
@ -2356,8 +2356,12 @@ factory('MtpApiManager', function (AppConfigManager, MtpAuthorizer, MtpNetworker
} ) ;
} ) ;
}
}
function mtpGetNetworker ( dcID , upload ) {
function mtpGetNetworker ( dcID , options ) {
var cache = upload ? cachedUploadNetworkers : cachedNetworkers ;
options = options || { } ;
var cache = ( options . fileUpload || options . fileDownload )
? cachedUploadNetworkers
: cachedNetworkers ;
if ( ! dcID ) {
if ( ! dcID ) {
throw new Exception ( 'get Networker without dcID' ) ;
throw new Exception ( 'get Networker without dcID' ) ;
}
}
@ -2382,7 +2386,11 @@ factory('MtpApiManager', function (AppConfigManager, MtpAuthorizer, MtpNetworker
var authKey = bytesFromHex ( authKeyHex ) ;
var authKey = bytesFromHex ( authKeyHex ) ;
var serverSalt = bytesFromHex ( serverSaltHex ) ;
var serverSalt = bytesFromHex ( serverSaltHex ) ;
return cache [ dcID ] = MtpNetworkerFactory . getNetworker ( dcID , authKey , serverSalt , { upload : upload } ) ;
return cache [ dcID ] = MtpNetworkerFactory . getNetworker ( dcID , authKey , serverSalt , options ) ;
}
if ( ! options . createNetworker ) {
return $q . reject ( { type : 'AUTH_KEY_EMPTY' , code : 500 } ) ;
}
}
return MtpAuthorizer . auth ( dcID ) . then ( function ( auth ) {
return MtpAuthorizer . auth ( dcID ) . then ( function ( auth ) {
@ -2391,7 +2399,7 @@ factory('MtpApiManager', function (AppConfigManager, MtpAuthorizer, MtpNetworker
storeObj [ ssk ] = bytesToHex ( auth . serverSalt ) ;
storeObj [ ssk ] = bytesToHex ( auth . serverSalt ) ;
AppConfigManager . set ( storeObj ) ;
AppConfigManager . set ( storeObj ) ;
return cache [ dcID ] = MtpNetworkerFactory . getNetworker ( dcID , auth . authKey , auth . serverSalt , { upload : upload } ) ;
return cache [ dcID ] = MtpNetworkerFactory . getNetworker ( dcID , auth . authKey , auth . serverSalt , options ) ;
} , function ( error ) {
} , function ( error ) {
console . log ( 'Get networker error' , error , error . stack ) ;
console . log ( 'Get networker error' , error , error . stack ) ;
return $q . reject ( error ) ;
return $q . reject ( error ) ;
@ -2404,14 +2412,13 @@ factory('MtpApiManager', function (AppConfigManager, MtpAuthorizer, MtpNetworker
var deferred = $q . defer ( ) ,
var deferred = $q . defer ( ) ,
dcID ,
dcID ,
upload = options . fileDownload || options . fileUpload ,
networkerPromise ;
networkerPromise ;
if ( dcID = options . dcID ) {
if ( dcID = options . dcID ) {
networkerPromise = mtpGetNetworker ( dcID , upload ) ;
networkerPromise = mtpGetNetworker ( dcID , options ) ;
} else {
} else {
networkerPromise = AppConfigManager . get ( 'dc' ) . then ( function ( baseDcID ) {
networkerPromise = AppConfigManager . get ( 'dc' ) . then ( function ( baseDcID ) {
return mtpGetNetworker ( dcID = baseDcID || 1 , upload ) ;
return mtpGetNetworker ( dcID = baseDcID || 1 , options ) ;
} ) ;
} ) ;
}
}
@ -2697,7 +2704,8 @@ factory('MtpApiFileManager', function (MtpApiManager, $q, $window) {
limit : 0
limit : 0
} , {
} , {
dcID : location . dc _id ,
dcID : location . dc _id ,
fileDownload : true
fileDownload : true ,
createNetworker : true
} ) ;
} ) ;
} ) ;
} ) ;
@ -2734,7 +2742,8 @@ factory('MtpApiFileManager', function (MtpApiManager, $q, $window) {
limit : 0
limit : 0
} , {
} , {
dcID : location . dc _id ,
dcID : location . dc _id ,
fileDownload : true
fileDownload : true ,
createNetworker : true
} ) ;
} ) ;
} ) . then ( function ( result ) {
} ) . then ( function ( result ) {
deferred . resolve ( cachedDownloads [ fileName ] = 'data:image/jpeg;base64,' + bytesToBase64 ( result . bytes ) )
deferred . resolve ( cachedDownloads [ fileName ] = 'data:image/jpeg;base64,' + bytesToBase64 ( result . bytes ) )
@ -2784,7 +2793,8 @@ factory('MtpApiFileManager', function (MtpApiManager, $q, $window) {
limit : limit
limit : limit
} , {
} , {
dcID : dcID ,
dcID : dcID ,
fileDownload : true
fileDownload : true ,
createNetworker : true
} ) ;
} ) ;
} , 6 ) . then ( function ( result ) {
} , 6 ) . then ( function ( result ) {
@ -2855,7 +2865,8 @@ factory('MtpApiFileManager', function (MtpApiManager, $q, $window) {
limit : limit
limit : limit
} , {
} , {
dcID : dcID ,
dcID : dcID ,
fileDownload : true
fileDownload : true ,
createNetworker : true
} ) ;
} ) ;
} , 6 ) . then ( function ( result ) {
} , 6 ) . then ( function ( result ) {
writeBlobPromise . then ( function ( ) {
writeBlobPromise . then ( function ( ) {