-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!--- Provide a general summary of your changes in the Title above --> ## Description <!--- Describe your changes in detail --> ## Related Issue(s) - #329 ## Verification - [x] **Your** code builds clean without any errors or warnings - [x] Manual testing done (required) - [ ] Relevant automated test added (if you find this hard, leave it and we'll help out) ## Documentation - [ ] Documentation is updated (either in `docs`-directory, Altinnpedia or a separate linked PR in [altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if applicable) Co-authored-by: Knut Haug <knut.espen.haug@digdir.no>
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Net.Mime; | ||
using System.Reflection; | ||
|
||
namespace Digdir.Domain.Dialogporten.Domain; | ||
|
||
public static class MediaTypes | ||
{ | ||
// Custom MediaTypes for embedding content in frontend applications | ||
private static readonly string[] CustomDialogportenMediaTypes = | ||
[ | ||
"application/vnd.dialogporten.frontchannelembed+json;type=markdown" | ||
]; | ||
|
||
private static string[]? _validMediaTypes; | ||
|
||
public static bool IsValid(string mediaType) => GetValidMediaTypes().Contains(mediaType); | ||
|
||
private static string[] GetValidMediaTypes() | ||
{ | ||
if (_validMediaTypes != null) | ||
{ | ||
return _validMediaTypes; | ||
} | ||
|
||
var applicationMediaTypes = GetMediaTypes(typeof(MediaTypeNames.Application)); | ||
var imageMediaTypes = GetMediaTypes(typeof(MediaTypeNames.Image)); | ||
var textMediaTypes = GetMediaTypes(typeof(MediaTypeNames.Text)); | ||
|
||
_validMediaTypes = applicationMediaTypes | ||
.Concat(imageMediaTypes) | ||
.Concat(textMediaTypes) | ||
.Concat(CustomDialogportenMediaTypes) | ||
.ToArray(); | ||
|
||
return _validMediaTypes; | ||
} | ||
|
||
private static IEnumerable<string> GetMediaTypes(Type mediaTypeClass) | ||
{ | ||
return mediaTypeClass | ||
.GetFields(BindingFlags.Public | BindingFlags.Static) | ||
.Where(field => field.FieldType == typeof(string)) | ||
.Select(field => (string)field.GetValue(null)!); | ||
} | ||
} |