Skip to content

Commit

Permalink
Small changes and cleanup to update code
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroglyph committed Apr 27, 2019
1 parent 2f9cd7b commit 199b891
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
23 changes: 9 additions & 14 deletions fow-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,6 @@ type configuration struct {
updatesDirectory string
}

type updateInfo struct {
version string
channel string
hardwareRevision string
contentType string // Usually "spiffs" or "flash"
file *os.File
md5String string // Hex encoded
}

var (
data *ferryData
config configuration
Expand Down Expand Up @@ -102,7 +93,7 @@ func main() {
}
currentPath = seattleBainbridgePath.getProcessedPath() // This is the only available path, but we could switch based on a flag if we wanted to later

log.Println("Flags parsed.")
log.Println("Flags parsed")

client := wsf.NewClient(nil)
client.AccessCode = config.accessCode
Expand All @@ -114,15 +105,14 @@ func main() {
log.Println("Trying to bind to", config.bind+"...")

if config.debugMode {
log.Println("Serving debug information under /debug.")
log.Println("Serving debug information under /debug")
http.HandleFunc("/debug", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, config.debugPagePath)
})
http.HandleFunc("/debug/get/", debugHandler)
http.HandleFunc("/debug/path/coords", pathCoordInfoHandler)
}
if config.updatesDirectory != "" {
http.HandleFunc("/update", updateHandler)
paths, err := filepath.Glob(filepath.Clean(config.updatesDirectory) + "/*.bin")
if err != nil {
log.Fatal(err)
Expand All @@ -137,15 +127,19 @@ func main() {

split = strings.Split(filename, "@")
if len(split) < 2 {
log.Println("Update name", filename, "is invalid.")
log.Println("Update name \"" + filename + "\" is invalid")
continue
}
info.version = split[0]
key = split[1]

if _, keyAlreadySet := updateFiles[key]; keyAlreadySet {
log.Fatal("Duplicate update files for key \"" + key + "\". Cannot continue!")
}

split = strings.Split(split[1], ":")
if len(split) < 2 {
log.Println("Update channel and hardware revision part \"", split[1], "\" is invalid")
log.Println("Update channel and hardware revision part \"" + split[1] + "\" is invalid")
continue
}

Expand All @@ -170,6 +164,7 @@ func main() {

updateFiles[key] = info
}
http.HandleFunc("/update", updateHandler)
}
http.HandleFunc("/progress", progressHandler)
log.Panicln(http.ListenAndServe(config.bind, nil))
Expand Down
10 changes: 10 additions & 0 deletions fow-server/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"io"
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
Expand All @@ -13,6 +14,15 @@ const (
typeQueryKey = "type"
)

type updateInfo struct {
version string
channel string
hardwareRevision string
contentType string // Usually "spiffs" or "flash"
file *os.File
md5String string // Hex encoded
}

func updateHandler(w http.ResponseWriter, r *http.Request) {
if r.URL.Query().Get(typeQueryKey) == "" {
http.Error(w, "Invalid type query parameter", http.StatusBadRequest)
Expand Down

0 comments on commit 199b891

Please sign in to comment.