fix(local): filename with whitespace issue (#3928)

* fix(local): filename whitespace problem

* fix(deps): remove deprecated package io/ioutil

---------

Co-authored-by: XZB <i@1248.ink>
This commit is contained in:
XZB-1248
2023-03-23 15:18:37 +08:00
committed by GitHub
parent c6af22b97e
commit 0eab31bdf5
4 changed files with 24 additions and 9 deletions

View File

@ -3,7 +3,6 @@ package common
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
@ -61,7 +60,8 @@ func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.
if err != nil {
return err
}
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`, file.GetName(), url.QueryEscape(file.GetName())))
filename := file.GetName()
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`, filename, url.PathEscape(filename)))
http.ServeContent(w, r, file.GetName(), fileStat.ModTime(), f)
return nil
} else {
@ -93,7 +93,7 @@ func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.
}
w.WriteHeader(res.StatusCode)
if res.StatusCode >= 400 {
all, _ := ioutil.ReadAll(res.Body)
all, _ := io.ReadAll(res.Body)
msg := string(all)
log.Debugln(msg)
return errors.New(msg)