[backend/core] Add Guid.ToStringLower() extension method

This commit is contained in:
Laura Hausmann 2024-04-25 18:26:42 +02:00
parent 1f3f7ad64d
commit 363b0c930c
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
5 changed files with 18 additions and 8 deletions

View file

@ -0,0 +1,6 @@
namespace Iceshrimp.Backend.Core.Extensions;
public static class GuidExtensions
{
public static string ToStringLower(this Guid guid) => guid.ToString().ToLowerInvariant();
}

View file

@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using Iceshrimp.Backend.Core.Configuration;
using Iceshrimp.Backend.Core.Database.Tables;
using Iceshrimp.Backend.Core.Extensions;
using Iceshrimp.Backend.Core.Federation.ActivityStreams.Types;
using Iceshrimp.Backend.Core.Middleware;
using Microsoft.Extensions.Options;
@ -14,7 +15,7 @@ public class ActivityRenderer(
)
{
private string GenerateActivityId() =>
$"https://{config.Value.WebDomain}/activities/ephemeral/{Guid.NewGuid().ToString().ToLowerInvariant()}";
$"https://{config.Value.WebDomain}/activities/ephemeral/{Guid.NewGuid().ToStringLower()}";
public static ASCreate RenderCreate(ASNote obj, ASObject actor) => new()
{

View file

@ -1,4 +1,5 @@
using Iceshrimp.Backend.Core.Database.Tables;
using Iceshrimp.Backend.Core.Extensions;
using Iceshrimp.Backend.Core.Federation.ActivityStreams;
using Iceshrimp.Backend.Core.Federation.ActivityStreams.Types;
using Iceshrimp.Backend.Core.Middleware;
@ -19,7 +20,7 @@ public class InboxQueue() : PostgresJobQueue<InboxJobData>("inbox", InboxQueuePr
)
{
var logger = scope.GetRequiredService<ILogger<InboxQueue>>();
logger.LogDebug("Processing inbox job {id}", job.Id.ToString().ToLowerInvariant());
logger.LogDebug("Processing inbox job {id}", job.Id.ToStringLower());
var expanded = LdHelpers.Expand(JToken.Parse(jobData.Body)) ?? throw new Exception("Failed to expand ASObject");
var obj = ASObject.Deserialize(expanded) ?? throw new Exception("Failed to deserialize ASObject");
if (obj is not ASActivity activity)

View file

@ -3,6 +3,7 @@ using Blurhash.ImageSharp;
using Iceshrimp.Backend.Core.Configuration;
using Iceshrimp.Backend.Core.Database;
using Iceshrimp.Backend.Core.Database.Tables;
using Iceshrimp.Backend.Core.Extensions;
using Iceshrimp.Backend.Core.Federation.Cryptography;
using Iceshrimp.Backend.Core.Helpers;
using Iceshrimp.Backend.Core.Middleware;
@ -318,14 +319,14 @@ public class DriveService(
private static string GenerateFilenameKeepingExtension(string filename)
{
var guid = Guid.NewGuid().ToString().ToLowerInvariant();
var guid = Guid.NewGuid().ToStringLower();
var ext = Path.GetExtension(filename);
return guid + ext;
}
private static string GenerateWebpFilename(string prefix = "")
{
var guid = Guid.NewGuid().ToString().ToLowerInvariant();
var guid = Guid.NewGuid().ToStringLower();
return $"{prefix}{guid}.webp";
}
@ -340,7 +341,7 @@ public class DriveService(
public class DriveFileCreationRequest
{
public string? Comment;
public required string Filename = Guid.NewGuid().ToString().ToLowerInvariant();
public required string Filename = Guid.NewGuid().ToStringLower();
public required bool IsSensitive;
public required string MimeType;
public Dictionary<string, string>? RequestHeaders;

View file

@ -436,12 +436,13 @@ public class PostgresJobQueue<T>(
var queueName = data is BackgroundTaskJobData ? name + $" ({data.GetType().Name})" : name;
if (e is GracefulException { Details: not null } ce)
{
logger.LogError("Failed to process job in {queue} queue: {error} - {details}",
queueName, ce.Message, ce.Details);
logger.LogError("Failed to process job {id} in {queue} queue: {error} - {details}",
queueName, job.Id.ToStringLower(), ce.Message, ce.Details);
}
else
{
logger.LogError(e, "Failed to process job in {queue} queue:", queueName);
logger.LogError(e, "Failed to process job {id} in {queue} queue:", job.Id.ToStringLower(),
queueName);
}
}