942d5c5f4dac131598bfc04d6077c53bb74a337f
chmalee
  Thu Aug 14 14:39:11 2025 -0700
Add client side checks for preventing uploading files associated with two different genomes to the same hub (right now only support one genome per hub), and prevent uploading a hub.txt to a hub that already has a hub.txt, refs #31058

diff --git src/hg/js/hgMyData.js src/hg/js/hgMyData.js
index 1f6ad8ce51b..ea4e818fa9e 100644
--- src/hg/js/hgMyData.js
+++ src/hg/js/hgMyData.js
@@ -298,41 +298,59 @@
             let parentDirMatch = file.meta.parentDir.match(parentDirRegex);
             if (!fileNameMatch || fileNameMatch[0] !== file.meta.name) {
                 uppy.info(`Error: File name has special characters, please rename file: ${file.meta.name} to only include alpha-numeric characters, period, dash, underscore or plus.`, 'error', 5000);
                 doUpload = false;
                 continue;
             }
             if (!parentDirMatch || parentDirMatch[0] !== file.meta.parentDir) {
                 uppy.info(`Error: Hub name has special characters, please rename hub: ${file.meta.parentDir} for file: ${file.meta.name} to only include alpha-numeric characters, period, dash, underscore, or plus.`, 'error', 5000);
                 doUpload = false;
                 continue;
             }
             if (!file.meta.genome) {
                 uppy.info(`Error: No genome selected for file ${file.meta.name}!`, 'error', 5000);
                 doUpload = false;
                 continue;
-            } else if  (!file.meta.fileType) {
+            }
+            if  (!file.meta.fileType) {
                 uppy.info(`Error: File type not supported, file: ${file.meta.name}!`, 'error', 5000);
                 doUpload = false;
                 continue;
             }
+            // check if this hub already exists and the genome is different from what was
+            // just selected, if so, make the user create a new hub
+            if (file.meta.parentDir in hubCreate.uiState.filesHash && hubCreate.uiState.filesHash[file.meta.parentDir].genome !== file.meta.genome) {
+                genome = hubCreate.uiState.filesHash[file.meta.parentDir].genome;
+                uppy.info(`Error: the hub ${file.meta.parentDir} already exists and is for genome "${genome}". Please select the correct genome, a different hub or make a new hub.`);
+                doUpload = false;
+                continue;
+            }
+            // check if the user is uploading a hub.txt into a hub that already has a hub.txt
+            let hubFiles = hubCreate.uiState.filesHash[file.meta.parentDir].children;
+            if (file.meta.fileType === "hub.txt" && hubFiles.filter((f) => f.fileType === "hub.txt").length !== 0) {
+                uppy.info(`Error: the hub definition file (ex: hub.txt) already exists, create a new hub if you want to upload this hub definition file`);
+                doUpload = false;
+                continue;
+            }
+
             uppy.setFileMeta(file.id, {
                 fileName: file.meta.name,
                 fileSize: file.size,
                 lastModified: file.data.lastModified,
             });
             thisQuota += file.size;
+
         }
         if (thisQuota + hubCreate.uiState.userQuota > hubCreate.uiState.maxQuota) {
             uppy.info(`Error: this file batch exceeds your quota. Please delete some files to make space or email genome-www@soe.ucsc.edu if you feel you need more space.`);
             doUpload = false;
         }
         return doUpload;
     },
 });
 
 // create a custom uppy plugin to batch change the type and db fields
 class BatchChangePlugin extends Uppy.BasePlugin {
     constructor(uppy, opts) {
         super(uppy, opts);
         this.id = "BatchChangePlugin";
         this.type = "progressindicator";