mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-15 10:30:37 +09:00
Allow arbitrary issue attachments
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
517fe5093e
commit
e9c8bd4805
5 changed files with 242 additions and 13 deletions
|
|
@ -1,10 +1,10 @@
|
|||
/**
|
||||
* Shared attachment content-type configuration.
|
||||
*
|
||||
* By default only image types are allowed. Set the
|
||||
* By default a curated set of image/document/text types are allowed. Set the
|
||||
* `PAPERCLIP_ALLOWED_ATTACHMENT_TYPES` environment variable to a
|
||||
* comma-separated list of MIME types or wildcard patterns to expand the
|
||||
* allowed set.
|
||||
* allowed set for routes that use this allowlist.
|
||||
*
|
||||
* Examples:
|
||||
* PAPERCLIP_ALLOWED_ATTACHMENT_TYPES=image/*,application/pdf
|
||||
|
|
@ -29,6 +29,17 @@ export const DEFAULT_ALLOWED_TYPES: readonly string[] = [
|
|||
"text/html",
|
||||
];
|
||||
|
||||
export const DEFAULT_ATTACHMENT_CONTENT_TYPE = "application/octet-stream";
|
||||
export const SVG_CONTENT_TYPE = "image/svg+xml";
|
||||
export const INLINE_ATTACHMENT_TYPES: readonly string[] = [
|
||||
"image/*",
|
||||
"application/pdf",
|
||||
"text/plain",
|
||||
"text/markdown",
|
||||
"application/json",
|
||||
"text/csv",
|
||||
];
|
||||
|
||||
/**
|
||||
* Parse a comma-separated list of MIME type patterns into a normalised array.
|
||||
* Returns the default image-only list when the input is empty or undefined.
|
||||
|
|
@ -59,6 +70,15 @@ export function matchesContentType(contentType: string, allowedPatterns: string[
|
|||
});
|
||||
}
|
||||
|
||||
export function normalizeContentType(contentType: string | null | undefined): string {
|
||||
const normalized = (contentType ?? "").trim().toLowerCase();
|
||||
return normalized || DEFAULT_ATTACHMENT_CONTENT_TYPE;
|
||||
}
|
||||
|
||||
export function isInlineAttachmentContentType(contentType: string): boolean {
|
||||
return matchesContentType(contentType, [...INLINE_ATTACHMENT_TYPES]);
|
||||
}
|
||||
|
||||
// ---------- Module-level singletons read once at startup ----------
|
||||
|
||||
const allowedPatterns: string[] = parseAllowedTypes(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue