2b063dcabdbbab34f4e93795f5d45b8c20a9ca6d
galt
  Wed Jul 2 22:43:03 2025 -0700
Add botdelay to hgFileSearch. Fixes #27537

diff --git src/hg/hgFileSearch/hgFileSearch.c src/hg/hgFileSearch/hgFileSearch.c
index 37081484342..e59f0883f50 100644
--- src/hg/hgFileSearch/hgFileSearch.c
+++ src/hg/hgFileSearch/hgFileSearch.c
@@ -5,30 +5,35 @@
 #include "obscure.h"
 #include "hash.h"
 #include "cheapcgi.h"
 #include "htmshell.h"
 #include "jsHelper.h"
 #include "trackDb.h"
 #include "hdb.h"
 #include "web.h"
 #include "mdb.h"
 #include "hCommon.h"
 #include "hui.h"
 #include "fileUi.h"
 #include "search.h"
 #include "cart.h"
 #include "grp.h"
+#include "botDelay.h"
+
+/* for earlyBotCheck() function at the beginning of main() */
+#define delayFraction   1.0    /* standard penalty is 1.0 for most CGIs */
+static boolean issueBotWarning = FALSE;
 
 #define FAKE_MDB_MULTI_SELECT_SUPPORT
 
 struct hash *trackHash = NULL;  // Is this needed?
 boolean measureTiming = FALSE;  /* DON'T EDIT THIS -- use CGI param "&measureTiming=." . */
 
 #define FILE_SEARCH_WHAT "Downloadable ENCODE Files"
 #define FILE_SEARCH_NAME FILE_SEARCH_WHAT " Search"
 
 #define FILE_SEARCH              "hgfs_Search"
 #define FILE_SEARCH_FORM         "fileSearch"
 #define FILE_SEARCH_CURRENT_TAB  "fsCurTab"
 #define FILE_SEARCH_ON_FILETYPE  "fsFileType"
 
 // These are common with trackSearch.  Should they be?
@@ -415,30 +420,37 @@
 
     slPairFreeList(&mdbSelects);
     }
 hFreeConn(&conn);
 
 webNewSection("About " FILE_SEARCH_NAME);
 printf("Search for downloadable ENCODE files by entering search terms in "
        "the Track name or Description fields and/or by making selections with "
        "the group, data format, and/or ENCODE metadata drop-downs.");
 printf("<BR><a target='_blank' href='../goldenPath/help/fileSearch.html'>more help</a>\n");
 }
 
 void doMiddle(struct cart *cart)
 /* Write body of web page. */
 {
+/* Using earlyBotCheck() at the beginning of main() to output message here if in delay time */
+if (issueBotWarning)
+    {
+    char *ip = getenv("REMOTE_ADDR");
+    botDelayMessage(ip, botDelayMillis);
+    }
+
 struct trackDb *tdbList = NULL;
 char *organism = NULL;
 char *db = NULL;
 getDbAndGenome(cart, &db, &organism, NULL);
 char *chrom = cartUsualString(cart, "c", hDefaultChrom(db));
 measureTiming = isNotEmpty(cartOptionalString(cart, "measureTiming"));
 
 // QUESTION: Do We need track list ???  trackHash ??? Can't we just get one track and no children
 trackHash = trackHashMakeWithComposites(db,chrom,&tdbList,FALSE);
 
 cartWebStart(cart, db, "Search for " FILE_SEARCH_WHAT " in the %s %s Assembly", 
              organism, hFreezeFromDb(db));
 
 webIncludeResourceFile("HGStyle.css");
 webIncludeResourceFile("jquery-ui.css");
@@ -455,27 +467,28 @@
 
 doFileSearch(db,organism,cart,tdbList);
 
 
 printf("<BR>\n");
 webEnd();
 }
 
 char *excludeVars[] = { "submit", "Submit", "g", "ajax", "clearCache", 
                         FILE_SEARCH,TRACK_SEARCH_ADD_ROW,TRACK_SEARCH_DEL_ROW};
 
 int main(int argc, char *argv[])
 /* Process command line. */
 {
 long enteredMainTime = clock1000();
+issueBotWarning = earlyBotCheck(enteredMainTime, "hgFileSearch", delayFraction, 0, 0, "html");
 cgiSpoof(&argc, argv);
 cartEmptyShell(doMiddle, hUserCookie(), excludeVars, NULL);
 cgiExitTime("hgFileSearch", enteredMainTime);
 return 0;
 }
 
 // TODO:
 // 1) Done: Limit to first 1000
 // 2) Work out simple verses advanced tabs
 // 3) work out support for non-encode downloads
 // 4) Make an hgTrackSearch to replace hgTracks track search ??   
 //    Simpler code, but may not be good idea because of composite reshaping in cart vars