|
@@ -3,13 +3,46 @@ package updates
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
+ "io/ioutil"
|
|
|
+ "log"
|
|
|
"net/http"
|
|
|
+ "runtime"
|
|
|
"time"
|
|
|
|
|
|
"github.com/gorilla/websocket"
|
|
|
"imuslab.com/arozos/mod/common"
|
|
|
)
|
|
|
|
|
|
+type UpdateConfig struct {
|
|
|
+ Vendor string `json:"vendor"`
|
|
|
+ Binary struct {
|
|
|
+ Windows struct {
|
|
|
+ Amd64 string `json:"amd64"`
|
|
|
+ Arm string `json:"arm"`
|
|
|
+ Arm64 string `json:"arm64"`
|
|
|
+ I386 string `json:"i386"`
|
|
|
+ } `json:"windows"`
|
|
|
+ Linux struct {
|
|
|
+ Arm string `json:"arm"`
|
|
|
+ Armv7 string `json:"armv7"`
|
|
|
+ Arm64 string `json:"arm64"`
|
|
|
+ Amd64 string `json:"amd64"`
|
|
|
+ Mipsle string `json:"mipsle"`
|
|
|
+ } `json:"linux"`
|
|
|
+ Darwin struct {
|
|
|
+ Amd64 string `json:"amd64"`
|
|
|
+ Arm64 string `json:"arm64"`
|
|
|
+ } `json:"darwin"`
|
|
|
+ Freebsd struct {
|
|
|
+ Amd64 string `json:"amd64"`
|
|
|
+ Arm string `json:"arm"`
|
|
|
+ Arm64 string `json:"arm64"`
|
|
|
+ I386 string `json:"i386"`
|
|
|
+ } `json:"freebsd"`
|
|
|
+ } `json:"binary"`
|
|
|
+ Webpack string `json:"webpack"`
|
|
|
+}
|
|
|
+
|
|
|
func HandleUpdateCheckSize(w http.ResponseWriter, r *http.Request) {
|
|
|
webpack, err := common.Mv(r, "webpack", true)
|
|
|
if err != nil {
|
|
@@ -98,34 +131,46 @@ func HandleUpdateDownloadRequest(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
-func HandleLauncherRestart(w http.ResponseWriter, r *http.Request) {
|
|
|
- //Check if there is a launcher listening to port 25576
|
|
|
- resp, err := http.Get("http://127.0.0.1:25576/chk")
|
|
|
+//Handle getting information for vendor update
|
|
|
+func HandleGetUpdatePlatformInfo(w http.ResponseWriter, r *http.Request) {
|
|
|
+ type UpdatePackageInfo struct {
|
|
|
+ Config UpdateConfig
|
|
|
+ OS string
|
|
|
+ ARCH string
|
|
|
+ }
|
|
|
+
|
|
|
+ //Check if update config find. If yes, parse that
|
|
|
+ updateFileContent, err := ioutil.ReadFile("./system/update.json")
|
|
|
if err != nil {
|
|
|
- common.SendErrorResponse(w, "No launcher found. Unable to restart")
|
|
|
+ common.SendErrorResponse(w, "No vendor update config found")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- content, err := ioutil.ReadAll(resp.Body)
|
|
|
+ //Read from the update config
|
|
|
+ vendorUpdateConfig := UpdateConfig{}
|
|
|
+ err = json.Unmarshal(updateFileContent, &vendorUpdateConfig)
|
|
|
if err != nil {
|
|
|
- common.SendErrorResponse(w, "Read launcher response failed")
|
|
|
+ log.Println("[Updates] Failed to parse update config file: ", err.Error())
|
|
|
+ common.SendErrorResponse(w, "Invalid or corrupted update config")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- execute, _ := common.Mv(r, "exec", true)
|
|
|
- if execute == "true" && r.Method == http.MethodPost {
|
|
|
- //Do the update
|
|
|
- log.Println("REQUESTING LAUNCHER FOR UPDATE RESTART")
|
|
|
+ updateinfo := UpdatePackageInfo{
|
|
|
+ Config: vendorUpdateConfig,
|
|
|
+ OS: runtime.GOOS,
|
|
|
+ ARCH: runtime.GOARCH,
|
|
|
+ }
|
|
|
|
|
|
- common.SendOK(w)
|
|
|
- } else if execute == "true" {
|
|
|
- w.WriteHeader(http.StatusMethodNotAllowed)
|
|
|
- w.Write([]byte("405 - Method Not Allowed"))
|
|
|
+ js, _ := json.Marshal(updateinfo)
|
|
|
+ common.SendJSONResponse(w, string(js))
|
|
|
+}
|
|
|
+
|
|
|
+//Handle check if there is a pending update
|
|
|
+func HandlePendingCheck(w http.ResponseWriter, r *http.Request) {
|
|
|
+ if common.FileExists("./updates/") && common.FileExists("./updates/web/") && common.FileExists("./updates/system/") {
|
|
|
+ //Update is pending
|
|
|
+ common.SendJSONResponse(w, "true")
|
|
|
} else {
|
|
|
- //Return the launcher message
|
|
|
- common.SendTextResponse(w, string(content))
|
|
|
+ common.SendJSONResponse(w, "false")
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-*/
|