summary refs log tree commit diff
path: root/extra/admin-api/Spacebar.Cdn/Mimes.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-03-11 00:58:13 +0100
committerRory& <root@rory.gay>2026-03-11 00:58:13 +0100
commitb40b5234f4cb3681bd9531d76c38111057f71733 (patch)
treeae238a01834f25871631b84d19141019c56c8f1b /extra/admin-api/Spacebar.Cdn/Mimes.cs
parentfix: fall back to undefined in message create (diff)
downloadserver-ts-github/dev/emma/gateway-batch-presence-lookup.tar.xz
Diffstat (limited to 'extra/admin-api/Spacebar.Cdn/Mimes.cs')
-rw-r--r--extra/admin-api/Spacebar.Cdn/Mimes.cs15
1 files changed, 15 insertions, 0 deletions
diff --git a/extra/admin-api/Spacebar.Cdn/Mimes.cs b/extra/admin-api/Spacebar.Cdn/Mimes.cs

index 508e9a3b..5a281432 100644 --- a/extra/admin-api/Spacebar.Cdn/Mimes.cs +++ b/extra/admin-api/Spacebar.Cdn/Mimes.cs
@@ -1,3 +1,4 @@ +using System.ComponentModel; using ImageMagick; namespace Spacebar.AdminApi.TestClient.Services; @@ -8,6 +9,20 @@ public static class Mimes { return mime; } + public static MagickFormat GetFormatForExtension(string extension) { + extension = extension.ToLower(); + // ban some values... + if (extension == "screenshot") throw new AccessViolationException("Disallowed extension: " + extension); + + var matchingFormat = Enum.GetNames(typeof(MagickFormat)).FirstOrDefault(f => f.ToLower() == extension); + if (string.IsNullOrWhiteSpace(matchingFormat)) throw new InvalidEnumArgumentException("Unknown format: " + extension); + if (Enum.TryParse(matchingFormat, out MagickFormat fmt)) { + return fmt; + } + + throw new InvalidEnumArgumentException("Unknown format: " + extension); + } + public static string GetMime(MagickFormat fmt) => fmt switch { MagickFormat.Png => "image/png", MagickFormat.Jpeg => "image/jpeg",