CasaOS - A simple, easy-to-use, elegant open-source Personal Cloud system.
Update entry json output (#1172)
linkf867453573c1
diff --git a/go.mod b/go.modindex 0b32cb5..6b1a91a 100644--- a/go.mod+++ b/go.mod@@ -41,7 +41,6 @@ require (go.uber.org/goleak v1.2.1go.uber.org/zap v1.24.0golang.org/x/crypto v0.8.0- golang.org/x/net v0.9.0golang.org/x/oauth2 v0.6.0golang.org/x/sync v0.1.0golang.org/x/sys v0.7.0@@ -124,6 +123,7 @@ require (golang.org/x/arch v0.3.0 // indirectgolang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirectgolang.org/x/image v0.6.0 // indirect+ golang.org/x/net v0.9.0 // indirectgolang.org/x/text v0.9.0 // indirectgolang.org/x/time v0.3.0 // indirectgoogle.golang.org/appengine v1.6.7 // indirectdiff --git a/main.go b/main.goindex 2462a10..82c8733 100644--- a/main.go+++ b/main.go@@ -106,15 +106,11 @@ func main() {v2Router := route.InitV2Router()v2DocRouter := route.InitV2DocRouter(_docHTML, _docYAML)- v3file := route.InitFile()- v4dir := route.InitDir()mux := &util_http.HandlerMultiplexer{HandlerMap: map[string]http.Handler{"v1": v1Router,"v2": v2Router,"doc": v2DocRouter,- "v3": v3file,- "v4": v4dir,},}@@ -147,7 +143,6 @@ func main() {"/v1/test",route.V2APIPath,route.V2DocPath,- route.V3FilePath,}for _, apiPath := range routers {err = service.MyService.Gateway().CreateRoute(&model.Route{diff --git a/route/v1/system.go b/route/v1/system.goindex b1de6cc..9c6c81e 100644--- a/route/v1/system.go+++ b/route/v1/system.go@@ -2,6 +2,7 @@ package v1import ("bytes"+ "encoding/json""fmt""io""io/ioutil"@@ -375,9 +376,10 @@ func PortCheck(c *gin.Context) {func GetSystemEntry(c *gin.Context) {entry := service.MyService.System().GetSystemEntry()- if !gjson.Valid(entry) {- c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: ""})+ str := json.RawMessage(entry)+ if !gjson.ValidBytes(str) {+ c.JSON(http.StatusInternalServerError, model.Result{Success: common_err.SERVICE_ERROR, Message: entry, Data: "[]"})return}- c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: entry})+ c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: str})}diff --git a/route/v2.go b/route/v2.goindex d2985f6..8d346c6 100644--- a/route/v2.go+++ b/route/v2.go@@ -2,17 +2,13 @@ package routeimport ("crypto/ecdsa"- "log""net/http""net/url"- "path"- "path/filepath""strconv""strings""github.com/IceWhaleTech/CasaOS/codegen""github.com/IceWhaleTech/CasaOS/pkg/config"- "github.com/IceWhaleTech/CasaOS/pkg/utils/file""github.com/IceWhaleTech/CasaOS-Common/external""github.com/IceWhaleTech/CasaOS-Common/utils/jwt"@@ -27,10 +23,8 @@ import (var (_swagger *openapi3.T- V2APIPath string- V2DocPath string- V3FilePath string- V4DirPath string+ V2APIPath string+ V2DocPath string)func init() {@@ -48,8 +42,6 @@ func init() {V2APIPath = strings.TrimRight(u.Path, "/")V2DocPath = "/doc" + V2APIPath- V3FilePath = "/v3/file"- V4DirPath = "/v4/dir"}func InitV2Router() http.Handler {@@ -139,87 +131,3 @@ func InitV2DocRouter(docHTML string, docYAML string) http.Handler {}})}--func InitFile() http.Handler {- return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {- filePath := r.URL.Query().Get("path")- fileName := path.Base(filePath)- w.Header().Add("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(fileName))- http.ServeFile(w, r, filePath)- })-}--func InitDir() http.Handler {- return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {- t := r.URL.Query().Get("format")- files := r.URL.Query().Get("files")-- if len(files) == 0 {- // w.JSON(common_err.CLIENT_ERROR, model.Result{- // Success: common_err.INVALID_PARAMS,- // Message: common_err.GetMsg(common_err.INVALID_PARAMS),- // })- return- }- list := strings.Split(files, ",")- for _, v := range list {- if !file.Exists(v) {- // c.JSON(common_err.SERVICE_ERROR, model.Result{- // Success: common_err.FILE_DOES_NOT_EXIST,- // Message: common_err.GetMsg(common_err.FILE_DOES_NOT_EXIST),- // })- return- }- }- w.Header().Add("Content-Type", "application/octet-stream")- w.Header().Add("Content-Transfer-Encoding", "binary")- w.Header().Add("Cache-Control", "no-cache")- // handles only single files not folders and multiple files- // if len(list) == 1 {-- // filePath := list[0]- // info, err := os.Stat(filePath)- // if err != nil {-- // w.JSON(http.StatusOK, model.Result{- // Success: common_err.FILE_DOES_NOT_EXIST,- // Message: common_err.GetMsg(common_err.FILE_DOES_NOT_EXIST),- // })- //return- // }- //}-- extension, ar, err := file.GetCompressionAlgorithm(t)- if err != nil {- // w.JSON(common_err.CLIENT_ERROR, model.Result{- // Success: common_err.INVALID_PARAMS,- // Message: common_err.GetMsg(common_err.INVALID_PARAMS),- // })- return- }-- err = ar.Create(w)- if err != nil {- // c.JSON(common_err.SERVICE_ERROR, model.Result{- // Success: common_err.SERVICE_ERROR,- // Message: common_err.GetMsg(common_err.SERVICE_ERROR),- // Data: err.Error(),- // })- return- }- defer ar.Close()- commonDir := file.CommonPrefix(filepath.Separator, list...)-- currentPath := filepath.Base(commonDir)-- name := "_" + currentPath- name += extension- w.Header().Add("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(name))- for _, fname := range list {- err = file.AddFile(ar, fname, commonDir)- if err != nil {- log.Printf("Failed to archive %s: %v", fname, err)- }- }- })-}