Browse Source

fix(Dropbox): fix removing files from dropbox

Gerald 9 years ago
parent
commit
7e03973140
2 changed files with 5 additions and 2 deletions
  1. 4 0
      src/background/sync/dropbox.js
  2. 1 2
      src/background/sync/index.js

+ 4 - 0
src/background/sync/dropbox.js

@@ -77,6 +77,8 @@ var dropbox = function () {
     };
   }
 
+  // When path is encoded in URL directly,
+  // we MUST encodeURIComponent twice to ensure the filename has no slashes
   function Dropbox(token) {
     this.token = token;
     this.headers = {
@@ -94,6 +96,7 @@ var dropbox = function () {
     });
   };
   Dropbox.prototype.put = function (path, data) {
+    path = encodeURIComponent(path);
     return this.fetch('https://content.dropboxapi.com/1/files_put/auto/' + path, {
       method: 'PUT',
       body: data,
@@ -102,6 +105,7 @@ var dropbox = function () {
     }).then(normalize);
   };
   Dropbox.prototype.get = function (path) {
+    path = encodeURIComponent(path);
     return this.fetch('https://content.dropboxapi.com/1/files/auto/' + path)
     .then(function (res) {
       return res.text();

+ 1 - 2
src/background/sync/index.js

@@ -46,8 +46,7 @@ var sync = function () {
     });
   }
   function getFilename(uri) {
-    // encodeURIComponent twice to ensure the decoded filename has no slashes
-    return encodeURIComponent(encodeURIComponent(uri) + '.user.js');
+    return encodeURIComponent(uri) + '.user.js';
   }
   function syncOne(service) {
     if (!service.inst) return;