diff --git a/godo/files/fs.go b/godo/files/fs.go index 6a3556e..790cd2e 100644 --- a/godo/files/fs.go +++ b/godo/files/fs.go @@ -353,7 +353,11 @@ func HandleWriteFile(w http.ResponseWriter, r *http.Request) { } // 判读是否加密 - ispwd := GetPwdFlag() + ispwd, err := GetPwdFlag() + if err != nil { + libs.HTTPError(w, http.StatusInternalServerError, err.Error()) + return + } // 没有加密写入明文 if !ispwd { diff --git a/godo/files/os.go b/godo/files/os.go index e8f2831..7fd6560 100644 --- a/godo/files/os.go +++ b/godo/files/os.go @@ -371,7 +371,7 @@ func GetSalt(r *http.Request) string { } // 获取加密标志 -func GetPwdFlag() bool { +func GetPwdFlag() (bool, error) { isPwd, has := libs.GetConfig("isPwd") if !has { // 默认不加密 @@ -381,9 +381,16 @@ func GetPwdFlag() bool { } libs.SetConfig(req) libs.SaveConfig() - return false + return false, nil // 返回默认值和无错误 + } + + // 添加类型断言失败处理 + if pwdFlag, ok := isPwd.(bool); ok { + return pwdFlag, nil } - return isPwd.(bool) + + // 如果断言失败,返回默认值和错误信息 + return false, fmt.Errorf("类型断言失败,期望类型为 bool") } // 检查文件是否加密 diff --git a/godo/files/pwdfile.go b/godo/files/pwdfile.go index 546e340..9ddcbad 100644 --- a/godo/files/pwdfile.go +++ b/godo/files/pwdfile.go @@ -15,7 +15,11 @@ func HandleReadFile(w http.ResponseWriter, r *http.Request) { path := r.URL.Query().Get("path") fPwd := r.Header.Get("fPwd") salt := GetSalt(r) - hasPwd := GetPwdFlag() + hasPwd, err := GetPwdFlag() + if err != nil { + libs.HTTPError(w, http.StatusInternalServerError, err.Error()) + return + } // 校验文件路径 if err := validateFilePath(path); err != nil { libs.HTTPError(w, http.StatusBadRequest, err.Error())