Index: build/web/building.cgi ================================================================== --- build/web/building.cgi +++ build/web/building.cgi @@ -14,10 +14,16 @@ set resultFormat "html" if {[llength $info] > 1} { set resultFormat [lindex $info 0] } +set scheme http +if {[info exists ::env(HTTPS)]} { + set scheme https +} +set base_url "${scheme}://kitcreator.rkeene.org/kits/$key" + set status "Unknown" set terminal 0 if {![regexp {^[0-9a-f]+$} $key]} { set status "Invalid Key" set terminal 1 @@ -112,15 +118,16 @@ append description ", No packages" } } if {[info exists outfile]} { + set build_log_url "${base_url}/${filename}.log" if {[file exists $outfile]} { set status "Complete" set terminal 1 - set url "http://kitcreator.rkeene.org/kits/$key/$filename" + set url "${base_url}/$filename" } elseif {[file exists "${outfile}.buildfail"]} { set status "Failed" set terminal 1 } else { set status "Building" @@ -127,41 +134,49 @@ } } if {$resultFormat in {json dict}} { set terminalBoolean [lindex {false true} $terminal] + + set resultsDict [dict create \ + status [string tolower $status] \ + terminal $terminalBoolean \ + ] + if {[string tolower $status] eq "complete"} { + dict set resultsDict kit_url $url + } + if {[string tolower $status] in {complete building}} { + dict set resultsDict build_log_url $build_log_url + } } switch -exact -- $resultFormat { "html" { # Handled below } "json" { puts "Content-Type: application/json" puts "" - if {$status eq "Complete"} { - puts "{\"status\":\"[string tolower $status]\", \"terminal\": $terminalBoolean, \"kit_url\":\"$url\"}" - } else { - puts "{\"status\":\"[string tolower $status]\", \"terminal\": $terminalBoolean}" + set resultsJSONItems [list] + foreach {key value} $resultsDict { + switch -exact -- $key { + "terminal" { + } + default { + set value "\"$value\"" + } + } + lappend resultsJSONItems "\"$key\": $value" } + set resultsJSON "{[join $resultsJSONItems {, }]}" + puts $resultsJSON exit 0 } "dict" { puts "Content-Type: text/plain" puts "" - if {$status eq "Complete"} { - puts [dict create \ - status [string tolower $status] \ - terminal $terminalBoolean \ - kit_url $url \ - ] - } else { - puts [dict create \ - status [string tolower $status] \ - terminal $terminalBoolean \ - ] - } + puts $resultsDict exit 0 } default { exit 1 }