Skip to content

Commit f0a6180

Browse files
committed
Add oggerStore.ThumbnailOptions
1 parent 6929bb6 commit f0a6180

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Diff for: Sources/Pulse/LoggerStore/LoggerStore+Configuration.swift

+10
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ extension LoggerStore {
7474
/// If `true`, the images added to the store as saved as small thumbnails.
7575
public var isStoringOnlyImageThumbnails = true
7676

77+
/// Defines how to generate the thumbnails for the images from network responses.
78+
public var imageThumbnailOptions = ThumbnailOptions()
79+
7780
/// Limit the maximum response size stored by the logger. The default
7881
/// value is `8 MB`. The same limit applies to requests.
7982
public var responseBodySizeLimit: Int = 8 * 1048576
@@ -104,4 +107,11 @@ extension LoggerStore {
104107
self.sizeLimit = sizeLimit
105108
}
106109
}
110+
111+
/// The configuration options for storing thumbnails for network responses
112+
/// containing media.
113+
public struct ThumbnailOptions {
114+
public var maximumPixelSize: CGFloat = 512
115+
public var compressionQuality: CGFloat = 0.5
116+
}
107117
}

Diff for: Sources/Pulse/LoggerStore/LoggerStore.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -491,14 +491,15 @@ extension LoggerStore {
491491
}
492492

493493
private func preprocessData(_ data: Data, contentType: NetworkLogger.ContentType?) -> Data {
494-
guard data.count > 20_000 else { // 20 KB is ok
494+
guard data.count > 15_000 else { // 15 KB is ok
495495
return data
496496
}
497497
guard configuration.isStoringOnlyImageThumbnails && (contentType?.isImage ?? false) else {
498498
return data
499499
}
500-
guard let thumbnail = Graphics.makeThumbnail(from: data, targetSize: 512),
501-
let data = Graphics.encode(thumbnail, compressionQuality: 0.7) else {
500+
let options = configuration.imageThumbnailOptions
501+
guard let thumbnail = Graphics.makeThumbnail(from: data, targetSize: options.maximumPixelSize),
502+
let data = Graphics.encode(thumbnail, compressionQuality: options.compressionQuality) else {
502503
return data
503504
}
504505
return data

0 commit comments

Comments
 (0)