diff --git a/godo/files/fs.go b/godo/files/fs.go index 0562ce5..d7e635d 100644 --- a/godo/files/fs.go +++ b/godo/files/fs.go @@ -357,7 +357,7 @@ func HandleWriteFile(w http.ResponseWriter, r *http.Request) { ispwd := GetPwdFlag() // 没有加密写入明文 - if ispwd == 0 { + if !ispwd { _, err := io.Copy(file, fileContent) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/godo/files/os.go b/godo/files/os.go index f5c2d49..6898727 100644 --- a/godo/files/os.go +++ b/godo/files/os.go @@ -368,17 +368,20 @@ func GetSalt(r *http.Request) string { } // 获取密码标识位,没有添加上 -func GetPwdFlag() int { - isPwd, has := libs.GetConfig("isPwd") - if !has { - req := libs.ReqBody{ - Name: "isPwd", - Value: 0, - } - libs.SetConfig(req) - libs.SaveConfig() - } - return isPwd.(int) +func GetPwdFlag() bool { + // TODO@lzw:这里有一个bug,ispwd的值存储的是bool类型,但是读取的时候是float64类型,导致无法正确读取 + // isPwd, has := libs.GetConfig("isPwd") + // if !has { + // req := libs.ReqBody{ + // Name: "isPwd", + // Value: false, + // } + // libs.SetConfig(req) + // libs.SaveConfig() + // return false + // } + // return isPwd.(bool) + return false } // 判读一个目录下有没有同名隐藏文件 diff --git a/godo/files/pwdfile.go b/godo/files/pwdfile.go index 0c54d55..37e14a1 100644 --- a/godo/files/pwdfile.go +++ b/godo/files/pwdfile.go @@ -37,14 +37,14 @@ func HandleReadFile(w http.ResponseWriter, r *http.Request) { } // 没有加密 base64明文传输 - if hasPwd == 0 { + if !hasPwd { data := string(fileContent) if !strings.HasPrefix(data, "link::") { data = base64.StdEncoding.EncodeToString(fileContent) - resp := libs.APIResponse{Message: "success", Data: data} - json.NewEncoder(w).Encode(resp) - return } + resp := libs.APIResponse{Message: "success", Data: data} + json.NewEncoder(w).Encode(resp) + return } // 有加密,先校验密码,再解密 @@ -117,9 +117,15 @@ func HandleSetIsPwd(w http.ResponseWriter, r *http.Request) { isPwd := r.URL.Query().Get("ispwd") // 0非加密机器 1加密机器 isPwdValue, _ := strconv.Atoi(isPwd) + var isPwdBool bool + if isPwdValue == 0 { + isPwdBool = false + } else { + isPwdBool = true + } pwdReq := libs.ReqBody{ Name: "isPwd", - Value: isPwdValue, + Value: isPwdBool, } libs.SetConfig(pwdReq) libs.SaveConfig()