[backend/core] Add Guid.ToStringLower() extension method
This commit is contained in:
parent
1f3f7ad64d
commit
363b0c930c
5 changed files with 18 additions and 8 deletions
6
Iceshrimp.Backend/Core/Extensions/GuidExtensions.cs
Normal file
6
Iceshrimp.Backend/Core/Extensions/GuidExtensions.cs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
namespace Iceshrimp.Backend.Core.Extensions;
|
||||||
|
|
||||||
|
public static class GuidExtensions
|
||||||
|
{
|
||||||
|
public static string ToStringLower(this Guid guid) => guid.ToString().ToLowerInvariant();
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Iceshrimp.Backend.Core.Configuration;
|
using Iceshrimp.Backend.Core.Configuration;
|
||||||
using Iceshrimp.Backend.Core.Database.Tables;
|
using Iceshrimp.Backend.Core.Database.Tables;
|
||||||
|
using Iceshrimp.Backend.Core.Extensions;
|
||||||
using Iceshrimp.Backend.Core.Federation.ActivityStreams.Types;
|
using Iceshrimp.Backend.Core.Federation.ActivityStreams.Types;
|
||||||
using Iceshrimp.Backend.Core.Middleware;
|
using Iceshrimp.Backend.Core.Middleware;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
@ -14,7 +15,7 @@ public class ActivityRenderer(
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
private string GenerateActivityId() =>
|
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()
|
public static ASCreate RenderCreate(ASNote obj, ASObject actor) => new()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using Iceshrimp.Backend.Core.Database.Tables;
|
using Iceshrimp.Backend.Core.Database.Tables;
|
||||||
|
using Iceshrimp.Backend.Core.Extensions;
|
||||||
using Iceshrimp.Backend.Core.Federation.ActivityStreams;
|
using Iceshrimp.Backend.Core.Federation.ActivityStreams;
|
||||||
using Iceshrimp.Backend.Core.Federation.ActivityStreams.Types;
|
using Iceshrimp.Backend.Core.Federation.ActivityStreams.Types;
|
||||||
using Iceshrimp.Backend.Core.Middleware;
|
using Iceshrimp.Backend.Core.Middleware;
|
||||||
|
@ -19,7 +20,7 @@ public class InboxQueue() : PostgresJobQueue<InboxJobData>("inbox", InboxQueuePr
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
var logger = scope.GetRequiredService<ILogger<InboxQueue>>();
|
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 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");
|
var obj = ASObject.Deserialize(expanded) ?? throw new Exception("Failed to deserialize ASObject");
|
||||||
if (obj is not ASActivity activity)
|
if (obj is not ASActivity activity)
|
||||||
|
|
|
@ -3,6 +3,7 @@ using Blurhash.ImageSharp;
|
||||||
using Iceshrimp.Backend.Core.Configuration;
|
using Iceshrimp.Backend.Core.Configuration;
|
||||||
using Iceshrimp.Backend.Core.Database;
|
using Iceshrimp.Backend.Core.Database;
|
||||||
using Iceshrimp.Backend.Core.Database.Tables;
|
using Iceshrimp.Backend.Core.Database.Tables;
|
||||||
|
using Iceshrimp.Backend.Core.Extensions;
|
||||||
using Iceshrimp.Backend.Core.Federation.Cryptography;
|
using Iceshrimp.Backend.Core.Federation.Cryptography;
|
||||||
using Iceshrimp.Backend.Core.Helpers;
|
using Iceshrimp.Backend.Core.Helpers;
|
||||||
using Iceshrimp.Backend.Core.Middleware;
|
using Iceshrimp.Backend.Core.Middleware;
|
||||||
|
@ -318,14 +319,14 @@ public class DriveService(
|
||||||
|
|
||||||
private static string GenerateFilenameKeepingExtension(string filename)
|
private static string GenerateFilenameKeepingExtension(string filename)
|
||||||
{
|
{
|
||||||
var guid = Guid.NewGuid().ToString().ToLowerInvariant();
|
var guid = Guid.NewGuid().ToStringLower();
|
||||||
var ext = Path.GetExtension(filename);
|
var ext = Path.GetExtension(filename);
|
||||||
return guid + ext;
|
return guid + ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GenerateWebpFilename(string prefix = "")
|
private static string GenerateWebpFilename(string prefix = "")
|
||||||
{
|
{
|
||||||
var guid = Guid.NewGuid().ToString().ToLowerInvariant();
|
var guid = Guid.NewGuid().ToStringLower();
|
||||||
return $"{prefix}{guid}.webp";
|
return $"{prefix}{guid}.webp";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,7 +341,7 @@ public class DriveService(
|
||||||
public class DriveFileCreationRequest
|
public class DriveFileCreationRequest
|
||||||
{
|
{
|
||||||
public string? Comment;
|
public string? Comment;
|
||||||
public required string Filename = Guid.NewGuid().ToString().ToLowerInvariant();
|
public required string Filename = Guid.NewGuid().ToStringLower();
|
||||||
public required bool IsSensitive;
|
public required bool IsSensitive;
|
||||||
public required string MimeType;
|
public required string MimeType;
|
||||||
public Dictionary<string, string>? RequestHeaders;
|
public Dictionary<string, string>? RequestHeaders;
|
||||||
|
|
|
@ -436,12 +436,13 @@ public class PostgresJobQueue<T>(
|
||||||
var queueName = data is BackgroundTaskJobData ? name + $" ({data.GetType().Name})" : name;
|
var queueName = data is BackgroundTaskJobData ? name + $" ({data.GetType().Name})" : name;
|
||||||
if (e is GracefulException { Details: not null } ce)
|
if (e is GracefulException { Details: not null } ce)
|
||||||
{
|
{
|
||||||
logger.LogError("Failed to process job in {queue} queue: {error} - {details}",
|
logger.LogError("Failed to process job {id} in {queue} queue: {error} - {details}",
|
||||||
queueName, ce.Message, ce.Details);
|
queueName, job.Id.ToStringLower(), ce.Message, ce.Details);
|
||||||
}
|
}
|
||||||
else
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue