From f0a6180212733e26eee4b0e7448a21c09aadde78 Mon Sep 17 00:00:00 2001 From: kean Date: Sat, 7 Sep 2024 13:50:56 -0400 Subject: [PATCH] Add oggerStore.ThumbnailOptions --- .../Pulse/LoggerStore/LoggerStore+Configuration.swift | 10 ++++++++++ Sources/Pulse/LoggerStore/LoggerStore.swift | 7 ++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Sources/Pulse/LoggerStore/LoggerStore+Configuration.swift b/Sources/Pulse/LoggerStore/LoggerStore+Configuration.swift index 180e40bd8..704ca6f55 100644 --- a/Sources/Pulse/LoggerStore/LoggerStore+Configuration.swift +++ b/Sources/Pulse/LoggerStore/LoggerStore+Configuration.swift @@ -74,6 +74,9 @@ extension LoggerStore { /// If `true`, the images added to the store as saved as small thumbnails. public var isStoringOnlyImageThumbnails = true + /// Defines how to generate the thumbnails for the images from network responses. + public var imageThumbnailOptions = ThumbnailOptions() + /// Limit the maximum response size stored by the logger. The default /// value is `8 MB`. The same limit applies to requests. public var responseBodySizeLimit: Int = 8 * 1048576 @@ -104,4 +107,11 @@ extension LoggerStore { self.sizeLimit = sizeLimit } } + + /// The configuration options for storing thumbnails for network responses + /// containing media. + public struct ThumbnailOptions { + public var maximumPixelSize: CGFloat = 512 + public var compressionQuality: CGFloat = 0.5 + } } diff --git a/Sources/Pulse/LoggerStore/LoggerStore.swift b/Sources/Pulse/LoggerStore/LoggerStore.swift index 5de439762..76ba4a23f 100644 --- a/Sources/Pulse/LoggerStore/LoggerStore.swift +++ b/Sources/Pulse/LoggerStore/LoggerStore.swift @@ -491,14 +491,15 @@ extension LoggerStore { } private func preprocessData(_ data: Data, contentType: NetworkLogger.ContentType?) -> Data { - guard data.count > 20_000 else { // 20 KB is ok + guard data.count > 15_000 else { // 15 KB is ok return data } guard configuration.isStoringOnlyImageThumbnails && (contentType?.isImage ?? false) else { return data } - guard let thumbnail = Graphics.makeThumbnail(from: data, targetSize: 512), - let data = Graphics.encode(thumbnail, compressionQuality: 0.7) else { + let options = configuration.imageThumbnailOptions + guard let thumbnail = Graphics.makeThumbnail(from: data, targetSize: options.maximumPixelSize), + let data = Graphics.encode(thumbnail, compressionQuality: options.compressionQuality) else { return data } return data