3a88c02326aadbb1df3436cd519f7b8a4df6ae5b
chmalee
  Thu Jun 6 15:32:15 2024 -0700
Work in progress using the mysql table for hubSpace on client side

diff --git src/hg/hgHubConnect/trackHubWizard.c src/hg/hgHubConnect/trackHubWizard.c
index a3fe480..74e29ce 100644
--- src/hg/hgHubConnect/trackHubWizard.c
+++ src/hg/hgHubConnect/trackHubWizard.c
@@ -6,117 +6,140 @@
 #include "common.h"
 #include "cart.h"
 #include "cheapcgi.h"
 #include "hdb.h"
 #include "hgConfig.h"
 #include "md5.h"
 #include "trashDir.h"
 #include "hgHubConnect.h"
 #include "jsHelper.h"
 #include "web.h"
 #include "wikiLink.h"
 #include "customTrack.h"
 #include "userdata.h"
 #include "jsonWrite.h"
 #include "cartJson.h"
+#include "hubSpace.h"
 
 void removeOneFile(char *userName, char *cgiFileName)
 /* Remove one single file for userName */
 {
 char *fileName = prefixUserFile(userName, cgiFileName);
 if (fileExists(fileName))
     {
     fprintf(stderr, "deleting file: '%s'\n", fileName);
     removeFileForUser(fileName, userName);
     fflush(stderr);
     }
 }
 
 void doRemoveFile(struct cartJson *cj, struct hash *paramHash)
 /* Process the request to remove a file */
 {
 char *userName = getUserName();
 if (userName)
     {
-    struct jsonWrite *errors = jsonWriteNew();
-    // verify the argument is present:
-    (void)cartJsonRequiredParam(paramHash, "deleteFile", errors, "doRemoveFile");
-    struct jsonElement *deleteJson = hashFindVal(paramHash, "deleteFile");
+    struct jsonElement *deleteJson = hashFindVal(paramHash, "fileNameList");
+    //struct jsonWrite *errors = jsonWriteNew();
+    // TODO: Check request is well-formed
     struct slRef *ele, *deleteList = deleteJson->val.jeList;
+    jsonWriteListStart(cj->jw, "deletedList");
     for (ele = deleteList; ele != NULL; ele = ele->next)
         {
         struct jsonElement *jsonVal = ele->val;
         removeOneFile(userName, jsonVal->val.jeString);
+        jsonWriteString(cj->jw, NULL, jsonVal->val.jeString);
         }
-    fprintf(stdout, "Status: 204 No Content\n\n");
-    fflush(stdout);
-    exit(0);
+    jsonWriteListEnd(cj->jw);
     }
-fprintf(stdout, "Status: 404 Not Found\n\n");
-fflush(stdout);
-exit(0);
+}
+
+void doMoveFile(struct cartJson *cj, struct hash *paramHash)
+/* Move a file to a new hub */
+{
+}
+
+static void writeHubText(struct trackHub *hub, char *hubDir, char *fileName, boolean makeDir)
+/* Create a hub.txt file, optionally creating the directory holding it */
+{
+int oldUmask = 00;
+oldUmask = umask(0);
+makeDirsOnPath(path);
+// restore umask
+umask(oldUmask);
+// now make the hub.txt with some basic information
+char *hubFile = catTwoStrings(path, "hub.txt");
+maybeTouchFile(hubFile);
+struct dyString *contents = dyStringNew(0);
+dyStringPrintf(contents, "hub %s\nemail %s\nshortLabel %s\nlongLabel %s\nuseOneFile on\n\ngenome %s\n\n", name, userName, name, name, db);
 }
 
 void doCreateHub(struct cartJson *cj, struct hash *paramHash)
 /* Make a new hub.txt with the parameters from the JSON request */
 {
 char *userName = getUserName();
 if (userName)
     {
     struct jsonWrite *errors = jsonWriteNew();
     // verify the arguments:
     (void)cartJsonRequiredParam(paramHash, "createHub", errors, "doCreateHub");
     // params is an object with everything necessary to create a hub: name and assembly
     struct hash *params = jsonObjectVal(hashFindVal(paramHash, "createHub"), "createHub");
     char *db = hashFindVal(params, "db");
     char *name = hashFindVal(params, "name");
     fprintf(stderr, "creating hub '%s' for db '%s'\n", name, db);
     fflush(stderr);
+    // check if this hub already exists, must have a directory and hub.txt already:
+    char *path = prefixUserFile(userName, name);
+    if (isDirectory(path))
+        {
+        // can't make a hub that already exists!
+        }
+    else
+        {
+        // good we can make a new directory and stuff a hub.txt in it
+        // the directory needs to be 777, so ignore umask for now
+        }
     }
 fprintf(stderr, "Status: 204 No Content\n\n");
 fflush(stdout);
 exit(0);
 }
 
 static void outFilesForUser()
 /* List out the currently stored files for the user and their sizes */
 {
 char *userName = getUserName();
 struct jsonWrite *jw = jsonWriteNew(); // the JSON to return for the client javascript
 jsonWriteObjectStart(jw, NULL);
 if (userName)
     {
     // the url for this user:
     jsonWriteString(jw, "userUrl", webDataDir(userName));
-    struct userHubs *hub, *hubList = listHubsForUser(userName);
-    // unpack hub directories into a flat list of files
     jsonWriteListStart(jw, "fileList");
-    for (hub = hubList; hub != NULL; hub = hub->next)
-        {
-        struct fileInfo *file;
-        struct userFiles *uf = listFilesForUserHub(userName, hub->hubName);
-        for (file = uf->fileList; file != NULL; file = file->next)
+    struct hubSpace *file, *fileList = listFilesForUser(userName);
+    for (file = fileList; file != NULL; file = file->next)
         {
         jsonWriteObjectStart(jw, NULL);
-            jsonWriteString(jw, "name", file->name);
-            jsonWriteNumber(jw, "size", file->size);
-            jsonWriteString(jw, "hub", hub->hubName);
-            jsonWriteString(jw, "genome", hub->genome);
-            jsonWriteDateFromUnix(jw, "createTime", file->creationTime);
+        jsonWriteString(jw, "fileName", file->fileName);
+        jsonWriteNumber(jw, "fileSize", file->fileSize);
+        jsonWriteString(jw, "fileType", file->fileType);
+        jsonWriteString(jw, "hub", "temp");
+        jsonWriteString(jw, "genome", file->db);
+        jsonWriteString(jw, "createTime", file->creationTime);
         jsonWriteObjectEnd(jw);
         }
-        }
     jsonWriteListEnd(jw);
     }
 jsonWriteObjectEnd(jw);
 jsInlineF("var userFiles = %s;\n", dyStringCannibalize(&jw->dy));
 jsonWriteFree(&jw);
 }
 
 void doTrackHubWizard()
 /* Offer an upload form so users can upload all their hub files */
 {
 jsIncludeFile("utils.js", NULL);
 jsIncludeFile("ajax.js", NULL);
 jsIncludeFile("lodash.3.10.0.compat.min.js", NULL);
 jsIncludeFile("cart.js", NULL);
 jsIncludeFile("tus.js", NULL);