WWW update
[ubi] / qml / ubi / u1.js
index 91bdd0e..478f7f9 100644 (file)
@@ -87,7 +87,7 @@ function oAuthHeader(url,secrets,method)
 
 function registerToken(secrets,user,root)
 {
-    var url = "https://one.ubuntu.com/oauth/sso-finished-so-get-tokens/" + user;
+    var url = "https://one.ubuntu.com/oauth/sso-finished-so-get-tokens/"+user;
     var xhr = oAuthRequest(url,secrets);
     xhr.onreadystatechange = function() {
                 if(xhr.readyState===4) {
@@ -129,8 +129,8 @@ function getAccount(secrets,root)
 
 function getFiles(secrets,rootNode,root)
 {
-    var url = "https://one.ubuntu.com/api/file_storage/v1"
-            +encodeURI(rootNode)+"/?include_children=true";
+    var url = encodeURI2("https://one.ubuntu.com/api/file_storage/v1"
+            +rootNode+"/?include_children=true");
     //console.log("url: "+url);
     var xhr = oAuthRequest(url,secrets);
     xhr.onreadystatechange = function() {
@@ -139,6 +139,8 @@ function getFiles(secrets,rootNode,root)
                         root.onErr(xhr.status);
                     } else {
                         //console.log(xhr.responseText);
+                        //console.log("");
+                        //console.log(xhr.getAllResponseHeaders());
                         var resp = eval('('+xhr.responseText+')');
                         var nodes = resp.children;
                         root.onResp(nodes);
@@ -189,8 +191,8 @@ function getFileTree(secrets,root)
 
 function renameFile(secrets,resourcePath,targetPath,root)
 {
-    var url = "https://one.ubuntu.com/api/file_storage/v1"+encodeURI(resourcePath);
-    //console.log("url: "+url);
+    var url = encodeURI2("https://one.ubuntu.com/api/file_storage/v1"+resourcePath);
+    console.log("url: "+url);
     //console.log("target: "+encodeURI(targetPath));
     //console.log("target: "+targetPath);
     var xhr = oAuthRequest(url,secrets,"PUT");
@@ -219,7 +221,7 @@ function renameFile(secrets,resourcePath,targetPath,root)
 
 function stopPublishing(secrets,resourcePath,root)
 {
-    var url = "https://one.ubuntu.com/api/file_storage/v1"+encodeURI(resourcePath);
+    var url = encodeURI2("https://one.ubuntu.com/api/file_storage/v1"+resourcePath);
     var xhr = oAuthRequest(url,secrets,"PUT");
     xhr.setRequestHeader("Content-Type","application/json");
     var body = '{"is_public":false}';
@@ -243,7 +245,7 @@ function stopPublishing(secrets,resourcePath,root)
 
 function startPublishing(secrets,resourcePath,root)
 {
-    var url = "https://one.ubuntu.com/api/file_storage/v1"+encodeURI(resourcePath);
+    var url = encodeURI2("https://one.ubuntu.com/api/file_storage/v1"+resourcePath);
     var xhr = oAuthRequest(url,secrets,"PUT");
     xhr.setRequestHeader("Content-Type","application/json");
     var body = '{"is_public":true}';
@@ -267,16 +269,16 @@ function startPublishing(secrets,resourcePath,root)
 
 function newFolder(secrets,resourcePath,root)
 {
-    var url = "https://one.ubuntu.com/api/file_storage/v1"+encodeURI(resourcePath);
-    console.log("url: "+url);
+    var url = encodeURI2("https://one.ubuntu.com/api/file_storage/v1"+resourcePath);
+    //console.log("url: "+url);
     var xhr = oAuthRequest(url,secrets,"PUT");
     xhr.setRequestHeader("Content-Type","application/json");
     var body = '{"kind": "directory"}';
-    console.log("body: "+body);
+    //console.log("body: "+body);
     xhr.onreadystatechange = function() {
                 if(xhr.readyState===4) {
                     if(xhr.status>=400||xhr.status===0) {
-                        console.log("status: "+xhr.status);
+                        //console.log("status: "+xhr.status);
                         //console.log(xhr.responseText);
                         root.onErrNew(xhr.status);
                     } else {
@@ -292,16 +294,19 @@ function newFolder(secrets,resourcePath,root)
 
 function deleteFile(secrets,resourcePath,root,utils)
 {
-    var url = "https://one.ubuntu.com/api/file_storage/v1"+encodeURI(resourcePath);
-    //console.log("url: "+url);
-    var auth = oAuthHeader(url,secrets,"DELETE");
+    //var urlA = "https://one.ubuntu.com/api/file_storage/v1"+encodeURI(resourcePath);
+    var url = "https://one.ubuntu.com/api/file_storage/v1"+resourcePath;
+    var urlA = encodeURI2(url);
+
+    //console.log("u1.js:delete url="+url);
+    var auth = oAuthHeader(urlA,secrets,"DELETE");
     utils.deleteFile(url,auth);
 }
 
 function getFileContentType(secrets,root,path)
 {
     //var url = "https://one.ubuntu.com/api/file_storage/v1"+encodeURI(path);
-    var url = "https://files.one.ubuntu.com"+encodeURI(path);
+    var url = encodeURI2("https://files.one.ubuntu.com"+path);
     //console.log("url: "+url);
     var xhr = oAuthRequest(url,secrets,"GET","bytes=0-10");
     xhr.onreadystatechange = function() {
@@ -352,25 +357,35 @@ function fixFolder(path) {
 function getFileContent(secrets,root,path,folder,size,utils)
 {
     //var url = "https://one.ubuntu.com/api/file_storage/v1"+encodeURI(path);
-    var url = "https://files.one.ubuntu.com"+encodeURI(path);
+    var url = "https://files.one.ubuntu.com"+path;
+    var urlA = encodeURI2(url);
+
     var filename = fixFilename(path);
     var ffolder = fixFolder(folder);
     //console.log("url: "+url);
     //console.log("ffolder: "+ffolder);
-    var auth = oAuthHeader(url,secrets,"GET");
+    var auth = oAuthHeader(urlA,secrets,"GET");
     //console.log("auth: "+auth);
     utils.downloadFile(ffolder,filename,url,size,auth);
 }
 
 function uploadFile(secrets,root,path,filename,folder,utils)
 {
-    //var url = "https://one.ubuntu.com/api/file_storage/v1"+encodeURI(path);
-    //var url = "https://files.one.ubuntu.com"+path;
-    var url = "https://files.one.ubuntu.com"+encodeURI(path);
-    //console.log(url);
+    var url = "https://files.one.ubuntu.com"+path;
+    var urlA = encodeURI2(url);
+
+    //console.log("u1.js:uploadFile url=" + url);
+    //console.log("u1.js:uploadFile urAl=" + urlA);
+
     var ffolder = fixFolder(folder);
-    var auth = oAuthHeader(url,secrets,"PUT");
+    var auth = oAuthHeader(urlA,secrets,"PUT");
     utils.uploadFile(ffolder,filename,url,auth);
 }
 
-
+function encodeURI2(uri)
+{
+    var uri2 = encodeURI(uri);
+    uri2 = uri2.replace(/\%5B/g, "[");
+    uri2 = uri2.replace(/\%5D/g, "]");
+    return uri2;
+}