Skip to content

Commit df69999

Browse files
committed
chore: code review
1 parent 09ebca5 commit df69999

7 files changed

Lines changed: 316 additions & 279 deletions

File tree

deploy/Terraform/container-app.tf

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ resource "azurerm_container_app" "app" {
8282
server = azurerm_container_registry.acr.login_server
8383
identity = azurerm_user_assigned_identity.uami.id
8484
}
85-
85+
8686
depends_on = [azurerm_role_assignment.acr_pull, azurerm_mssql_database.db]
8787

8888
# needed for container app to access other Microsoft Entra protected resources
@@ -179,6 +179,16 @@ resource "azurerm_container_app" "app" {
179179
name = "ASPNETCORE_ENVIRONMENT"
180180
value = "Production"
181181
}
182+
183+
env {
184+
name = "AzureAIFoundry__ContentSafetyKey"
185+
secret_name = "content-safety-key"
186+
}
187+
188+
env {
189+
name = "AzureAIFoundry__ContentSafetyEndpoint"
190+
value = var.content_safety_api
191+
}
182192
}
183193
}
184194

@@ -216,4 +226,9 @@ resource "azurerm_container_app" "app" {
216226
value = var.smtp_password
217227
}
218228

229+
secret {
230+
name = "content-safety-key"
231+
value = var.content_safety_key
232+
}
233+
219234
}

deploy/Terraform/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,14 @@ variable "smtp_password" {
3535
type = string
3636
sensitive = true
3737
}
38+
39+
variable "content_safety_key" {
40+
description = "Azure AI foundry content safety key"
41+
type = string
42+
sensitive = true
43+
}
44+
45+
variable "content_safety_api" {
46+
description = "Azure AI foundry content safety api endpoint"
47+
type = string
48+
}

src/Evently.Server/Common/Extensions/LoggerExtension.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ public static partial void LogSuccessEmail(
2828
Message = "Error occurred at {context}: {errorMsg}")]
2929
public static partial void LogErrorContext(
3030
this ILogger logger, string context, string errorMsg);
31+
32+
[LoggerMessage(
33+
EventId = 5,
34+
Level = LogLevel.Error,
35+
Message = "Analyze image failed. Status code: {statusCode}, Error code: {errorCode}, Error message: {errMsg}")]
36+
public static partial void LogContentModerationError(
37+
this ILogger logger, string statusCode, string errorCode, string errMsg);
38+
//
3139
}

src/Evently.Server/Features/Files/Services/ObjectStorageService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Azure.Storage.Blobs.Models;
55
using Evently.Server.Common.Domains.Interfaces;
66
using Evently.Server.Common.Domains.Models;
7+
using Evently.Server.Common.Extensions;
78
using Microsoft.Extensions.Options;
89

910
namespace Evently.Server.Features.Files.Services;
@@ -77,7 +78,7 @@ public async Task<bool> PassesContentModeration(BinaryData binaryData) {
7778
try {
7879
response = await _contentSafetyClient.AnalyzeImageAsync(request);
7980
} catch (RequestFailedException ex) {
80-
Console.WriteLine("Analyze image failed.\nStatus code: {0}, Error code: {1}, Error message: {2}", ex.Status, ex.ErrorCode, ex.Message);
81+
logger.LogContentModerationError(ex.Status.ToString(), ex.ErrorCode ?? "", ex.Message);
8182
throw;
8283
}
8384

@@ -86,6 +87,6 @@ public async Task<bool> PassesContentModeration(BinaryData binaryData) {
8687
.Select(v => v.Severity)
8788
.Aggregate((a, b) => a + b)
8889
?? 0;
89-
return result.CategoriesAnalysis.Count != 0 && score == 0;
90+
return score == 0;
9091
}
9192
}

src/Evently.Server/Features/Gatherings/Controllers/GatheringsController.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public async Task<ActionResult<Gathering>> CreateGathering([FromForm] GatheringR
6868
}
6969

7070
if (coverImg != null) {
71-
Uri uri = await UploadCoverImage(gatheringReqDto.GatheringId, coverImg: coverImg ?? throw new ArgumentNullException(nameof(coverImg)));
72-
gatheringReqDto = gatheringReqDto with { CoverSrc = uri.AbsoluteUri };
71+
string uri = await UploadCoverImage(gatheringReqDto.GatheringId, coverImg);
72+
gatheringReqDto = gatheringReqDto with { CoverSrc = uri };
7373
}
7474

7575
Gathering gathering = await gatheringService.CreateGathering(gatheringReqDto);
@@ -88,9 +88,8 @@ public async Task<ActionResult> UpdateGathering(long gatheringId, [FromForm] Gat
8888
}
8989

9090
if (coverImg != null) {
91-
Uri uri = await UploadCoverImage(gatheringReqDto.GatheringId, coverImg);
92-
gathering.CoverSrc = uri.AbsoluteUri;
93-
gatheringReqDto = gatheringReqDto with { CoverSrc = uri.AbsoluteUri };
91+
string uri = await UploadCoverImage(gatheringReqDto.GatheringId, coverImg);
92+
gatheringReqDto = gatheringReqDto with { CoverSrc = uri };
9493
}
9594

9695
gathering = await gatheringService.UpdateGathering(gatheringId, gatheringReqDto);
@@ -112,16 +111,17 @@ public async Task<ActionResult<Gathering>> DeleteGathering(long gatheringId) {
112111
return NoContent();
113112
}
114113

115-
private async Task<Uri> UploadCoverImage(long gatheringId, IFormFile coverImg) {
114+
private async Task<string> UploadCoverImage(long gatheringId, IFormFile coverImg) {
116115
string fileName = $"gatherings/{gatheringId}/cover-image{Path.GetExtension(coverImg.FileName)}";
117116
BinaryData binaryData = await coverImg.ToBinaryData();
118117
bool isContentSafe = await objectStorageService.PassesContentModeration(binaryData);
119118
if (!isContentSafe) {
120-
return new Uri(string.Empty, UriKind.RelativeOrAbsolute);
119+
return string.Empty;
121120
}
122-
return await objectStorageService.UploadFile(_containerName,
121+
Uri uri = await objectStorageService.UploadFile(_containerName,
123122
fileName,
124123
binaryData,
125124
mimeType: MimeTypes.GetMimeType(coverImg.FileName));
125+
return uri.AbsoluteUri;
126126
}
127127
}

src/evently.client/src/lib/components/card.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export function Card({ gathering, accountId }: CardProps): JSX.Element {
1818
(detail) => detail.category
1919
);
2020

21-
// ignore img-src for now
2221
if (imgSrc == null || imgSrc.length === 0) {
2322
const hash: number = hashString(gathering.name);
2423
imgSrc = hash % 2 === 0 ? Placeholder1 : Placeholder2;

0 commit comments

Comments
 (0)