From abfc92a7fa33cbfd599de91b0deceef385ff7552 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 10:33:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=B8=8D=E5=88=B0=E9=93=BE=E6=8E=A5=E6=96=87=E4=BB=B6bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- godo/files/pwdfile.go | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/godo/files/pwdfile.go b/godo/files/pwdfile.go index 9ddcbad..e0bb6ba 100644 --- a/godo/files/pwdfile.go +++ b/godo/files/pwdfile.go @@ -6,14 +6,14 @@ import ( "godo/libs" "net/http" "strconv" + "strings" ) -// 加密读 func HandleReadFile(w http.ResponseWriter, r *http.Request) { // 初始值 path := r.URL.Query().Get("path") - fPwd := r.Header.Get("fPwd") + fPwd := r.Header.Get("filePwd") salt := GetSalt(r) hasPwd, err := GetPwdFlag() if err != nil { @@ -38,12 +38,14 @@ func HandleReadFile(w http.ResponseWriter, r *http.Request) { libs.HTTPError(w, http.StatusNotFound, err.Error()) return } - + fileData := string(fileContent) // 无加密情况 if !hasPwd { - // 直接base64编码原文返回 - data := base64.StdEncoding.EncodeToString(fileContent) - resp := libs.APIResponse{Message: "success", Data: data} + // 判断文件开头是否以link:开头 + if !strings.HasPrefix(fileData, "link::") { + fileData = base64.StdEncoding.EncodeToString(fileContent) + } + resp := libs.APIResponse{Message: "success", Data: fileData} json.NewEncoder(w).Encode(resp) return } @@ -63,10 +65,14 @@ func HandleReadFile(w http.ResponseWriter, r *http.Request) { } // 3. base64编码后返回 - content := base64.StdEncoding.EncodeToString(fileContent) + // 判断文件开头是否以link:开头 + fileData = string(fileContent) + if !strings.HasPrefix(fileData, "link::") { + fileData = base64.StdEncoding.EncodeToString(fileContent) + } // 初始响应 - res := libs.APIResponse{Code: 0, Message: "success", Data: content} + res := libs.APIResponse{Code: 0, Message: "success", Data: fileData} json.NewEncoder(w).Encode(res) } @@ -116,7 +122,11 @@ func HandleChangeFilePwd(w http.ResponseWriter, r *http.Request) { func HandleSetIsPwd(w http.ResponseWriter, r *http.Request) { isPwd := r.URL.Query().Get("ispwd") // 0非加密机器 1加密机器 - isPwdValue, _ := strconv.Atoi(isPwd) + isPwdValue, err := strconv.Atoi(isPwd) + if err != nil { + libs.HTTPError(w, http.StatusBadRequest, err.Error()) + return + } var isPwdBool bool if isPwdValue == 0 { isPwdBool = false