从HTML中提取图片文件,并删除
(htmlStr string)
| 173 | |
| 174 | //从HTML中提取图片文件,并删除 |
| 175 | func (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文件夹 |
| 196 | func (o *Oss) DelOssFolder(folder string) (err error) { |
nothing calls this directly
no test coverage detected