MCPcopy Create free account
hub / github.com/TruthHun/BookStack / DelByHtmlPics

Method DelByHtmlPics

models/store/oss.go:175–193  ·  view source on GitHub ↗

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

(htmlStr string)

Source from the content-addressed store, hash-verified

173
174//从HTML中提取图片文件,并删除
175func (o *Oss) DelByHtmlPics(htmlStr string) {
176 doc, err := goquery.NewDocumentFromReader(strings.NewReader(htmlStr))
177 if err != nil {
178 beego.Error(err.Error())
179 return
180 }
181 doc.Find("img").Each(func(i int, s *goquery.Selection) {
182 // For each item found, get the band and title
183 if src, exist := s.Attr("src"); exist {
184 //不存在http开头的图片链接,则更新为绝对链接
185 if !(strings.HasPrefix(src, "http://") || strings.HasPrefix(src, "https://")) {
186 o.DelFromOss(strings.TrimLeft(src, "./")) //删除
187 } else if strings.HasPrefix(src, o.Domain) {
188 o.DelFromOss(strings.TrimPrefix(src, o.Domain)) //删除
189 }
190 }
191 })
192 return
193}
194
195//根据oss文件夹
196func (o *Oss) DelOssFolder(folder string) (err error) {

Callers

nothing calls this directly

Calls 2

DelFromOssMethod · 0.95
FindMethod · 0.45

Tested by

no test coverage detected