adds iconImageUrl to article utils

This commit is contained in:
Stuart Breckenridge 2020-12-24 07:31:44 +08:00
parent 3254d57189
commit fe194ec2e5
No known key found for this signature in database
GPG Key ID: 1F11FD62007DC331
2 changed files with 18 additions and 11 deletions

View File

@ -103,6 +103,22 @@ extension Article {
return FaviconGenerator.favicon(webFeed)
}
func iconImageUrl(webFeed: WebFeed) -> URL? {
if let image = iconImage() {
let fm = FileManager.default
var path = fm.urls(for: .cachesDirectory, in: .userDomainMask)[0]
#if os(macOS)
path.appendPathComponent(webFeed.webFeedID + "_smallIcon.tiff")
#else
path.appendPathComponent(webFeed.webFeedID + "_smallIcon.png")
#endif
fm.createFile(atPath: path.path, contents: image.image.dataRepresentation()!, attributes: nil)
return path
} else {
return nil
}
}
func byline() -> String {
guard let authors = authors ?? webFeed?.authors, !authors.isEmpty else {
return ""

View File

@ -73,17 +73,8 @@ private extension UserNotificationManager {
/// - Returns: A `UNNotifcationAttachment` if an icon is available. Otherwise nil.
/// - Warning: In certain scenarios, this will return the `faviconTemplateImage`.
func thumbnailAttachment(for article: Article, webFeed: WebFeed) -> UNNotificationAttachment? {
if let image = article.iconImage() {
let fm = FileManager.default
var path = fm.urls(for: .cachesDirectory, in: .userDomainMask)[0]
#if os(macOS)
path.appendPathComponent(webFeed.webFeedID + "_smallIcon.tiff")
#else
path.appendPathComponent(webFeed.webFeedID + "_smallIcon.png")
#endif
fm.createFile(atPath: path.path, contents: image.image.dataRepresentation()!, attributes: nil)
let thumbnail = try? UNNotificationAttachment(identifier: webFeed.webFeedID, url: path, options: nil)
if let imageURL = article.iconImageUrl(webFeed: webFeed) {
let thumbnail = try? UNNotificationAttachment(identifier: webFeed.webFeedID, url: imageURL, options: nil)
return thumbnail
}
return nil