@@ -59,7 +59,7 @@ function validURL(value) {
5959 * Our Nextcloud Provider
6060 */
6161function Nextcloud ( ) {
62- // this.log = Log4Moz.getConfiguredLogger("Nextcloud", Log4Moz.Level.Info, Log4Moz.Level.Debug,
62+ //this.log = Log4Moz.getConfiguredLogger("Nextcloud", Log4Moz.Level.Info, Log4Moz.Level.Debug,
6363 // Log4Moz.Level.Debug);
6464 this . log = Log4Moz . getConfiguredLogger ( "Nextcloud" ) ;
6565}
@@ -108,6 +108,7 @@ Nextcloud.prototype = {
108108 _accountKey : false ,
109109 _serverUrl : "" ,
110110 _serverPort : 443 ,
111+ _fullUrl : "" ,
111112 _storageFolder : "" ,
112113 _userName : "" ,
113114 _password : "" ,
@@ -150,6 +151,12 @@ Nextcloud.prototype = {
150151 this . _serverUrl = this . _prefBranch . getCharPref ( "server" ) ;
151152 this . _serverPort = this . _prefBranch . getIntPref ( "port" ) ;
152153 this . _userName = this . _prefBranch . getCharPref ( "username" ) ;
154+ let fullUrl = this . _serverUrl + ":" + this . _serverPort ;
155+ const thirdSlash = this . _serverUrl . indexOf ( '/' , 9 ) ;
156+ if ( thirdSlash !== - 1 ) {
157+ fullUrl = this . _serverUrl . slice ( 0 , thirdSlash ) + ":" + this . _serverPort + this . _serverUrl . slice ( thirdSlash ) ;
158+ }
159+ this . _fullUrl = fullUrl ;
153160
154161 if ( this . _prefBranch . prefHasUserValue ( "storageFolder" ) ) {
155162 this . _storageFolder = this . _prefBranch . getCharPref ( "storageFolder" ) ;
@@ -353,7 +360,7 @@ Nextcloud.prototype = {
353360 this . log . info ( "Suppressing password prompt" ) ;
354361 }
355362
356- let passwordURI = this . _serverUrl ;
363+ let passwordURI = this . _fullUrl ;
357364 let logins = Services . logins . findLogins ( { } , passwordURI , null , passwordURI ) ;
358365 for ( let loginInfo of logins ) {
359366 if ( loginInfo . username == aUsername ) {
@@ -370,10 +377,10 @@ Nextcloud.prototype = {
370377 let authPrompter = Services . ww . getNewAuthPrompter ( win ) ;
371378 let password = { value : "" } ;
372379 // Use the service name in the prompt text
373- let userPos = this . _serverUrl . indexOf ( "//" ) + 2 ;
380+ let userPos = this . _fullUrl . indexOf ( "//" ) + 2 ;
374381 let userNamePart = encodeURIComponent ( this . _userName ) + '@' ;
375382 let serverUrl =
376- this . _serverUrl . substr ( 0 , userPos ) + userNamePart + this . _serverUrl . substr ( userPos ) ;
383+ this . _fullUrl . substr ( 0 , userPos ) + userNamePart + this . _fullUrl . substr ( userPos ) ;
377384 let messengerBundle = Services . strings . createBundle (
378385 "chrome://messenger/locale/messenger.properties" ) ;
379386 let promptString = messengerBundle . formatStringFromName ( "passwordPrompt" ,
@@ -431,7 +438,7 @@ Nextcloud.prototype = {
431438 let req = Cc [ "@mozilla.org/xmlextras/xmlhttprequest;1" ]
432439 . createInstance ( Ci . nsIXMLHttpRequest ) ;
433440
434- req . open ( "GET" , this . _serverUrl + ":" + this . _serverPort + kAuthPath + args , true ) ;
441+ req . open ( "GET" , this . _fullUrl + kAuthPath + args , true ) ;
435442 req . setRequestHeader ( "Content-Type" , "application/x-www-form-urlencoded" ) ;
436443 req . setRequestHeader ( "OCS-APIREQUEST" , "true" ) ;
437444 req . setRequestHeader ( "Authorization" ,
@@ -571,7 +578,7 @@ Nextcloud.prototype = {
571578 let req = Cc [ "@mozilla.org/xmlextras/xmlhttprequest;1" ] . createInstance (
572579 Ci . nsIXMLHttpRequest ) ;
573580
574- req . open ( "PROPFIND" , this . _serverUrl + ":" + this . _serverPort + kWebDavPath , true ,
581+ req . open ( "PROPFIND" , this . _fullUrl + kWebDavPath , true ,
575582 this . _userName , this . _password ) ;
576583 req . onerror = function ( ) {
577584 this . log . info ( "logon failure" ) ;
@@ -634,7 +641,7 @@ Nextcloud.prototype = {
634641 let req = Cc [ "@mozilla.org/xmlextras/xmlhttprequest;1" ]
635642 . createInstance ( Ci . nsIXMLHttpRequest ) ;
636643
637- req . open ( "PROPFIND" , this . _serverUrl + kWebDavPath +
644+ req . open ( "PROPFIND" , this . _fullUrl + kWebDavPath +
638645 ( "/" + this . _storageFolder + "/" ) . replace ( / \/ + / g, '/' ) , true , this . _userName ,
639646 this . _password ) ;
640647 req . onerror = function ( ) {
@@ -670,7 +677,7 @@ Nextcloud.prototype = {
670677 let req = Cc [ "@mozilla.org/xmlextras/xmlhttprequest;1" ]
671678 . createInstance ( Ci . nsIXMLHttpRequest ) ;
672679
673- req . open ( "MKCOL" , this . _serverUrl + kWebDavPath +
680+ req . open ( "MKCOL" , this . _fullUrl + kWebDavPath +
674681 ( "/" + this . _storageFolder + "/" ) . replace ( / \/ + / g, '/' ) , true , this . _userName ,
675682 this . _password ) ;
676683
@@ -754,9 +761,7 @@ NextcloudFileUploader.prototype = {
754761
755762 let folder = ( "/" + this . nextcloud . _storageFolder + "/" ) . replace ( / \/ + / g, '/' ) ;
756763
757- let url = this . nextcloud . _serverUrl +
758- ":" +
759- this . nextcloud . _serverPort +
764+ let url = this . nextcloud . _fullUrl +
760765 kWebDavPath +
761766 folder +
762767 this . _fileUploadTS [ this . file . path ] +
@@ -827,7 +832,6 @@ NextcloudFileUploader.prototype = {
827832 * @private
828833 */
829834 _getShareUrl : function nsNCFU_getShareUrl ( aFile , aCallback ) {
830- //let url = this.nextcloud._serverUrl + ":" + this.nextcloud._serverPort + kWebDavPath;
831835 this . file = aFile ;
832836 let shareType = 3 ;
833837 let args = "?format=json" ;
@@ -844,7 +848,7 @@ NextcloudFileUploader.prototype = {
844848 }
845849
846850 req . open ( "POST" ,
847- this . nextcloud . _serverUrl + ":" + this . nextcloud . _serverPort + kShareApp + args ,
851+ this . nextcloud . _fullUrl + kShareApp + args ,
848852 true ,
849853 this . nextcloud . _userName ,
850854 this . nextcloud . _password
0 commit comments