Skip to content

Commit e84b89c

Browse files
committed
Merge branch 'dev'
2 parents 736b139 + 2753ecb commit e84b89c

File tree

16 files changed

+8062
-106
lines changed

16 files changed

+8062
-106
lines changed

api/net/Areas/Services/Controllers/SourceController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
using Microsoft.Extensions.Options;
66
using Swashbuckle.AspNetCore.Annotations;
77
using TNO.API.Areas.Services.Models.Ingest;
8+
using TNO.API.Filters;
89
using TNO.API.Models;
910
using TNO.DAL.Services;
1011
using TNO.Keycloak;
11-
using TNO.API.Filters;
1212

1313
namespace TNO.API.Areas.Services.Controllers;
1414

@@ -67,9 +67,10 @@ public IActionResult FindByCode(string code)
6767
/// Get an array of sources.
6868
/// </summary>
6969
/// <returns></returns>
70-
[HttpGet]
70+
[HttpGet, HttpHead]
7171
[Produces(MediaTypeNames.Application.Json)]
7272
[ProducesResponseType(typeof(IEnumerable<SourceModel>), (int)HttpStatusCode.OK)]
73+
[ProducesResponseType((int)HttpStatusCode.NotModified)]
7374
[SwaggerOperation(Tags = new[] { "Source" })]
7475
[ETagCacheTableFilter("sources")]
7576
public IActionResult GetSources()

libs/net/core/Http/HttpRequestClient.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public void Dispose()
6969

7070
/// <summary>
7171
/// Deserialize the specified 'response' into the specified type of 'TModel'.
72+
/// Returns null if no content is returned and the status code is successful.
7273
/// </summary>
7374
/// <typeparam name="TModel"></typeparam>
7475
/// <param name="response"></param>
@@ -78,20 +79,29 @@ public void Dispose()
7879
var responseStream = await response.Content.ReadAsStreamAsync();
7980
// var data = await response.Content.ReadAsByteArrayAsync();
8081
var contentType = response.Content.Headers.ContentType;
82+
var body = "";
8183
try
8284
{
83-
if (contentType?.MediaType?.Contains("json", StringComparison.InvariantCultureIgnoreCase) == true)
85+
if (contentType?.MediaType?.Contains("json", StringComparison.InvariantCultureIgnoreCase) == true && response.IsSuccessStatusCode)
8486
return JsonSerializer.Deserialize<TModel>(responseStream, _serializeOptions);
87+
else if (response.IsSuccessStatusCode)
88+
return default;
89+
else if (response.StatusCode == HttpStatusCode.NotModified)
90+
return default;
8591
}
8692
catch (Exception ex)
8793
{
94+
// Catch deserialization errors and log the response data.
8895
var data = responseStream.ReadAllBytes();
89-
var body = Encoding.Default.GetString(data);
96+
body = Encoding.Default.GetString(data);
9097
_logger.LogError(ex, "Failed to deserialize response: {body}", body);
9198
throw;
9299
}
93100

94-
throw new HttpClientRequestException(response, $"Response must contain JSON but was '{contentType?.MediaType}'.");
101+
// Throw exception because the response failed and cannot be deserialized.
102+
var errorEx = new HttpClientRequestException($"Response must contain JSON but was '{contentType?.MediaType}'.", response.StatusCode);
103+
errorEx.Data["body"] = body;
104+
throw errorEx;
95105
}
96106

