Diff

Differences From Artifact [fa17a7dcc9]:

To Artifact [ce6b7093ed]:


12
13
14
15
16
17
18






19
20
21
22
23
24
25
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31







+
+
+
+
+
+







}
set key [lindex $info end]
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

	unset key
110
111
112
113
114
115
116

117
118
119
120
121

122
123
124
125
126
127
128
129
130
131











132
133
134
135
136
137
138
139
140
141

142
143
144
145












146
147
148
149
150
151
152

153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
116
117
118
119
120
121
122
123
124
125
126
127

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

159




160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176


177










178
179
180
181
182
183
184







+




-
+










+
+
+
+
+
+
+
+
+
+
+









-
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+





-
-
+
-
-
-
-
-
-
-
-
-
-







		append description ", Packages: [join $buildinfo(packages) {, }]"
	} else {
		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"
	}
}

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"} {
		set resultsJSONItems [list]
			puts "{\"status\":\"[string tolower $status]\", \"terminal\": $terminalBoolean, \"kit_url\":\"$url\"}"
		} else {
			puts "{\"status\":\"[string tolower $status]\", \"terminal\": $terminalBoolean}"
		}
		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 \
		puts $resultsDict
				status [string tolower $status] \
				terminal $terminalBoolean \
				kit_url $url \
			]
		} else {
			puts [dict create \
				status [string tolower $status] \
				terminal $terminalBoolean \
			]
		}
		exit 0
	}
	default {
		exit 1
	}
}