diff --git a/Modules/Account/Sources/Account/LocalAccount/LocalAccountRefresher.swift b/Modules/Account/Sources/Account/LocalAccount/LocalAccountRefresher.swift index e61285dd5..87cd39223 100644 --- a/Modules/Account/Sources/Account/LocalAccount/LocalAccountRefresher.swift +++ b/Modules/Account/Sources/Account/LocalAccount/LocalAccountRefresher.swift @@ -285,7 +285,7 @@ import os } let dataHash = data.md5String - let dataSizeMessage = Int64(data.count).formatted(.byteCount(style: .memory)) + let dataSizeMessage = ActivityLog.dataSizeMessage(data) if dataHash == feed.contentHash { if let activityOwner { ActivityLog.shared.didComplete(activityOwner, kind: activityKind, message: "\(dataSizeMessage), content unchanged") diff --git a/Modules/ActivityLog/Sources/ActivityLog/ActivityLogDataSize.swift b/Modules/ActivityLog/Sources/ActivityLog/ActivityLogDataSize.swift new file mode 100644 index 000000000..4087f3062 --- /dev/null +++ b/Modules/ActivityLog/Sources/ActivityLog/ActivityLogDataSize.swift @@ -0,0 +1,16 @@ +// +// ActivityLogDataSize.swift +// ActivityLog +// +// Created by Brent Simmons on 6/18/26. +// + +import Foundation + +public extension ActivityLog { + + /// Formats a download size for an activity message — for example "39 kB". + nonisolated static func dataSizeMessage(_ data: Data) -> String { + Int64(data.count).formatted(.byteCount(style: .file)) + } +} diff --git a/Modules/FeedFinder/Sources/FeedFinder/FeedFinder.swift b/Modules/FeedFinder/Sources/FeedFinder/FeedFinder.swift index 8afeff4c1..fb06d5146 100644 --- a/Modules/FeedFinder/Sources/FeedFinder/FeedFinder.swift +++ b/Modules/FeedFinder/Sources/FeedFinder/FeedFinder.swift @@ -282,8 +282,7 @@ private extension FeedFinder { } let statusPart = formattedStatus(response.forcedStatusCode) if response.statusIsOK, let data, !data.isEmpty { - let sizeText = Int64(data.count).formatted(.byteCount(style: .file)) - return "\(statusPart) · \(sizeText)" + return "\(statusPart) · \(ActivityLog.dataSizeMessage(data))" } return statusPart } diff --git a/Modules/HTMLMetadata/Sources/HTMLMetadata/HTMLMetadataDownloader.swift b/Modules/HTMLMetadata/Sources/HTMLMetadata/HTMLMetadataDownloader.swift index 78fa12057..6fe321e00 100644 --- a/Modules/HTMLMetadata/Sources/HTMLMetadata/HTMLMetadataDownloader.swift +++ b/Modules/HTMLMetadata/Sources/HTMLMetadata/HTMLMetadataDownloader.swift @@ -130,7 +130,7 @@ nonisolated private extension HTMLMetadataDownloader { cacheRecord(record) postNotification(record) - activityLog.didComplete(.htmlMetadataDownloader, kind: kind, returnedFromCache: downloadResponse.returnedFromCache) + activityLog.didComplete(.htmlMetadataDownloader, kind: kind, message: ActivityLog.dataSizeMessage(data), returnedFromCache: downloadResponse.returnedFromCache) return } diff --git a/Modules/Images/Sources/Images/ImageDownloader.swift b/Modules/Images/Sources/Images/ImageDownloader.swift index 8b826ffae..2b6e0d4b8 100644 --- a/Modules/Images/Sources/Images/ImageDownloader.swift +++ b/Modules/Images/Sources/Images/ImageDownloader.swift @@ -116,9 +116,10 @@ private extension ImageDownloader { } do { - let (image, fromCache) = try await downloadImage(url) + let (image, downloadResponse) = try await downloadImage(url) if let activityOwner, let activityKind { - activityLog.didComplete(activityOwner, kind: activityKind, returnedFromCache: fromCache) + let message = downloadResponse.data.map(ActivityLog.dataSizeMessage) + activityLog.didComplete(activityOwner, kind: activityKind, message: message, returnedFromCache: downloadResponse.returnedFromCache) } cacheImage(url, image) ImageMetadataDatabase.shared.clearFailure(url: url) @@ -156,7 +157,7 @@ private extension ImageDownloader { } } - func downloadImage(_ url: String) async throws(ImageDownloadError) -> (Data, Bool) { + func downloadImage(_ url: String) async throws(ImageDownloadError) -> (Data, DownloadResponse) { guard let imageURL = URL(string: url) else { throw ImageDownloadError(statusCode: nil, decodingFailed: false, isTransient: false) } @@ -172,7 +173,7 @@ private extension ImageDownloader { if let data = downloadResponse.data, !data.isEmpty, let response = downloadResponse.response, response.statusIsOK { let scaledData = RSImage.scaledImageData(data, maxPixelSize: RSImage.maxIconPixelSize) ?? data saveToDisk(url, scaledData) - return (scaledData, downloadResponse.returnedFromCache) + return (scaledData, downloadResponse) } let statusCode = (downloadResponse.response as? HTTPURLResponse)?.statusCode diff --git a/Modules/Images/Sources/Images/SingleFaviconDownloader.swift b/Modules/Images/Sources/Images/SingleFaviconDownloader.swift index 37cd8a7b1..643315b33 100644 --- a/Modules/Images/Sources/Images/SingleFaviconDownloader.swift +++ b/Modules/Images/Sources/Images/SingleFaviconDownloader.swift @@ -164,7 +164,7 @@ private extension SingleFaviconDownloader { throw error } saveToDisk(scaledData) - activityLog.didComplete(.faviconDownloader, kind: kind, returnedFromCache: downloadResponse.returnedFromCache) + activityLog.didComplete(.faviconDownloader, kind: kind, message: ActivityLog.dataSizeMessage(data), returnedFromCache: downloadResponse.returnedFromCache) return image }