1
0
mirror of https://github.com/j-a-n/raspberrymatic-addon-rmupdate.git synced 2023-10-10 11:37:40 +00:00

working version

This commit is contained in:
Jan Schneider
2017-03-26 00:26:39 +01:00
parent 63580ae33f
commit 0f3cc9b506
4 changed files with 162 additions and 115 deletions

View File

@@ -47,43 +47,36 @@ proc process {} {
return "\"[rmupdate::version]\""
} elseif {[lindex $path 1] == "get_firmware_info"} {
return [rmupdate::get_firmware_info]
} elseif {[lindex $path 1] == "install_firmware"} {
fconfigure stdout -buffering none
#puts "Content-Type: application/octet-stream"
puts "Content-Type: text/html; charset=utf-8"
puts "Status: 200 OK";
puts ""
flush stdout
after 1000
puts "Line 1\n"
flush stdout
after 1000
puts "Line 2\n"
flush stdout
after 1000
puts "Line 3\n"
flush stdout
after 1000
puts "Line 4\n"
flush stdout
return ""
} elseif {[lindex $path 1] == "start_install_firmware"} {
regexp {^([\d\.]+)$} $data match version
if { [info exists version] && $version != "" } {
rmupdate::install_firmware_version $version
return "\"done\""
} else {
error "Invalid version: ${data}"
}
} elseif {[lindex $path 1] == "read_install_log"} {
variable content_type "text/html"
return [rmupdate::read_install_log]
}
}
error "invalid request" "Not found" 404
}
variable content_type "application/json"
if [catch {process} result] {
set status 500
if { [info exists $errorCode] } {
set status $errorCode
}
puts "Content-Type: application/json"
puts "Content-Type: ${content_type}"
puts "Status: $status";
puts ""
set result [json_string $result]
puts -nonewline "\{\"error\":\"${result}\"\}"
} elseif {$result != ""} {
puts "Content-Type: application/json"
} else {
puts "Content-Type: ${content_type}"
puts "Status: 200 OK";
puts ""
puts -nonewline $result