Skip to content

Commit

Permalink
Add oggerStore.ThumbnailOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Sep 7, 2024
1 parent 6929bb6 commit 91ec07a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions Sources/Pulse/LoggerStore/LoggerStore+Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = 512
public var compressionQuality = 0.5
}
}
6 changes: 3 additions & 3 deletions Sources/Pulse/LoggerStore/LoggerStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -491,14 +491,14 @@ 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 {
guard let thumbnail = Graphics.makeThumbnail(from: data, targetSize: imageThumbnailOptions.maximumPixelSize),
let data = Graphics.encode(thumbnail, compressionQuality: imageThumbnailOptions.compressionQuality) else {
return data
}
return data
Expand Down

0 comments on commit 91ec07a

Please sign in to comment.