Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b7rnC7jppGGdHGESvy
31 lines
1.3 KiB
Java
31 lines
1.3 KiB
Java
package com.ankurm.imagegen;
|
|
|
|
import java.util.Set;
|
|
|
|
/**
|
|
* Every limit in one place so a test (and a reader) can see them.
|
|
*
|
|
* @param maxBytes largest image we will accept, decoded
|
|
* @param maxPixels largest width x height we will accept, read from the header before decoding
|
|
* @param maxPromptChars longest prompt we will send
|
|
* @param allowedTypes sniffed MIME types we will store
|
|
* @param fetchHosts hosts a provider-returned URL may point at (exact match, https only unless allowInsecure)
|
|
* @param allowInsecure allow http:// fetches; only for tests against a local server
|
|
*/
|
|
public record ImagePolicy(long maxBytes, long maxPixels, int maxPromptChars, Set<String> allowedTypes,
|
|
Set<String> fetchHosts, boolean allowInsecure) {
|
|
|
|
public static ImagePolicy defaults() {
|
|
return new ImagePolicy(8L * 1024 * 1024, 16_000_000L, 4000,
|
|
Set.of("image/png", "image/jpeg", "image/webp"), Set.of(), false);
|
|
}
|
|
|
|
public ImagePolicy withMaxBytes(long v) {
|
|
return new ImagePolicy(v, maxPixels, maxPromptChars, allowedTypes, fetchHosts, allowInsecure);
|
|
}
|
|
|
|
public ImagePolicy withFetch(Set<String> hosts, boolean insecure) {
|
|
return new ImagePolicy(maxBytes, maxPixels, maxPromptChars, allowedTypes, hosts, insecure);
|
|
}
|
|
}
|