THE RETURN OF THE KING

This reverts commit c18d07538a.
This commit is contained in:
DrSmugleaf
2021-11-22 19:08:27 +01:00
parent 14e342663e
commit c3fe5909ad
65 changed files with 7021 additions and 236 deletions

View File

@@ -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")]