Skip to content

Commit

Permalink
recover thumb if download faild
Browse files Browse the repository at this point in the history
  • Loading branch information
Monirzadeh committed Aug 5, 2023
1 parent 91937b3 commit c12e3f2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/core/processing.go
Expand Up @@ -72,7 +72,7 @@ func ProcessBookmark(req ProcessRequest) (book model.Bookmark, isFatalErr bool,

nurl, err := url.Parse(book.URL)
if err != nil {
return book, true, fmt.Errorf("Failed to parse url: %v", err)
return book, true, fmt.Errorf("failed to parse url: %v", err)
}

article, err := readability.FromReader(readabilityInput, nurl)
Expand Down Expand Up @@ -117,13 +117,17 @@ func ProcessBookmark(req ProcessRequest) (book model.Bookmark, isFatalErr bool,
// Save article image to local disk
strID := strconv.Itoa(book.ID)
imgPath := fp.Join(req.DataDir, "thumb", strID)
tmpImgPath := fp.Join(req.DataDir, "tmp/thumb", strID)

for _, imageURL := range imageURLs {
err = downloadBookImage(imageURL, imgPath)
err = downloadBookImage(imageURL, tmpImgPath)
if err == nil {
book.ImageURL = path.Join("/", "bookmark", strID, "thumb")
os.Remove(tmpImgPath)
break
}
os.Remove(imgPath)
os.Rename(tmpImgPath, imgPath)
}

// If needed, create ebook as well
Expand Down

0 comments on commit c12e3f2

Please sign in to comment.