Skip to content

Commit 65545fa

Browse files
committed
修正图片链接
1 parent 217d639 commit 65545fa

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

controllers/BookController.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ func (this *BookController) UploadCover() {
427427
url = string(url[1:])
428428
}
429429

430-
oldCover := book.Cover
430+
oldCover := strings.ReplaceAll(book.Cover, "\\", "/")
431431
osspath := fmt.Sprintf("projects/%v/%v", book.Identify, strings.TrimLeft(url, "./"))
432432
book.Cover = "/" + osspath
433433
if utils.StoreType == utils.StoreLocal {

controllers/StaticController.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,19 @@ func (this *StaticController) Uploads() {
3939
file := strings.TrimLeft(this.GetString(":splat"), "./")
4040
path := strings.ReplaceAll(filepath.Join("uploads", file), "\\", "/")
4141

42-
// 签名验证
43-
sign := this.GetString("sign")
44-
if !this.isValidSign(sign, path) {
45-
// 签名验证不通过,需要再次验证书籍是否是用户的(针对编辑状态)
46-
if !this.isBookOwner() {
47-
this.Abort("404")
48-
return
42+
if this.isMedia(path) { // 签名验证
43+
sign := this.GetString("sign")
44+
if !this.isValidSign(sign, path) {
45+
// 签名验证不通过,需要再次验证书籍是否是用户的(针对编辑状态)
46+
if !this.isBookOwner() {
47+
this.Abort("404")
48+
return
49+
}
4950
}
50-
}
5151

52-
if utils.IsSignUsed(sign) {
53-
this.Abort("404")
52+
if utils.IsSignUsed(sign) {
53+
this.Abort("404")
54+
}
5455
}
5556

5657
http.ServeFile(this.Ctx.ResponseWriter, this.Ctx.Request, path)
@@ -63,7 +64,8 @@ func (this *StaticController) StaticFile() {
6364
http.ServeFile(this.Ctx.ResponseWriter, this.Ctx.Request, file)
6465
return
6566
}
66-
file = strings.TrimLeft(file, "./")
67+
fmt.Println(file, "===============")
68+
file = strings.ReplaceAll(strings.TrimLeft(file, "./"), "\\", "/")
6769
path := filepath.Join(utils.VirtualRoot, file)
6870
http.ServeFile(this.Ctx.ResponseWriter, this.Ctx.Request, path)
6971
}

models/book.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ func (m *Book) ThoroughDeleteBook(id int) (err error) {
327327
//删除oss中书籍对应的文件夹
328328
switch utils.StoreType {
329329
case utils.StoreLocal: //删除本地存储,记得加上uploads
330+
m.Cover = strings.ReplaceAll(m.Cover, "\\", "/")
330331
if m.Cover != beego.AppConfig.DefaultString("cover", "/static/images/book.png") {
331332
os.Remove(strings.TrimLeft(m.Cover, "/ ")) //删除封面
332333
}
@@ -557,7 +558,7 @@ func (book *Book) ToBookResult() (m *BookResult) {
557558
m.CommentCount = book.CommentCount
558559
m.CreateTime = book.CreateTime
559560
m.ModifyTime = book.ModifyTime
560-
m.Cover = book.Cover
561+
m.Cover = strings.ReplaceAll(book.Cover, "\\", "/")
561562
m.MemberId = book.MemberId
562563
m.Label = book.Label
563564
m.Status = book.Status

models/book_counter.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io/ioutil"
77
"os"
88
"strconv"
9+
"strings"
910
"time"
1011

1112
"github.com/astaxie/beego/orm"
@@ -129,7 +130,7 @@ func (*BookCounter) _sort(prd period, limit int, orderField string, withCache ..
129130
books = append(books, SortedBook{
130131
BookId: book.BookId,
131132
Identify: book.Identify,
132-
Cover: book.Cover,
133+
Cover: strings.ReplaceAll(book.Cover, "\\", "/"),
133134
BookName: book.BookName,
134135
Cnt: cnt,
135136
})

utils/util.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ func HandleSVG(doc *goquery.Document, project string) *goquery.Document {
570570
//操作图片显示
571571
//如果用的是oss存储,这style是avatar、cover可选项
572572
func ShowImg(img string, style ...string) (url string) {
573+
img = strings.ReplaceAll(img, "\\", "/")
573574
if strings.HasPrefix(img, "https://") || strings.HasPrefix(img, "http://") {
574575
return img
575576
}

0 commit comments

Comments
 (0)