Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/nextcloud-filelink.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Bille <thomas.bille625@gmail.com>2017-04-20 17:37:59 +0300
committerThomas Bille <thomas.bille625@gmail.com>2017-04-20 17:37:59 +0300
commit1b3191ef3fdbaf65dd9282c5ce4e87fa9b593eaa (patch)
treee94b8b1b553f67c3a889f50b2dc160773c8c84ef /src
parenta0f8dea1aa188dafaf92c9b2eb51c6d51814d9ca (diff)
Create a folder if the folder entered in the settings doesn't exist
Diffstat (limited to 'src')
-rw-r--r--src/components/nsNextcloud.js44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/components/nsNextcloud.js b/src/components/nsNextcloud.js
index 746b629..0b9f480 100644
--- a/src/components/nsNextcloud.js
+++ b/src/components/nsNextcloud.js
@@ -271,12 +271,22 @@ Nextcloud.prototype = {
createExistingAccount: function nsNc_createExistingAccount (aRequestObserver) {
// XXX: replace this with a better function
let successCb = function () {
+
+ let callbackCreateFolder = function (created) {
+ if (created) {
+ aRequestObserver.onStopRequest(null, this, Cr.NS_OK);
+ }
+ else {
+ aRequestObserver.onStopRequest(null, this, Ci.nsIMsgCloudFileProvider.authErr);
+ }
+ }.bind(this);
+
let folderExists = function (exists) {
if (exists) {
aRequestObserver.onStopRequest(null, this, Cr.NS_OK);
}
else {
- aRequestObserver.onStopRequest(null, this, Ci.nsIMsgCloudFileProvider.authErr);
+ this._createFolder(callbackCreateFolder);
}
}.bind(this);
this._checkFolderExists(folderExists);
@@ -638,6 +648,38 @@ Nextcloud.prototype = {
},
/**
+ * A private function which creates a folder entered
+ * in the settings screen on the server.
+ *
+ * @param callback callback function called with true or false as an argument
+ * @private
+ */
+ _createFolder: function createFolder(callback) {
+ if (this._storageFolder !== '/') {
+ let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
+ .createInstance(Ci.nsIXMLHttpRequest);
+
+ req.open("MKCOL", this._serverUrl + kWebDavPath +
+ ("/" + this._storageFolder + "/").replace(/\/+/g, '/'), true, this._userName,
+ this._password);
+
+ req.onload = function () {
+ if (req.status === 201) {
+ return callback(true);
+ }
+ else {
+ return callback(false);
+ }
+ }.bind(this);
+ req.send();
+ }
+ else {
+ return callback(false);
+ }
+
+ },
+
+ /**
* A private function that first ensures that the user is logged in, and then
* retrieves the user's profile information.
*