97107
#region HttpResponseMessage Methods
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
DO $$
2+
BEGIN
3+
4+
-- Update the basic alert template.
5+
UPDATE public."notification_template" SET
6+
"subject" = '@inherits RazorEngineCore.RazorEngineTemplateBase<TNO.TemplateEngine.Models.Notifications.NotificationEngineContentModel>
7+
@using System.Linq
8+
@{
9+
var isAV = @Content.ContentType == TNO.Entities.ContentType.AudioVideo;
10+
var useSummary = @Content.ContentType == TNO.Entities.ContentType.Image || isAV;
11+
var isTranscriptAvailable = isAV && !string.IsNullOrWhiteSpace(@Content.Body) && @Content.IsApproved;
12+
var sourceCode = !string.IsNullOrEmpty(@Content.Source?.Code) ? @Content.Source.Code : @Content.OtherSource;
13+
var body = isTranscriptAvailable ? @Content.Body : (useSummary ? @Content.Summary : @Content.Body);
14+
var transcriptIcon = isTranscriptAvailable ? "▶️📄" : (isAV ? "▶️" : "");
15+
var toneIcon = "";
16+
if (@EnableReportSentiment)
17+
{
18+
switch (@Content.TonePools.FirstOrDefault()?.Value)
19+
{
20+
case 0:
21+
toneIcon = "😐 ";
22+
break;
23+
case -3:
24+
case -4:
25+
case -5:
26+
toneIcon = "☹️ ";
27+
break;
28+
case 3:
29+
case 4:
30+
case 5:
31+
toneIcon = "🙂 ";
32+
break;
33+
}
34+
}
35+
}@toneIcon@sourceCode: @Content.Headline @transcriptIcon'
36+
, "body" = '@inherits RazorEngineCore.RazorEngineTemplateBase<TNO.TemplateEngine.Models.Notifications.NotificationEngineContentModel>
37+
@using System
38+
@using System.Web
39+
@using System.Linq
40+
@{
41+
var subscriberAppUrl = @SubscriberAppUrl?.ToString();
42+
var viewContentUrl = @ViewContentUrl?.ToString();
43+
var requestTranscriptUrl = @RequestTranscriptUrl?.ToString();
44+
var addToReportUrl = @AddToReportUrl?.ToString();
45+
var isAV = @Content.ContentType == TNO.Entities.ContentType.AudioVideo;
46+
var useSummary = @Content.ContentType == TNO.Entities.ContentType.Image || isAV;
47+
var isTranscriptAvailable = isAV && !string.IsNullOrWhiteSpace(@Content.Body) && @Content.IsApproved;
48+
var sourceCode = !string.IsNullOrEmpty(@Content.Source?.Code) ? @Content.Source.Code : @Content.OtherSource;
49+
var body = isTranscriptAvailable ? @Content.Body : (useSummary ? @Content.Summary : @Content.Body);
50+
var replaceWith = "<br/>";
51+
body = body.Replace("\r\n", replaceWith).Replace("\n", replaceWith).Replace("\r", replaceWith);
52+
var filePath = @Content.FileReferences.FirstOrDefault()?.Path;
53+
54+
var tz = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
55+
var utcOffset = tz.GetUtcOffset(System.DateTime.Now).Hours;
56+
}
57+
@if (!string.IsNullOrWhiteSpace(@Content.Source?.Name))
58+
{
59+
<div>@Content.Source.Name</div>
60+
}
61+
@if (!string.IsNullOrEmpty(@Content.Series?.Name))
62+
{
63+
<div>@Content.Series.Name</div>
64+
}
65+
<div>@Content.PublishedOn?.AddHours(@utcOffset).ToString("dd-MMM-yyyy HH:mm")</div>
66+
@if (!string.IsNullOrEmpty(@Content.Byline))
67+
{
68+
<div>@Content.Byline</div>
69+
}
70+
@if (!string.IsNullOrEmpty(@Content.Page))
71+
{
72+
<div>Page #@Content.Page</div>
73+
}
74+
@if (@Content.ContentType == TNO.Entities.ContentType.Image && !string.IsNullOrEmpty(filePath))
75+
{
76+
var apiFileUrl = subscriberAppUrl + "api/subscriber/contents/download?path=" + filePath;
77+
<div><img src="@apiFileUrl" alt="@Content.FileReferences.FirstOrDefault()?.FileName" /></div>
78+
}
79+
<br/>
80+
<p>
81+
<hr></hr>
82+
<div>@body</div>
83+
<br />
84+
@if (!string.IsNullOrEmpty(subscriberAppUrl))
85+
{
86+
<div><a href="@subscriberAppUrl" target="">MMI</a> : <a href="@viewContentUrl@Content.Id" target="_blank">View article on MMI website</a></div>
87+
<br />
88+
}
89+
@if (isAV && !isTranscriptAvailable && !string.IsNullOrEmpty(requestTranscriptUrl) && Content.Source?.DisableTranscribe == false)
90+
{
91+
<div><a href="@($"{requestTranscriptUrl}{Content.Id}")?uid=@(Content.OwnerId)&headline=@(HttpUtility.UrlEncode(Content.Headline))&source=@(HttpUtility.UrlEncode(Content.OtherSource))" target="_blank"
92+
style="margin-left:auto; padding:0.5em; color:#123456; background-color:#fff7e1; border:2px solid #dcc797; height:2em; border-radius:0.85em; text-decoration:none; display:inline-flex; align-items:center; gap:0.5em;"
93+
onmouseover="this.style.backgroundColor=''#ffebb3'';"
94+
onmouseout="this.style.backgroundColor=''#fff7e1'';">
95+
<i class="fa fa-feather" style="color:#cccccc;"></i> Request Transcript</a>
96+
</div>
97+
<br />
98+
}
99+
<br /><hr></hr>
100+
<div style="font-size: 14px;">
101+
<b>This e-mail is a service provided by Government Communications and Public Engagement and is only intended
102+
for the original addressee. All content is the copyrighted property of a third party creator of the material. Copying, re-transmitting, redistributing, selling, licensing, or e-mailing the material to any third party or any employee of the Province who is not authorized to access the material is prohibited. </b>
103+
</div>'
104+
WHERE "id" = cast((SELECT value FROM setting
105+
WHERE name = 'BasicAlertTemplateId') as integer);
106+
107+
END $$;

0 commit comments

Comments
 (0)