Skip to content

Commit

Permalink
const file view route
Browse files Browse the repository at this point in the history
  • Loading branch information
csznet committed Nov 17, 2023
1 parent e76a796 commit 6ca420e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ type UploadResponse struct {
Code int `json:"code"`
Message string `json:"message"`
}

const FileRoute = "/d/"
6 changes: 3 additions & 3 deletions control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func UploadImageAPI(w http.ResponseWriter, r *http.Request) {
Message: "error",
}
var img string
img = "/d/" + utils.UpDocument(utils.TgFileData(header.Filename, file))
if img != "/d/" {
img = conf.FileRoute + utils.UpDocument(utils.TgFileData(header.Filename, file))
if img != conf.FileRoute {
res = conf.UploadResponse{
Code: 1,
Message: img,
Expand All @@ -87,7 +87,7 @@ func errJsonMsg(msg string, w http.ResponseWriter) {
}
func D(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
id := strings.TrimPrefix(path, "/d/")
id := strings.TrimPrefix(path, conf.FileRoute)
if id == "" {
// 设置响应的状态码为 404
w.WriteHeader(http.StatusNotFound)
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func web() {
if conf.Pass != "" && conf.Pass != "none" {
http.HandleFunc("/pwd", control.Pwd)
}
http.HandleFunc("/d/", control.D)
http.HandleFunc(conf.FileRoute, control.D)
http.HandleFunc("/api", control.Middleware(control.UploadImageAPI))
if index {
http.HandleFunc("/", control.Middleware(control.Index))
Expand Down

0 comments on commit 6ca420e

Please sign in to comment.