c79deb301511fcf0de0ed376c7746e4902804472
chmalee
  Fri May 5 16:59:33 2023 -0700
Experiment number one, can succesfully upload a file and store it via
hgCustom. New userdata library for managing where to store the files

Get skeleton structure of new cgi together

More work in progress, mostly stubbing out the CGI

More work in progress, mostly stubbing out the html page

diff --git src/hg/lib/customTrack.c src/hg/lib/customTrack.c
index d048e9f..6937a58 100644
--- src/hg/lib/customTrack.c
+++ src/hg/lib/customTrack.c
@@ -17,30 +17,32 @@
 #include "customTrack.h"
 #include "ctgPos.h"
 #include "psl.h"
 #include "gff.h"
 #include "genePred.h"
 #include "net.h"
 #include "hdb.h"
 #include "hui.h"
 #include "cheapcgi.h"
 #include "wiggle.h"
 #include "hgConfig.h"
 #include "customFactory.h"
 #include "trashDir.h"
 #include "jsHelper.h"
 #include "botDelay.h"
+#include "wikiLink.h"
+#include "userdata.h"
 
 static boolean printSaveList = FALSE; // if this is true, we print to stderr the number of custom tracks saved
 
 /* Track names begin with track and then go to variable/value pairs.  The
  * values must be quoted if they include white space. Defined variables are:
  *  name - any text up to 15 letters.
  *  description - any text up to 60 letters.
  *  url - URL.  If it contains '$$' this will be substituted with itemName.
  *  visibility - 0=hide, 1=dense, 2=full, 3=pack, 4=squish
  *  useScore - 0=use colors. 1=use grayscale based on score.
  *  color = R,G,B,  main color, should be dark.  Components from 0-255.
  *  altColor = R,G,B secondary color.
  *  priority = number.
  */
 
@@ -691,40 +693,79 @@
 // exclude plain VCF (as opposed to vcfTabix) from bigData treatment
 result = (type != NULL && differentString(type, "vcf"));
 
 freeMem(type);
 freeMem(fileNameDecoded);
 return result;
 }
 
 static char *prepBigData(struct cart *cart, char *fileName, char *binVar, char *fileVar)
 /* Pass data's memory offset and size through to customFactory */
 {
 if (!customTrackIsBigData(fileName))
     return NULL;
 char buf[1024];
 char *cFBin = cartOptionalString(cart, binVar);
+char *cF = cartOptionalString(cart, fileVar);
+char *offset = NULL;
+unsigned long size = 0;
 if (cFBin)
     {
     // cFBin already contains memory offset and size (search for __binary in cheapcgi.c)
     safef(buf,sizeof(buf),"memory://%s %s", fileName, cFBin);
+    char *split[3];
+    int splitCount = chopByWhite(cloneString(cFBin), split, sizeof(split));
+    if (splitCount > 2) {errAbort("hgCustom: extra garbage in %s", binVar);}
+    offset = (char *)sqlUnsignedLong(split[0]);
+    size = sqlUnsignedLong(split[1]);
     }
 else
     {
-    char *cF = cartOptionalString(cart, fileVar);
     safef(buf, sizeof(buf),"memory://%s %lu %lu",
 	  fileName, (unsigned long) cF, (unsigned long) strlen(cF));
+    offset = (char *)sqlUnsignedLong(cF);
+    size = (unsigned long)strlen(cF);
+    }
+if (cfgOptionBooleanDefault("storeUserFiles", FALSE))
+    {
+    //dumpStack("prepBigData: fileName = '%s'\n", fileName);
+    //errAbort("prepBigData: fileName = '%s'\n", fileName);
+    // figure out if user is logged in:
+    //   1. if so, save 'fileName', which is really a pointer to memory, to username encoded directory
+    //   2. Turn buf into a web accessible url to this data so it will be parsed
+    //   as a track correctly
+    char *userName = (loginSystemEnabled() || wikiLinkEnabled()) ? wikiLinkUserName() : NULL;
+    if (userName)
+        {
+        // storeUserFiles returns a URL to a track
+        // after sucessfully saving the data into /userdata
+        char *retFileName = storeUserFile(userName, fileName, offset, size);
+        struct dyString *ret = dyStringNew(0);
+        char *type = NULL;
+        if (endsWith(fileName, ".bam"))
+            type = "bam";
+        else if (endsWith(fileName, ".bb") || endsWith(fileName, ".bigBed"))
+            type = "bigBed";
+        else if (endsWith(fileName, ".inter.bb") || endsWith(fileName, ".inter.bigBed"))
+            type = "bigInteract";
+        else if (endsWith(fileName, ".bw") || endsWith(fileName, ".bigWig"))
+            type = "bigWig";
+        if (!type)
+            errAbort("Unable to determine track type from extension: %s", fileName);
+        dyStringPrintf(ret, "track type=%s bigDataUrl=%s", type, retFileName);
+        return dyStringCannibalize(&ret);
+        }
     }
 return cloneString(buf);
 }
 
 boolean ctConfigUpdate(char *ctFile)
 /* CT update is needed if database has been enabled since
  * the custom tracks in this file were created.  The only way to check is
  * by file mod time, unless we add the enable time to
  * browser metadata somewhere */
 {
 if (!ctFile || !fileExists(ctFile))
     return FALSE;
 return cfgModTime() > fileModTime(ctFile);
 }