[backend/drive] Add option to reject images that exceed the maximum media processing resolution
This commit is contained in:
parent
f903a1d8a4
commit
1d31553199
3 changed files with 19 additions and 6 deletions
|
@ -206,6 +206,7 @@ public sealed class Config
|
|||
public Enums.ImageProcessor ImageProcessor { get; init; } = Enums.ImageProcessor.ImageSharp;
|
||||
public int MaxResolutionMpx { get; init; } = 30;
|
||||
public bool LocalOnly { get; init; } = false;
|
||||
public bool FailIfImageExceedsMaxRes { get; init; } = false;
|
||||
|
||||
[Range(0, 128)] public int ImageProcessorConcurrency { get; init; } = 8;
|
||||
|
||||
|
|
|
@ -263,9 +263,16 @@ public class DriveService(
|
|||
}
|
||||
else if (ident.Width * ident.Height > storageConfig.Value.MediaProcessing.MaxResolutionPx)
|
||||
{
|
||||
var config = storageConfig.Value.MediaProcessing;
|
||||
if (config.FailIfImageExceedsMaxRes)
|
||||
{
|
||||
// @formatter:off
|
||||
throw GracefulException.UnprocessableEntity($"Image is larger than {config.MaxResolutionMpx}mpx. Please resize your image to fit within the allowed dimensions.");
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
logger.LogDebug("Image is larger than {mpx}mpx ({width}x{height}), bypassing image processing...",
|
||||
storageConfig.Value.MediaProcessing.MaxResolutionMpx, ident.Width,
|
||||
ident.Height);
|
||||
config.MaxResolutionMpx, ident.Width, ident.Height);
|
||||
skipImageProcessing = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -158,9 +158,14 @@ MaxFileSize = 10M
|
|||
|
||||
;; Maximum resolution for files to be considered for image processing, in megapixels
|
||||
;; Note that processing an image requires up to 4MB of system memory per megapixel, in some edge case scenarios.
|
||||
;; Caution: metadata (e.g. location data) for locally originating images will *not* be stripped for files larger than this
|
||||
;; Caution: metadata (e.g. location data) for locally originating images will *not* be stripped for files larger than this.
|
||||
;; If this is unwanted behavior, enable FailIfImageExceedsMaxRes.
|
||||
MaxResolutionMpx = 30
|
||||
|
||||
;; Should you prefer to reject locally originating images that exceed MaxResolutionMpx, set this option to true.
|
||||
;; Note that this does not apply to remote images, or to local images in a format not supported by the configured image processor.
|
||||
FailIfImageExceedsMaxRes = false
|
||||
|
||||
;; Maxmimum concurrent image encode tasks to run. (0 = no limit)
|
||||
ImageProcessorConcurrency = 8
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue