From 77ec2354e8f46d5ef149d1dcaf25f51c04149137 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 5 Sep 2023 13:09:04 -0600 Subject: [PATCH] Fix Content-Disposition handling --- api/_routers/98-use-rcontext.go | 2 +- util/mime.go | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/api/_routers/98-use-rcontext.go b/api/_routers/98-use-rcontext.go index bd6bf03b..18c678c1 100644 --- a/api/_routers/98-use-rcontext.go +++ b/api/_routers/98-use-rcontext.go @@ -112,7 +112,7 @@ beforeParseDownload: if contentType == "" { disposition = "attachment" } else { - if util.HasAnyPrefix(contentType, []string{"image/", "audio/", "video/", "text/plain"}) { + if util.CanInline(contentType) { disposition = "inline" } else { disposition = "attachment" diff --git a/util/mime.go b/util/mime.go index 58876549..8d34d03f 100644 --- a/util/mime.go +++ b/util/mime.go @@ -16,3 +16,39 @@ func ExtensionForContentType(ct string) string { } return ".bin" } + +func CanInline(ct string) bool { + ct = FixContentType(ct) + return ArrayContains(InlineContentTypes, ct) +} + +var InlineContentTypes = []string{ + // Types are inherited from https://github.com/matrix-org/synapse/pull/15988 + + "text/css", + "text/plain", + "text/csv", + "application/json", + "application/ld+json", + "image/jpeg", + "image/gif", + "image/png", + "image/apng", + "image/webp", + "image/avif", + "video/mp4", + "video/webm", + "video/ogg", + "video/quicktime", + "audio/mp4", + "audio/webm", + "audio/aac", + "audio/mpeg", + "audio/ogg", + "audio/wave", + "audio/wav", + "audio/x-wav", + "audio/x-pn-wav", + "audio/flac", + "audio/x-flac", +}