从HTML中提取图片文件,并删除
(htmlStr string)
| 335 | |
| 336 | //从HTML中提取图片文件,并删除 |
| 337 | func (c *CloudStore) DeleteImageFromHtml(htmlStr string) { |
| 338 | doc, err := goquery.NewDocumentFromReader(strings.NewReader(htmlStr)) |
| 339 | if err != nil { |
| 340 | helper.Logger.Error(err.Error()) |
| 341 | return |
| 342 | } |
| 343 | |
| 344 | var objects []string |
| 345 | |
| 346 | domain := c.GetPublicDomain() |
| 347 | |
| 348 | doc.Find("img").Each(func(i int, s *goquery.Selection) { |
| 349 | // For each item found, get the band and title |
| 350 | if src, exist := s.Attr("src"); exist { |
| 351 | //不存在http开头的图片链接,则更新为绝对链接 |
| 352 | if !(strings.HasPrefix(src, "http://") || strings.HasPrefix(src, "https://")) { |
| 353 | objects = append(objects, src) |
| 354 | } else { |
| 355 | src = strings.TrimPrefix(src, domain) |
| 356 | objects = append(objects, src) |
| 357 | } |
| 358 | } |
| 359 | }) |
| 360 | if err = c.Delete(objects...); err != nil { |
| 361 | helper.Logger.Error(err.Error()) |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | func (c *CloudStore) PingTest() (err error) { |
| 366 | tmpFile := "dochub-test-file.txt" |
no test coverage detected