Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
csznet committed Nov 20, 2023
1 parent e61f63c commit 641903b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion api/vercel.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Vercel(w http.ResponseWriter, r *http.Request) {
// 获取请求路径
path := r.URL.Path
// 如果请求路径以 "/img/" 开头
if strings.HasPrefix(path, "/d/") {
if strings.HasPrefix(path, conf.FileRoute) {
control.D(w, r)
return // 结束处理,确保不执行默认处理
}
Expand Down
17 changes: 5 additions & 12 deletions control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ func UploadImageAPI(w http.ResponseWriter, r *http.Request) {
Code: 0,
Message: "error",
}
var img string
img = conf.FileRoute + utils.UpDocument(utils.TgFileData(header.Filename, file))
img := conf.FileRoute + utils.UpDocument(utils.TgFileData(header.Filename, file))
if img != conf.FileRoute {
res = conf.UploadResponse{
Code: 1,
Expand Down Expand Up @@ -103,7 +102,6 @@ func D(w http.ResponseWriter, r *http.Request) {
return
}
defer resp.Body.Close()
rType := resp.Header.Get("Content-Type")
w.Header().Set("Content-Disposition", "inline") // 设置为 "inline" 以支持在线播放
// 检查Content-Type是否为图片类型
if !strings.HasPrefix(resp.Header.Get("Content-Type"), "application/octet-stream") {
Expand Down Expand Up @@ -148,8 +146,7 @@ func D(w http.ResponseWriter, r *http.Request) {

} else {
// 使用DetectContentType函数检测文件类型
rType = http.DetectContentType(buffer)
w.Header().Set("Content-Type", rType)
w.Header().Set("Content-Type", http.DetectContentType(buffer))
// 写入前512个字节到响应w
_, err = w.Write(buffer[:n])
if err != nil {
Expand Down Expand Up @@ -178,16 +175,14 @@ func Index(w http.ResponseWriter, r *http.Request) {
return
}
// 读取头部模板
headerPath := "templates/header.tmpl"
headerFile, err := assets.Templates.ReadFile(headerPath)
headerFile, err := assets.Templates.ReadFile("templates/header.tmpl")
if err != nil {
http.Error(w, "Header template not found", http.StatusNotFound)
return
}

// 读取页脚模板
footerPath := "templates/footer.tmpl"
footerFile, err := assets.Templates.ReadFile(footerPath)
footerFile, err := assets.Templates.ReadFile("templates/footer.tmpl")
if err != nil {
http.Error(w, "Footer template not found", http.StatusNotFound)
return
Expand Down Expand Up @@ -232,8 +227,7 @@ func Pwd(w http.ResponseWriter, r *http.Request) {
return
}
// 读取头部模板
headerPath := "templates/header.tmpl"
headerFile, err := assets.Templates.ReadFile(headerPath)
headerFile, err := assets.Templates.ReadFile("templates/header.tmpl")
if err != nil {
http.Error(w, "Header template not found", http.StatusNotFound)
return
Expand All @@ -254,7 +248,6 @@ func Pwd(w http.ResponseWriter, r *http.Request) {

// 直接将HTML内容发送给客户端
w.Header().Set("Content-Type", "text/html")
err = tmpl.Execute(w, nil)
if err := tmpl.Execute(w, nil); err != nil {
http.Error(w, "Error rendering HTML template", http.StatusInternalServerError)
}
Expand Down

0 comments on commit 641903b

Please sign in to comment.