Data Format Update

This update set the groundwork for data storage in the database.

This update will also allow better support for any data format additions to be easily added.
This commit is contained in:
JacobTech 2023-05-13 00:27:13 -04:00
parent e739b5eb7a
commit 01e42af1f8
8 changed files with 57 additions and 3 deletions

View File

@ -7,9 +7,16 @@ public static class Channels
{ {
public static TableColumn<long> ID { get; } = new("id", true); public static TableColumn<long> ID { get; } = new("id", true);
public static TableColumn<ChannelType> Type { get; } = new("type"); public static TableColumn<ChannelType> Type { get; } = new("type");
public static TableColumn<DateTime> Epoch { get; } = new("epoch");
public static TableColumn<byte[]> Name { get; } = new("name"); public static TableColumn<byte[]> Name { get; } = new("name");
public static TableColumn<byte[]> Description { get; } = new("description"); public static TableColumn<byte[]> Description { get; } = new("description");
public static TableColumn<string> Key { get; } = new("key"); public static TableColumn<string> Key { get; } = new("key");
public static TableColumn<long[]> RoleOverides { get; } = new("role_overides"); public static TableColumn<long[]> RoleOverides { get; } = new("role_overides");
public static TableColumn<long[]> UserOverides { get; } = new("member_overides"); public static TableColumn<long[]> UserOverides { get; } = new("member_overides");
public static TableColumn<EncryptionType> TitleEncryptionType { get; } = new("title_encryption_type");
public static TableColumn<EncryptionType> DescriptionEncryptionType { get; } = new("description_encryption_type");
public static TableColumn<EncryptionType[]> AllowedEncryptionTypes { get; } = new("allowed_encryption_types");
public static TableColumn<EncoderType> TitleEncoderType { get; } = new("title_encoder_type");
public static TableColumn<EncoderType> DescriptionEncoderType { get; } = new("description_encoder_type");
public static TableColumn<EncoderType[]> AllowedEncoderTypes { get; } = new("allowed_encoder_types");
} }

View File

@ -1,3 +1,4 @@
using LuskiServer.Enums;
using ServerDatabase; using ServerDatabase;
namespace LuskiServer.Classes.TableDef; namespace LuskiServer.Classes.TableDef;
@ -9,4 +10,6 @@ public static class Files
public static TableColumn<byte[]> Name { get; } = new("name"); public static TableColumn<byte[]> Name { get; } = new("name");
public static TableColumn<byte[]> Hash { get; } = new("hash"); public static TableColumn<byte[]> Hash { get; } = new("hash");
public static TableColumn<byte[]> Data { get; } = new("data"); public static TableColumn<byte[]> Data { get; } = new("data");
public static TableColumn<EncryptionType> EncryptionType { get; } = new("encryption_type");
public static TableColumn<EncoderType> EncoderType { get; } = new("encoder_type");
} }

View File

@ -1,3 +1,4 @@
using LuskiServer.Enums;
using ServerDatabase; using ServerDatabase;
namespace LuskiServer.Classes.TableDef; namespace LuskiServer.Classes.TableDef;
@ -9,5 +10,7 @@ public static class Messages
public static TableColumn<long> AuthorID { get; } = new("author_id"); public static TableColumn<long> AuthorID { get; } = new("author_id");
public static TableColumn<long> TimeStamp { get; } = new("ts"); public static TableColumn<long> TimeStamp { get; } = new("ts");
public static TableColumn<byte[]> Context { get; } = new("context"); public static TableColumn<byte[]> Context { get; } = new("context");
public static TableColumn<EncryptionType> EncryptionType { get; } = new("encryption_type");
public static TableColumn<EncoderType> EncoderType { get; } = new("encoder_type");
public static TableColumn<long[]> Files { get; } = new("files"); public static TableColumn<long[]> Files { get; } = new("files");
} }

View File

@ -2,5 +2,5 @@ namespace LuskiServer.Enums;
public enum ChannelType : short public enum ChannelType : short
{ {
Default = 0
} }

View File

@ -0,0 +1,12 @@
namespace LuskiServer.Enums;
public enum EncoderType : short
{
UTF8 = 0,
UTF16 = 1,
UTF32 = 2,
ASCII = 3,
Latin1 = 4,
Unicode = 5,
BigEndianUnicode = 6
}

View File

@ -0,0 +1,8 @@
namespace LuskiServer.Enums;
public enum EncryptionType : short
{
None = 0,
RSA = 1,
AES = 2,
}

View File

@ -21,7 +21,7 @@
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="7.0.0" /> <PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.3" /> <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.3" />
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" /> <PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
<PackageReference Include="ServerDatabase" Version="2.5.1" /> <PackageReference Include="ServerDatabase" Version="2.5.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" /> <PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
</ItemGroup> </ItemGroup>

View File

@ -1,4 +1,5 @@
using System.Reflection; using System.Reflection;
using System.Text;
using Asp.Versioning.ApiExplorer; using Asp.Versioning.ApiExplorer;
using LuskiServer; using LuskiServer;
using LuskiServer.Classes; using LuskiServer.Classes;
@ -95,10 +96,30 @@ if (!Tables.Categories.TryRead(Categories.ID, out _, Categories.ID.CreateParamet
"The default category for the server. Everybody will see this category."), "The default category for the server. Everybody will see this category."),
Categories.RoleOverides.CreateParameter(new long[1] { 0 }) Categories.RoleOverides.CreateParameter(new long[1] { 0 })
); );
Tables.Channels.Insert(
Channels.ID.CreateParameter(0),
Channels.Type.CreateParameter(ChannelType.Default),
Channels.Description.CreateParameter(Encoding.UTF8.GetBytes("Default chat for you to use in your new server")),
Channels.Name.CreateParameter(Encoding.UTF8.GetBytes("Default Channel")),
Channels.Key.CreateParameter(Luski.Encryption.Keys.PublicKey),
Channels.RoleOverides.CreateParameter(Array.Empty<long>()),
Channels.UserOverides.CreateParameter(Array.Empty<long>()),
Channels.Epoch.CreateParameter(DateTime.UtcNow),
Channels.TitleEncryptionType.CreateParameter(EncryptionType.None),
Channels.DescriptionEncryptionType.CreateParameter(EncryptionType.None),
Channels.AllowedEncryptionTypes.CreateParameter(new [] { EncryptionType.RSA, EncryptionType.AES }),
Channels.TitleEncoderType.CreateParameter(EncoderType.UTF8),
Channels.DescriptionEncoderType.CreateParameter(EncoderType.UTF8),
Channels.AllowedEncoderTypes.CreateParameter(new []
{
EncoderType.UTF8, EncoderType.UTF16,
EncoderType.UTF32, EncoderType.ASCII,
EncoderType.Latin1, EncoderType.Unicode,
EncoderType.BigEndianUnicode
}));
} }
var builder = WebApplication.CreateBuilder( args ); var builder = WebApplication.CreateBuilder( args );
// Add services to the container. // Add services to the container.