| 312 | } |
| 313 | |
| 314 | func (c *CloudStore) ImageWithoutDomain(htmlOld string) (htmlNew string) { |
| 315 | doc, err := goquery.NewDocumentFromReader(strings.NewReader(htmlOld)) |
| 316 | if err != nil { |
| 317 | helper.Logger.Error(err.Error()) |
| 318 | return htmlOld |
| 319 | } |
| 320 | domain := c.GetPublicDomain() |
| 321 | |
| 322 | doc.Find("img").Each(func(i int, s *goquery.Selection) { |
| 323 | // For each item found, get the band and title |
| 324 | if src, exist := s.Attr("src"); exist { |
| 325 | //不存在http开头的图片链接,则更新为绝对链接 |
| 326 | if strings.HasPrefix(src, "http://") || strings.HasPrefix(src, "https://") { |
| 327 | src = strings.TrimPrefix(src, domain) |
| 328 | s.SetAttr("src", src) |
| 329 | } |
| 330 | } |
| 331 | }) |
| 332 | htmlNew, _ = doc.Find("body").Html() |
| 333 | return |
| 334 | } |
| 335 | |
| 336 | //从HTML中提取图片文件,并删除 |
| 337 | func (c *CloudStore) DeleteImageFromHtml(htmlStr string) { |