Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c635c1e

Browse files
committed
图片处理 bugfix
1 parent 057b49d commit c635c1e

File tree

5 files changed

+9
-10
lines changed

5 files changed

+9
-10
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ require (
3636
github.com/olekukonko/tablewriter v0.0.1 // indirect
3737
github.com/polaris1119/config v0.0.0-20160609095218-06a751e884f3
3838
github.com/polaris1119/email v0.0.0-20171030115359-9c57dd3e3e7d
39-
github.com/polaris1119/goutils v0.0.0-20160602032428-582c98b3184b
39+
github.com/polaris1119/goutils v0.0.0-20190815094239-73c47df9b896
4040
github.com/polaris1119/keyword v0.0.0-20170608075927-96ae6735f2f2
4141
github.com/polaris1119/logger v0.0.0-20170422061149-0233d014769e
4242
github.com/polaris1119/nosql v0.0.0-20181019111233-3852ef28d084

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ github.com/polaris1119/email v0.0.0-20171030115359-9c57dd3e3e7d h1:5Tx8BuKqRGhit
158158
github.com/polaris1119/email v0.0.0-20171030115359-9c57dd3e3e7d/go.mod h1:3S7Km+d2GftzOJJgrvIGHDtRxm5eUZamHaoUzLZNJX0=
159159
github.com/polaris1119/goutils v0.0.0-20160602032428-582c98b3184b h1:THcO90yP3NaMbkQmcnKyu8wJBS1iSO3Z7eAo5axqVbA=
160160
github.com/polaris1119/goutils v0.0.0-20160602032428-582c98b3184b/go.mod h1:yHb+G3YG7G0Hf0EIXCjbOe/Aus8TXZtYa/ZPEqyMxXU=
161+
github.com/polaris1119/goutils v0.0.0-20190815094239-73c47df9b896 h1:BYTbNGq/6Y28744ZVeOcD9s0qkeuTrDka8PCbaXPs4g=
162+
github.com/polaris1119/goutils v0.0.0-20190815094239-73c47df9b896/go.mod h1:yHb+G3YG7G0Hf0EIXCjbOe/Aus8TXZtYa/ZPEqyMxXU=
161163
github.com/polaris1119/keyword v0.0.0-20170608075927-96ae6735f2f2 h1:63TyJE7nj3eUsJ/1jbzrnH8gxw1z3oV/su2RIyVHlRQ=
162164
github.com/polaris1119/keyword v0.0.0-20170608075927-96ae6735f2f2/go.mod h1:YYx1sYXgS43cG1iH0cXYFcibESl8azhUrA6W10gYb9E=
163165
github.com/polaris1119/logger v0.0.0-20170422061149-0233d014769e h1:HSeLmpKe7eny4fT5tdnYfQffWvx6aKCdzIcW/MZWt3I=

logic/article.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,9 @@ func (self ArticleLogic) transferImage(ctx context.Context, s *goquery.Selection
867867

868868
func (self ArticleLogic) setImgSrc(ctx context.Context, v string, imgDeny bool, s *goquery.Selection, domain string) {
869869
if imgDeny {
870-
if !strings.HasPrefix(v, "http") {
870+
if strings.HasPrefix(v, "//") {
871+
v = "https:" + v
872+
} else if !strings.HasPrefix(v, "http") {
871873
v = "http://" + domain + "/" + v
872874
}
873875
path, err := DefaultUploader.TransferUrl(ctx, v)

logic/resource.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,18 @@ func (ResourceLogic) Publish(ctx context.Context, me *model.Me, form url.Values)
4444
return
4545
}
4646

47-
fields := []string{"title", "catid", "form", "url", "content"}
4847
if form.Get("form") == model.LinkForm {
4948
form.Set("content", "")
5049
} else {
5150
form.Set("url", "")
5251
}
5352

54-
for _, field := range fields {
55-
form.Del(field)
56-
}
57-
5853
err = schemaDecoder.Decode(resource, form)
5954
if err != nil {
6055
objLog.Errorln("ResourceLogic Publish decode error:", err)
6156
return
6257
}
63-
_, err = MasterDB.Id(id).Update(resource)
58+
_, err = MasterDB.ID(id).Update(resource)
6459
if err != nil {
6560
objLog.Errorf("更新资源 【%s】 信息失败:%s\n", id, err)
6661
return

logic/uploader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,12 @@ func (this *UploaderLogic) TransferUrl(ctx context.Context, origUrl string, pref
219219
exts, err := mime.ExtensionsByType(contentType)
220220
if err != nil {
221221
logger.Errorln("detect extension error:", err, "orig url:", origUrl)
222-
} else if len(exts) > 0 {
222+
} else if len(exts) > 0 {
223223
ext = exts[0]
224224
}
225225
}
226226

227-
if ext == "" || !strings.Contains("png,jpg,jpeg,gif,bmp", strings.ToLower(ext)) {
227+
if ext == "" && !strings.Contains("png,jpg,jpeg,gif,bmp", strings.ToLower(ext)) {
228228
logger.Errorln("can't fetch extension, url:", origUrl)
229229
return origUrl, errors.New("can't fetch extension")
230230
}

0 commit comments

Comments
 (0)