MCPcopy Index your code
hub / github.com/TruthHun/DocHub / DeleteImageFromHtml

Method DeleteImageFromHtml

models/CloudStoreModel.go:337–363  ·  view source on GitHub ↗

从HTML中提取图片文件,并删除

(htmlStr string)

Source from the content-addressed store, hash-verified

335
336//从HTML中提取图片文件,并删除
337func (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
365func (c *CloudStore) PingTest() (err error) {
366 tmpFile := "dochub-test-file.txt"

Callers 1

DelMethod · 0.95

Calls 2

GetPublicDomainMethod · 0.95
DeleteMethod · 0.95

Tested by

no test coverage detected