Compare commits

...

2 Commits

Author SHA1 Message Date
ed796e6d7f defer release resouce 2024-03-18 14:58:11 +08:00
389bbad65f 完善 2023-07-11 14:59:39 +08:00
2 changed files with 11 additions and 8 deletions

View File

@ -65,6 +65,7 @@ func fetch(u string) (r rss2.Item) {
return
}
dom, err := goquery.NewDocumentFromReader(res.Body)
defer res.Body.Close()
if err != nil {
return
}
@ -104,6 +105,7 @@ func downAndSendMail(doc *goquery.Document, title string) {
if err != nil {
return
}
var fn []func()
for _, ss := range []string{".bbcle-download-extension-pdf", ".bbcle-download-extension-mp3"} {
uu, ok := doc.Find(ss).Attr("href")
if ok {
@ -116,6 +118,10 @@ func downAndSendMail(doc *goquery.Document, title string) {
if err != nil {
continue
}
fn = append(fn, func() {
response.Body.Close()
file.Close()
})
_, err = io.Copy(file, response.Body)
if err != nil {
continue
@ -123,6 +129,11 @@ func downAndSendMail(doc *goquery.Document, title string) {
mm.f = append(mm.f, name)
}
}
defer func() {
for _, f := range fn {
f()
}
}()
if len(mm.f) < 1 {
return
}

View File

@ -38,14 +38,6 @@ func SendMail(subject string, content string, files ...string) error {
}
cmd := exec.Command(cm, v...)
file, err := os.OpenFile("run.sh", os.O_CREATE|os.O_APPEND, 0755)
if err != nil {
return err
}
_, err = file.WriteString(cmd.String())
if err != nil {
return err
}
output, err := cmd.CombinedOutput()
log.Println(string(output))
return err