diff --git a/cmd/upgrade/main.go b/cmd/upgrade/main.go index 83e5ff798..687b52f26 100644 --- a/cmd/upgrade/main.go +++ b/cmd/upgrade/main.go @@ -6,61 +6,16 @@ import ( "fmt" "go_dreamfactory/cmd/upgrade/tools" "html/template" - "io" "io/ioutil" "log" "net/http" - "os" "path" - "strconv" "strings" "time" "github.com/gin-gonic/gin" ) -// func main() { -// http.HandleFunc("/download", FileDownload) -// http.HandleFunc("/upload", FileUpload) - -// log.Print("http server start") -// if err := http.ListenAndServe(":8910", nil); err != nil { -// log.Fatal(err) -// } -// } - -func FileUpload(w http.ResponseWriter, r *http.Request) { - //获取文件流,第三个返回值是错误对象 - file, header, _ := r.FormFile("file") - //读取文件流为[]byte - b, _ := ioutil.ReadAll(file) - //把文件保存到指定位置 - ioutil.WriteFile("/opt/upgrade", b, 0777) - //输出上传时文件名 - fmt.Println("上传文件名:", header.Filename) -} - -func FileDownload(w http.ResponseWriter, r *http.Request) { - filename := "E:\\projects\\workspace\\go_dreamfactory\\cmd\\v2\\RobotGUI.exe" - - file, _ := os.Open(filename) - defer file.Close() - - fileHeader := make([]byte, 512) - file.Read(fileHeader) - - fileStat, _ := file.Stat() - - w.Header().Set("Content-Disposition", "attachment; filename="+filename) - w.Header().Set("Content-Type", http.DetectContentType(fileHeader)) - w.Header().Set("Content-Length", strconv.FormatInt(fileStat.Size(), 10)) - - file.Seek(0, 0) - io.Copy(w, file) - - return -} - //go:embed views/* var f embed.FS @@ -92,6 +47,11 @@ func main() { c.HTML(http.StatusOK, "index.html", nil) }) + r.GET("/upload", func(c *gin.Context) { + fmt.Println(tmpl.DefinedTemplates()) + c.HTML(http.StatusOK, "upload.html", nil) + }) + r.POST("/upload", func(c *gin.Context) { f, err := c.FormFile("file") if err != nil { diff --git a/cmd/upgrade/readme.md b/cmd/upgrade/readme.md index e69de29bb..93367b14b 100644 --- a/cmd/upgrade/readme.md +++ b/cmd/upgrade/readme.md @@ -0,0 +1,5 @@ +解压文件 +- resources +- RobotGUI.exe + +建议覆盖所有文件 \ No newline at end of file diff --git a/cmd/upgrade/views/index.html b/cmd/upgrade/views/index.html index d8181e590..c4470ff00 100644 --- a/cmd/upgrade/views/index.html +++ b/cmd/upgrade/views/index.html @@ -20,21 +20,7 @@
点击或者拖拽上传
-点击或者拖拽上传
+