From 3bfc2726b43adba6d3ab61c0feac391ea202a8f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=AD=90=E6=97=BA?= <15039612+liu-ziwang123@user.noreply.gitee.com> Date: Thu, 31 Oct 2024 09:21:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AF=86=E7=A0=81=E6=A0=87?= =?UTF-8?q?=E8=AF=86=E4=BD=8D=E6=96=AD=E8=A8=80=E5=A4=B1=E8=B4=A5=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- godo/files/fs.go | 6 +++++- godo/files/os.go | 13 ++++++++++--- godo/files/pwdfile.go | 6 +++++- 3 files changed, 20 insertions(+), 5 deletions(-) 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())