@@ -292,7 +292,7 @@ function correct_ReadMapCount(class_name) {
292292
293293 for ( const element of x ) {
294294 element . value = element . value . trim ( ) ;
295- if ( element . value === ( "" || null || undefined ) ) {
295+ if ( ! element . value ) {
296296 element . value = 0 ;
297297 }
298298 element . value = only_ReadNum ( element . value ) ;
@@ -326,55 +326,46 @@ function only_ReadNum(input_string) {
326326function check_links ( bam_name , repo_name ) {
327327 const x = document . getElementById ( "Entries_all" ) . querySelectorAll ( repo_name ) ;
328328 const bam_x = document . getElementById ( "Entries_all" ) . querySelectorAll ( bam_name ) ;
329+ let foundBamInput = false ;
330+
329331 for ( let i = 0 ; i < x . length ; i ++ ) {
330332 if ( x [ i ] . id === "bam_input" ) {
331- if ( x [ i ] . value . length > 0 ) {
332- if ( bam_x [ i ] . value == "Google Drive" ) {
333- // Verify if Google Link
334- const driveLink = x [ i ] . value . split ( "//" ) ;
335- if ( driveLink . length > 1 ) {
336- // If starts with https
337- const driveURL = driveLink [ 1 ] ;
338- return (
339- driveURL . split ( "/" ) [ 0 ] === "drive.google.com" ||
340- driveURL . split ( "/" ) [ 0 ] === "www.drive.google.com"
341- ) ;
342- } else if ( driveLink . length === 0 ) {
343- // If does not start with https
344- return (
345- driveLink . split ( "/" ) [ 0 ] === "drive.google.com" ||
346- driveLink . split ( "/" ) [ 0 ] === "www.drive.google.com"
347- ) ;
348- } else {
349- // Not URL
350- return false ;
351- }
352- } else if ( bam_x [ i ] . value == "Amazon AWS" ) {
353- /** Link from string to URL format */
354- const urlString = new URL ( x [ i ] . value ) ;
355-
356- if (
357- ( urlString . host ( "s3.amazonaws.com" ) || x [ i ] . value . includes ( "araport.cyverse-cdn.tacc.cloud" ) ) &&
358- check_amazon_for_bam ( x [ i ] . value )
359- ) {
360- return true ;
361- } else if (
362- ( urlString . host ( "s3.amazonaws.com" ) ||
363- x [ i ] . value . includes ( "araport.cyverse-cdn.tacc.cloud/" ) ) &&
364- check_amazon_for_bam ( x [ i ] . value )
365- ) {
366- return false ;
367- } else {
368- return false ;
369- }
370- } else {
333+ foundBamInput = true ;
334+ if ( ! x [ i ] . value || ! bam_x ?. [ i ] ?. value ) {
335+ return false ;
336+ }
337+
338+ let urlString ;
339+ try {
340+ urlString = new URL ( x [ i ] . value ) ;
341+ } catch {
342+ return false ;
343+ }
344+
345+ const hostValue = urlString ?. host ?? "" ;
346+ const bamHostType = bam_x [ i ] . value ;
347+
348+ if ( bamHostType === "Google Drive" ) {
349+ if ( ! [ "drive.google.com" , "www.drive.google.com" ] . includes ( hostValue ) ) {
350+ return false ;
351+ }
352+ } else if ( bamHostType === "Amazon AWS" ) {
353+ if (
354+ ! check_amazon_for_bam ( x [ i ] . value ) ||
355+ ! (
356+ [ "s3.amazonaws.com" , "araport.cyverse-cdn.tacc.cloud" ] . includes ( hostValue ) ||
357+ x [ i ] . value . includes ( "araport.cyverse-cdn.tacc.cloud" )
358+ )
359+ ) {
371360 return false ;
372361 }
373362 } else {
374363 return false ;
375364 }
376365 }
377366 }
367+
368+ return foundBamInput ;
378369}
379370
380371/**
@@ -507,19 +498,21 @@ function outline_links(bam_name, repo_name) {
507498
508499 /** URL for the hosted BAM file */
509500 let urlValue ;
501+ let hostValue = "" ;
510502
511- // Convert the
503+ // Convert the string into a URL object if valid
512504 try {
513505 urlValue = new URL ( x [ i ] . value ) ;
506+ hostValue = urlValue . host || "" ;
514507 } catch {
515508 console . error ( "Unreadable URL presented: " , x [ i ] . value ) ;
516509 }
517510
518- if ( bamHostType && urlValue ) {
511+ if ( bamHostType && hostValue ) {
519512 if ( bamHostType === "Amazon AWS" ) {
520513 if (
521514 check_amazon_for_bam ( x [ i ] . value ) &&
522- [ "s3.amazonaws.com" , "araport.cyverse-cdn.tacc.cloud" ] . includes ( urlValue [ host ] )
515+ [ "s3.amazonaws.com" , "araport.cyverse-cdn.tacc.cloud" ] . includes ( hostValue )
523516 ) {
524517 x [ i ] . style . borderColor = null ;
525518 x [ i ] . style . boxShadow = null ;
@@ -528,7 +521,7 @@ function outline_links(bam_name, repo_name) {
528521 x [ i ] . style . boxShadow = "0 0 10px #ff2626" ;
529522 }
530523 } else if ( bamHostType === "Google Drive" ) {
531- if ( [ "drive.google.com" ] . includes ( urlValue [ host ] ) ) {
524+ if ( [ "drive.google.com" , "www.drive.google.com" ] . includes ( hostValue ) ) {
532525 x [ i ] . style . borderColor = null ;
533526 x [ i ] . style . boxShadow = null ;
534527 } else {
@@ -1300,3 +1293,12 @@ function initGen() {
13001293setTimeout ( function ( ) {
13011294 initGen ( ) ;
13021295} , 1000 ) ;
1296+
1297+ // Export functions for testing in Node.js environments
1298+ if ( typeof module !== "undefined" && module . exports ) {
1299+ module . exports = {
1300+ update,
1301+ check_links,
1302+ check_amazon_for_bam,
1303+ } ;
1304+ }
0 commit comments