Skip to content

Commit

Permalink
isImageAsset extended support for input source formats
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrch committed Nov 22, 2024
1 parent 9b6c9b3 commit eef2005
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public static ContentItemSimplifiedModel SampleArticleSubPageContentItemSimplifi
["EventText"] = "en-US Event sample 2024 (reusable)",
["EventDate"] = new DateTime(2024,1,1,0,0,0,0, DateTimeKind.Utc),
["EventRecurrentYearly"] = true,
["EventTeaser"] = new AssetDataSource
["EventTeaser"] = new AssetDataSource
{
ContentItemGuid = SampleEvent2024ContentItemGuid,
Identifier = new Guid("2A645BAB-F2DC-4B94-A226-FD680B9DF901"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,21 +460,21 @@ private static IEnumerable<FormFieldInfo> UnpackReusableFieldSchemas(IEnumerable

private static bool IsImageAsset(object? value)
{
if (value is JsonElement { ValueKind: JsonValueKind.Object } element && element.GetProperty(AssetSource.DISCRIMINATOR_PROPERTY).GetString() is { })
switch (value)
{
var assetSource = element.Deserialize<AssetSource>();
if (assetSource is not null)
case AssetSource assetSource:
{
return ImageHelper.IsImage(assetSource.InferExtension());
}
else
case JsonElement { ValueKind: JsonValueKind.Object } jsonElement when jsonElement.GetProperty(AssetSource.DISCRIMINATOR_PROPERTY).GetString() is { }:
{
throw new InvalidOperationException($"JSON object with property {AssetSource.DISCRIMINATOR_PROPERTY} cannot be deserialized");
var asset = jsonElement.Deserialize<AssetSource>() ?? throw new InvalidOperationException($"JSON object with property {AssetSource.DISCRIMINATOR_PROPERTY} cannot be deserialized");
return ImageHelper.IsImage(asset.InferExtension());
}
default:
{
return false;
}
}
else
{
return false;
}
}
}

0 comments on commit eef2005

Please sign in to comment.