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
diff options
context:
space:
mode:
authorGuillaume Viguier-Just <guillaume@viguierjust.com>2017-05-01 17:26:56 +0300
committerGitHub <noreply@github.com>2017-05-01 17:26:56 +0300
commitda1e37178c79676013d498853817414ed61fc403 (patch)
treee94b8b1b553f67c3a889f50b2dc160773c8c84ef
parenta0f8dea1aa188dafaf92c9b2eb51c6d51814d9ca (diff)
parent1b3191ef3fdbaf65dd9282c5ce4e87fa9b593eaa (diff)
Merge pull request #20 from tbille/create-folder
Create a folder if the folder entered in the settings doesn't exist
-rw-r--r--README.md2
-rw-r--r--src/components/nsNextcloud.js44
2 files changed, 44 insertions, 2 deletions
diff --git a/README.md b/README.md
index 1ea4830..c6bba62 100644
--- a/README.md
+++ b/README.md
@@ -30,7 +30,7 @@ It is currently possible to upload files as large as 1GB.
## Nextcloud configuration
1. Make sure that you have checked "Allow users to share via link" in the **"Sharing"** section of the admin page of your Nextcloud installation. If you have also checked-in the **"Enforce password protection"** option, make sure to fill the **"Password for uploaded files"** field when setting up the add-on in Thunderbird
-1. By default your mail attachments will be saved in a folder called `Mail-attachments`. You currently need to create that folder in the root folder of your Nextcloud prior to using the Thunderbird add-on
+1. By default your mail attachments will be saved in a folder called `Mail-attachments`.
*Note: It's also possible to use a different folder name. Simply type the name of the folder you want to use when setting up the provider in Thunderbird*
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.
*