Diff

Differences From Artifact [c7e1a0c441]:

To Artifact [fa17a7dcc9]:


     1      1   #! /usr/bin/env tclsh
     2      2   
     3      3   set outdir "/web/customers/kitcreator.rkeene.org/kits"
     4         -set key ""
            4  +set info [list]
     5      5   if {[info exists ::env(PATH_INFO)]} {
     6         -	set key [lindex [split $::env(PATH_INFO) "/"] 1]
            6  +	set info [lmap item [split $::env(PATH_INFO) /] {
            7  +		if {$item eq ""} {
            8  +			continue
            9  +		}
           10  +		return -level 0 $item
           11  +	}]
           12  +}
           13  +set key [lindex $info end]
           14  +set resultFormat "html"
           15  +if {[llength $info] > 1} {
           16  +	set resultFormat [lindex $info 0]
     7     17   }
     8     18   
     9     19   set status "Unknown"
    10     20   set terminal 0
    11     21   if {![regexp {^[0-9a-f]+$} $key]} {
    12     22   	set status "Invalid Key"
           23  +	set terminal 1
    13     24   
    14     25   	unset key
    15     26   }
    16     27   
    17     28   if {[info exists key]} {
    18     29   	set workdir [file join $outdir $key]
    19     30   }
................................................................................
   111    122   	} elseif {[file exists "${outfile}.buildfail"]} {
   112    123   		set status "Failed"
   113    124   		set terminal 1
   114    125   	} else {
   115    126   		set status "Building"
   116    127   	}
   117    128   }
          129  +
          130  +if {$resultFormat in {json dict}} {
          131  +	set terminalBoolean [lindex {false true} $terminal]
          132  +}
          133  +
          134  +switch -exact -- $resultFormat {
          135  +	"html" {
          136  +		# Handled below
          137  +	}
          138  +	"json" {
          139  +		puts "Content-Type: application/json"
          140  +		puts ""
          141  +		if {$status eq "Complete"} {
          142  +			puts "{\"status\":\"[string tolower $status]\", \"terminal\": $terminalBoolean, \"kit_url\":\"$url\"}"
          143  +		} else {
          144  +			puts "{\"status\":\"[string tolower $status]\", \"terminal\": $terminalBoolean}"
          145  +		}
          146  +		exit 0
          147  +	}
          148  +	"dict" {
          149  +		puts "Content-Type: text/plain"
          150  +		puts ""
          151  +		if {$status eq "Complete"} {
          152  +			puts [dict create \
          153  +				status [string tolower $status] \
          154  +				terminal $terminalBoolean \
          155  +				kit_url $url \
          156  +			]
          157  +		} else {
          158  +			puts [dict create \
          159  +				status [string tolower $status] \
          160  +				terminal $terminalBoolean \
          161  +			]
          162  +		}
          163  +		exit 0
          164  +	}
          165  +	default {
          166  +		exit 1
          167  +	}
          168  +}
   118    169   
   119    170   puts "Content-Type: text/html"
   120    171   if {[info exists url]} {
   121    172   	# Use a refresh here instead of a "Location" so that
   122    173   	# the client can see the page
   123    174   	puts "Refresh: 0;url=$url"
   124    175   } else {