JJ Colocate
This commit is contained in:
@@ -1,75 +1,75 @@
|
||||
using MongoDB.Bson.IO;
|
||||
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace AobaServer.Models;
|
||||
|
||||
public class AuthInfo
|
||||
{
|
||||
public required string Issuer { get; set; }
|
||||
public required string Audience { get; set; }
|
||||
public required byte[] SecureKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Save this auth into in a json format to the sepcified file
|
||||
/// </summary>
|
||||
/// <param name="path">File path</param>
|
||||
/// <returns></returns>
|
||||
public AuthInfo Save(string path)
|
||||
{
|
||||
File.WriteAllText(path, JsonSerializer.Serialize(this));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a new Auth Info with newly generated keys
|
||||
/// </summary>
|
||||
/// <param name="issuer"></param>
|
||||
/// <param name="audience"></param>
|
||||
/// <returns></returns>
|
||||
public static AuthInfo Create(string issuer, string audience)
|
||||
{
|
||||
var auth = new AuthInfo
|
||||
{
|
||||
Issuer = issuer,
|
||||
Audience = audience,
|
||||
SecureKey = GenetateJWTKey()
|
||||
};
|
||||
return auth;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load auth info from a json file
|
||||
/// </summary>
|
||||
/// <param name="path">File path</param>
|
||||
/// <returns></returns>
|
||||
internal static AuthInfo? Load(string path)
|
||||
{
|
||||
return JsonSerializer.Deserialize<AuthInfo>(File.ReadAllText(path));
|
||||
}
|
||||
|
||||
internal static AuthInfo LoadOrCreate(string path, string issuer, string audience)
|
||||
{
|
||||
if (File.Exists(path))
|
||||
{
|
||||
var loaded = Load(path);
|
||||
if (loaded != null)
|
||||
return loaded;
|
||||
}
|
||||
var info = Create(issuer, audience);
|
||||
info.Save(path);
|
||||
return info;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a new key for use by JWT
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static byte[] GenetateJWTKey(int size = 64)
|
||||
{
|
||||
var key = new byte[size];
|
||||
RandomNumberGenerator.Fill(key);
|
||||
return key;
|
||||
}
|
||||
using MongoDB.Bson.IO;
|
||||
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace AobaServer.Models;
|
||||
|
||||
public class AuthInfo
|
||||
{
|
||||
public required string Issuer { get; set; }
|
||||
public required string Audience { get; set; }
|
||||
public required byte[] SecureKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Save this auth into in a json format to the sepcified file
|
||||
/// </summary>
|
||||
/// <param name="path">File path</param>
|
||||
/// <returns></returns>
|
||||
public AuthInfo Save(string path)
|
||||
{
|
||||
File.WriteAllText(path, JsonSerializer.Serialize(this));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a new Auth Info with newly generated keys
|
||||
/// </summary>
|
||||
/// <param name="issuer"></param>
|
||||
/// <param name="audience"></param>
|
||||
/// <returns></returns>
|
||||
public static AuthInfo Create(string issuer, string audience)
|
||||
{
|
||||
var auth = new AuthInfo
|
||||
{
|
||||
Issuer = issuer,
|
||||
Audience = audience,
|
||||
SecureKey = GenetateJWTKey()
|
||||
};
|
||||
return auth;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load auth info from a json file
|
||||
/// </summary>
|
||||
/// <param name="path">File path</param>
|
||||
/// <returns></returns>
|
||||
internal static AuthInfo? Load(string path)
|
||||
{
|
||||
return JsonSerializer.Deserialize<AuthInfo>(File.ReadAllText(path));
|
||||
}
|
||||
|
||||
internal static AuthInfo LoadOrCreate(string path, string issuer, string audience)
|
||||
{
|
||||
if (File.Exists(path))
|
||||
{
|
||||
var loaded = Load(path);
|
||||
if (loaded != null)
|
||||
return loaded;
|
||||
}
|
||||
var info = Create(issuer, audience);
|
||||
info.Save(path);
|
||||
return info;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a new key for use by JWT
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static byte[] GenetateJWTKey(int size = 64)
|
||||
{
|
||||
var key = new byte[size];
|
||||
RandomNumberGenerator.Fill(key);
|
||||
return key;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,31 @@
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using MongoDB.Bson;
|
||||
|
||||
namespace AobaServer.Models;
|
||||
|
||||
public class BsonIdModelBinderProvider : IModelBinderProvider
|
||||
{
|
||||
public IModelBinder? GetBinder(ModelBinderProviderContext context)
|
||||
{
|
||||
if (context.Metadata.ModelType == typeof(ObjectId))
|
||||
return new BsonIdModelBinder();
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public class BsonIdModelBinder : IModelBinder
|
||||
{
|
||||
public Task BindModelAsync(ModelBindingContext bindingContext)
|
||||
{
|
||||
var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
|
||||
if (value == ValueProviderResult.None)
|
||||
return Task.CompletedTask;
|
||||
|
||||
if (ObjectId.TryParse(value.FirstValue, out var id))
|
||||
bindingContext.Result = ModelBindingResult.Success(id);
|
||||
else
|
||||
bindingContext.Result = ModelBindingResult.Failed();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using MongoDB.Bson;
|
||||
|
||||
namespace AobaServer.Models;
|
||||
|
||||
public class BsonIdModelBinderProvider : IModelBinderProvider
|
||||
{
|
||||
public IModelBinder? GetBinder(ModelBinderProviderContext context)
|
||||
{
|
||||
if (context.Metadata.ModelType == typeof(ObjectId))
|
||||
return new BsonIdModelBinder();
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public class BsonIdModelBinder : IModelBinder
|
||||
{
|
||||
public Task BindModelAsync(ModelBindingContext bindingContext)
|
||||
{
|
||||
var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
|
||||
if (value == ValueProviderResult.None)
|
||||
return Task.CompletedTask;
|
||||
|
||||
if (ObjectId.TryParse(value.FirstValue, out var id))
|
||||
bindingContext.Result = ModelBindingResult.Success(id);
|
||||
else
|
||||
bindingContext.Result = ModelBindingResult.Failed();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
namespace AobaServer.Models;
|
||||
|
||||
public class ShareXDestination
|
||||
{
|
||||
public string Version { get; set; } = "14.0.1";
|
||||
public string Name { get; set; } = "Aoba";
|
||||
public string DestinationType { get; set; } = "ImageUploader, TextUploader, FileUploader";
|
||||
public string RequestMethod { get; set; } = "POST";
|
||||
public string RequestURL { get; set; } = "https://aoba.app/api/media/upload";
|
||||
public Dictionary<string, string> Headers { get; set; } = [];
|
||||
public string Body { get; set; } = "MultipartFormData";
|
||||
public Dictionary<string, string> Arguments { get; set; } = new() { { "name", "$filename$" } };
|
||||
public string FileFormName { get; set; } = "file";
|
||||
public string[] RegexList { get; set; } = ["([^/]+)/?$"];
|
||||
public string URL { get; set; } = "https://aoba.app{json:url}";
|
||||
public string? ThumbnailURL { get; set; }
|
||||
public string? DeletionURL { get; set; }
|
||||
namespace AobaServer.Models;
|
||||
|
||||
public class ShareXDestination
|
||||
{
|
||||
public string Version { get; set; } = "14.0.1";
|
||||
public string Name { get; set; } = "Aoba";
|
||||
public string DestinationType { get; set; } = "ImageUploader, TextUploader, FileUploader";
|
||||
public string RequestMethod { get; set; } = "POST";
|
||||
public string RequestURL { get; set; } = "https://aoba.app/api/media/upload";
|
||||
public Dictionary<string, string> Headers { get; set; } = [];
|
||||
public string Body { get; set; } = "MultipartFormData";
|
||||
public Dictionary<string, string> Arguments { get; set; } = new() { { "name", "$filename$" } };
|
||||
public string FileFormName { get; set; } = "file";
|
||||
public string[] RegexList { get; set; } = ["([^/]+)/?$"];
|
||||
public string URL { get; set; } = "https://aoba.app{json:url}";
|
||||
public string? ThumbnailURL { get; set; }
|
||||
public string? DeletionURL { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user