♻️ Move the keys store out of the publisher meta
This commit is contained in:
@@ -32,6 +32,9 @@ public class SnPublisher : ModelBase, IIdentifiedResource
|
||||
[Column(TypeName = "jsonb")] public SnVerificationMark? Verification { get; set; }
|
||||
[Column(TypeName = "jsonb")] public Dictionary<string, object>? Meta { get; set; }
|
||||
|
||||
[MaxLength(8192)] [JsonIgnore] public string? PrivateKeyPem { get; set; }
|
||||
[MaxLength(8192)] public string? PublicKeyPem { get; set; }
|
||||
|
||||
[IgnoreMember] [JsonIgnore] public ICollection<SnPost> Posts { get; set; } = [];
|
||||
[IgnoreMember] [JsonIgnore] public ICollection<SnPoll> Polls { get; set; } = [];
|
||||
[IgnoreMember] [JsonIgnore] public ICollection<SnPostCollection> Collections { get; set; } = [];
|
||||
|
||||
@@ -327,14 +327,25 @@ public class ActivityPubController(
|
||||
|
||||
private static string? GetPublisherKey(SnPublisher publisher, string keyName)
|
||||
{
|
||||
var metadata = publisher.Meta;
|
||||
return metadata?.GetValueOrDefault(keyName)?.ToString();
|
||||
return keyName switch
|
||||
{
|
||||
"private_key" => publisher.PrivateKeyPem,
|
||||
"public_key" => publisher.PublicKeyPem,
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
private static void SavePublisherKey(SnPublisher publisher, string keyName, string keyValue)
|
||||
{
|
||||
publisher.Meta ??= new Dictionary<string, object>();
|
||||
publisher.Meta[keyName] = keyValue;
|
||||
switch (keyName)
|
||||
{
|
||||
case "private_key":
|
||||
publisher.PrivateKeyPem = keyValue;
|
||||
break;
|
||||
case "public_key":
|
||||
publisher.PublicKeyPem = keyValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -161,20 +161,24 @@ public class ActivityPubSignatureService(
|
||||
|
||||
private string? GetPublisherKey(SnPublisher publisher, string keyName)
|
||||
{
|
||||
if (publisher.Meta == null)
|
||||
return null;
|
||||
|
||||
var metadata = publisher.Meta as Dictionary<string, object>;
|
||||
return metadata?.GetValueOrDefault(keyName)?.ToString();
|
||||
return keyName switch
|
||||
{
|
||||
"private_key" => publisher.PrivateKeyPem,
|
||||
"public_key" => publisher.PublicKeyPem,
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
private void SavePublisherKey(SnPublisher publisher, string keyName, string keyValue)
|
||||
{
|
||||
publisher.Meta ??= new Dictionary<string, object>();
|
||||
var metadata = publisher.Meta as Dictionary<string, object>;
|
||||
if (metadata != null)
|
||||
switch (keyName)
|
||||
{
|
||||
metadata[keyName] = keyValue;
|
||||
case "private_key":
|
||||
publisher.PrivateKeyPem = keyValue;
|
||||
break;
|
||||
case "public_key":
|
||||
publisher.PublicKeyPem = keyValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2693
DysonNetwork.Sphere/Migrations/20251229174336_AddPublisherKeys.Designer.cs
generated
Normal file
2693
DysonNetwork.Sphere/Migrations/20251229174336_AddPublisherKeys.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,40 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DysonNetwork.Sphere.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddPublisherKeys : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "private_key_pem",
|
||||
table: "publishers",
|
||||
type: "character varying(8192)",
|
||||
maxLength: 8192,
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "public_key_pem",
|
||||
table: "publishers",
|
||||
type: "character varying(8192)",
|
||||
maxLength: 8192,
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "private_key_pem",
|
||||
table: "publishers");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "public_key_pem",
|
||||
table: "publishers");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1544,6 +1544,16 @@ namespace DysonNetwork.Sphere.Migrations
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("picture");
|
||||
|
||||
b.Property<string>("PrivateKeyPem")
|
||||
.HasMaxLength(8192)
|
||||
.HasColumnType("character varying(8192)")
|
||||
.HasColumnName("private_key_pem");
|
||||
|
||||
b.Property<string>("PublicKeyPem")
|
||||
.HasMaxLength(8192)
|
||||
.HasColumnType("character varying(8192)")
|
||||
.HasColumnName("public_key_pem");
|
||||
|
||||
b.Property<Guid?>("RealmId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("realm_id");
|
||||
|
||||
Reference in New Issue
Block a user