|
|
|
@ -27,27 +27,33 @@ public sealed class EventFluidExtensions : IFluidExtension |
|
|
|
{ |
|
|
|
options.Filters.AddFilter("contentUrl", ContentUrl); |
|
|
|
options.Filters.AddFilter("assetContentUrl", AssetContentUrl); |
|
|
|
options.Filters.AddFilter("assetContentAppUrl", AssetContentAppUrl); |
|
|
|
options.Filters.AddFilter("assetContentAppUrl", AssetContentUrl); |
|
|
|
options.Filters.AddFilter("assetContentSlugUrl", AssetContentSlugUrl); |
|
|
|
} |
|
|
|
|
|
|
|
private ValueTask<FluidValue> ContentUrl(FluidValue input, FilterArguments arguments, TemplateContext context) |
|
|
|
{ |
|
|
|
FluidValue TryResolveId(TemplateContext context, DomainId id) |
|
|
|
{ |
|
|
|
if (context.GetValue("event")?.ToObjectValue() is EnrichedContentEvent contentEvent) |
|
|
|
{ |
|
|
|
var url = urlGenerator.ContentUI(contentEvent.AppId, contentEvent.SchemaId, id); |
|
|
|
|
|
|
|
return new StringValue(url); |
|
|
|
} |
|
|
|
|
|
|
|
return NilValue.Empty; |
|
|
|
} |
|
|
|
|
|
|
|
var value = input.ToObjectValue(); |
|
|
|
|
|
|
|
switch (value) |
|
|
|
{ |
|
|
|
case DomainId id: |
|
|
|
{ |
|
|
|
if (context.GetValue("event")?.ToObjectValue() is EnrichedContentEvent contentEvent) |
|
|
|
{ |
|
|
|
var result = urlGenerator.ContentUI(contentEvent.AppId, contentEvent.SchemaId, id); |
|
|
|
|
|
|
|
return new StringValue(result); |
|
|
|
} |
|
|
|
return TryResolveId(context, id); |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
case string id: |
|
|
|
return TryResolveId(context, DomainId.Create(id)); |
|
|
|
|
|
|
|
case EnrichedContentEvent contentEvent: |
|
|
|
{ |
|
|
|
@ -62,50 +68,27 @@ public sealed class EventFluidExtensions : IFluidExtension |
|
|
|
|
|
|
|
private ValueTask<FluidValue> AssetContentUrl(FluidValue input, FilterArguments arguments, TemplateContext context) |
|
|
|
{ |
|
|
|
var value = input.ToObjectValue(); |
|
|
|
|
|
|
|
switch (value) |
|
|
|
FluidValue TryResolveId(TemplateContext context, string id) |
|
|
|
{ |
|
|
|
case DomainId id: |
|
|
|
{ |
|
|
|
if (context.GetValue("event")?.ToObjectValue() is EnrichedAssetEvent assetEvent) |
|
|
|
{ |
|
|
|
var result = urlGenerator.AssetContent(assetEvent.AppId, id.ToString()); |
|
|
|
if (context.GetValue("event")?.ToObjectValue() is EnrichedEvent enrichedEvent) |
|
|
|
{ |
|
|
|
var result = urlGenerator.AssetContent(enrichedEvent.AppId, id); |
|
|
|
|
|
|
|
return new StringValue(result); |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
case EnrichedAssetEvent assetEvent: |
|
|
|
{ |
|
|
|
var result = urlGenerator.AssetContent(assetEvent.AppId, assetEvent.Id.ToString()); |
|
|
|
return new StringValue(result); |
|
|
|
} |
|
|
|
|
|
|
|
return new StringValue(result); |
|
|
|
} |
|
|
|
return NilValue.Empty; |
|
|
|
} |
|
|
|
|
|
|
|
return NilValue.Empty; |
|
|
|
} |
|
|
|
|
|
|
|
private ValueTask<FluidValue> AssetContentAppUrl(FluidValue input, FilterArguments arguments, TemplateContext context) |
|
|
|
{ |
|
|
|
var value = input.ToObjectValue(); |
|
|
|
|
|
|
|
switch (value) |
|
|
|
{ |
|
|
|
case DomainId id: |
|
|
|
{ |
|
|
|
if (context.GetValue("event")?.ToObjectValue() is EnrichedAssetEvent assetEvent) |
|
|
|
{ |
|
|
|
var result = urlGenerator.AssetContent(assetEvent.AppId, id.ToString()); |
|
|
|
return TryResolveId(context, id.ToString()); |
|
|
|
|
|
|
|
return new StringValue(result); |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
case string id: |
|
|
|
return TryResolveId(context, id); |
|
|
|
|
|
|
|
case EnrichedAssetEvent assetEvent: |
|
|
|
{ |
|
|
|
@ -120,21 +103,24 @@ public sealed class EventFluidExtensions : IFluidExtension |
|
|
|
|
|
|
|
private ValueTask<FluidValue> AssetContentSlugUrl(FluidValue input, FilterArguments arguments, TemplateContext context) |
|
|
|
{ |
|
|
|
FluidValue TryResolveSlug(TemplateContext context, string slug) |
|
|
|
{ |
|
|
|
if (context.GetValue("event")?.ToObjectValue() is EnrichedEvent enrichedEvent) |
|
|
|
{ |
|
|
|
var result = urlGenerator.AssetContent(enrichedEvent.AppId, slug.Slugify()); |
|
|
|
|
|
|
|
return new StringValue(result); |
|
|
|
} |
|
|
|
|
|
|
|
return NilValue.Empty; |
|
|
|
} |
|
|
|
|
|
|
|
var value = input.ToObjectValue(); |
|
|
|
|
|
|
|
switch (value) |
|
|
|
{ |
|
|
|
case string s: |
|
|
|
{ |
|
|
|
if (context.GetValue("event")?.ToObjectValue() is EnrichedAssetEvent assetEvent) |
|
|
|
{ |
|
|
|
var result = urlGenerator.AssetContent(assetEvent.AppId, s.Slugify()); |
|
|
|
|
|
|
|
return new StringValue(result); |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
return TryResolveSlug(context, s); |
|
|
|
|
|
|
|
case EnrichedAssetEvent assetEvent: |
|
|
|
{ |
|
|
|
|