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/customFactory.c src/hg/lib/customFactory.c
index 97431d1..c3af836 100644
--- src/hg/lib/customFactory.c
+++ src/hg/lib/customFactory.c
@@ -3480,51 +3480,73 @@
     if (!isprint(string[i]) && !isspace(string[i]))
 	return TRUE;
 return FALSE;
 }
 
 static boolean bigDataOopsRecognizer(struct customFactory *fac,	struct customPp *cpp, char *type,
 				     struct customTrack *track)
 /* errAbort if looks like user uploaded a bigData file, otherwise return FALSE. */
 {
 char *line = customFactoryNextRealTilTrack(cpp);
 if (line == NULL)
     return FALSE;
 if (hasUnprintable(line, 6))
     {
     char *fileName = customPpFileName(cpp);
+    dumpStack("bigDataOoops: fileName = '%s'\n", fileName);
+    errAbort("bigDataOops: fileName = '%s'\n", fileName);
     if (type == NULL &&isNotEmpty(fileName))
         {
         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";
         }
     char *docUrl = NULL;
     if (isNotEmpty(type))
         docUrl = bigDataDocPath(type);
     struct dyString *dataName = dyStringNew(0);
     if (isNotEmpty(fileName) && !sameString(fileName, CT_NO_FILE_NAME)
             && !startsWith("memory://", fileName))
         dyStringPrintf(dataName, " (%s)", fileName);
     else if (track->tdb && track->tdb->shortLabel
              && differentString(track->tdb->shortLabel, CT_DEFAULT_TRACK_NAME))
         dyStringPrintf(dataName, " (%s)", track->tdb->shortLabel);
+    if (cfgOptionBooleanDefault("storeUserFiles", FALSE))
+        {
+        // figure out if user is logged in:
+        //   1. if so, save 'line', which is really a binary data, to username encoded directory
+        //   2. if not, do regular oops recognizer
+        // TODO: make sure the correct loader is called after this
+        // essential that the struct customTrack * track structure
+        // gets filled in correctly for the loader to work because the
+        // 'line' will not exist at that point
+        // For now I think the best thing is to store the file and construct
+        // a bigDataUrl to it, then re do the custom track load
+        // so the right factory is called
+        //char *userName = (loginSystemEnabled() || wikiLinkEnabled()) ? wikiLinkUserName() : NULL;
+        //if (userName)
+        //    {
+        //    storeUserFiles(fileName, line);
+        //    customPpReuse(cpp, line);
+        //    return TRUE;
+        //    }
+        }
     if (docUrl)
         errAbort("It appears that you are directly uploading binary data of type %s%s.  "
              "Custom tracks of this type require the files to be accessible by "
              "public http/https/ftp. Our <a href='../goldenPath/help/hgTrackHubHelp.html#Hosting' target=_blank>track hub documentation</a> "
                      "lists third-party services where you can "
                      "store custom track or track hub files. "
                      "Once the files are available on the internet, file URLs can be entered as-is, one per line, "
                      "or via the bigDataUrl "
              "setting on a &quot;track&quot; line.  "
              "See <A HREF='%s' TARGET=_BLANK>%s custom track documentation</A> for "
              "more information and examples.",
              type, dataName->string, docUrl, type);
     else
         errAbort("It appears that you are directly uploading binary data in an unrecognized "
              "format%s.  For custom track formatting information, please see "
@@ -4227,30 +4249,31 @@
 int ptMax = atoi(cfgOptionDefault("parallelFetch.threads", "20"));  // default number of threads for parallel fetch.
 
 struct lineFile *lf = customLineFile(text, isFile);
 
 /* wrap a customPp object around it. */
 struct customPp *cpp = customPpNew(lf);
 lf = NULL;
 
 /* Loop through this once for each track. */
 while ((line = customPpNextReal(cpp)) != NULL)
     {
     /* Parse out track line and save it in track var.
      * First time through make up track var from thin air
      * if no track line. Find out explicit type setting if any.
      * Also make sure settingsHash is set up. */
+    // NOTE: line is binary data if a file upload
     lf = cpp->fileStack;
     char *dataUrl = NULL;
     if (lf->fileName && (
             startsWith("http://" , lf->fileName) ||
             startsWith("https://", lf->fileName) ||
             startsWith("ftp://"  , lf->fileName) ||
             udcIsResolvable(lf->fileName)
             ))
         dataUrl = cloneString(lf->fileName);
     if (startsWithWord("track", line))
         {
 	track = trackLineToTrack(genomeDb, line, cpp->fileStack->lineIx);
         }
     else if (trackList == NULL)
     /* In this case we handle simple files with a single track