@@ -1,7 +1,10 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
@@ -57,6 +60,14 @@ namespace Content.Server.Database
|
||||
.Property(e => e.Address)
|
||||
.HasColumnType("TEXT")
|
||||
.HasConversion(ipMaskConverter);
|
||||
|
||||
var jsonConverter = new ValueConverter<JsonDocument, string>(
|
||||
v => JsonDocumentToString(v),
|
||||
v => StringToJsonDocument(v));
|
||||
|
||||
modelBuilder.Entity<AdminLog>()
|
||||
.Property(log => log.Json)
|
||||
.HasConversion(jsonConverter);
|
||||
}
|
||||
|
||||
public SqliteServerDbContext(DbContextOptions<ServerDbContext> options) : base(options)
|
||||
@@ -81,6 +92,22 @@ namespace Content.Server.Database
|
||||
int.Parse(inet.AsSpan(idx + 1), provider: CultureInfo.InvariantCulture)
|
||||
);
|
||||
}
|
||||
|
||||
private static string JsonDocumentToString(JsonDocument document)
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
using var writer = new Utf8JsonWriter(stream, new JsonWriterOptions {Indented = false});
|
||||
|
||||
document.WriteTo(writer);
|
||||
writer.Flush();
|
||||
|
||||
return Encoding.UTF8.GetString(stream.ToArray());
|
||||
}
|
||||
|
||||
private static JsonDocument StringToJsonDocument(string str)
|
||||
{
|
||||
return JsonDocument.Parse(str);
|
||||
}
|
||||
}
|
||||
|
||||
[Table("ban")]
|
||||
|
||||
Reference in New Issue
Block a user