mirror of
https://github.com/miawinter98/just-short-it.git
synced 2024-12-03 12:19:53 +00:00
Added Customization for generated ID length using JSI_CUSTOMIZATION__GENERATEDIDLENGTH
This commit is contained in:
parent
cf4c671d7e
commit
1191e0694d
|
@ -5,9 +5,12 @@
|
|||
@using System.Text.RegularExpressions
|
||||
@using System.Web
|
||||
@using Humanizer
|
||||
@using JustShortIt.Model
|
||||
@using Microsoft.AspNetCore.WebUtilities
|
||||
@using Microsoft.Extensions.Options
|
||||
@attribute [Authorize]
|
||||
|
||||
@inject IOptions<Customization> CustomizationOptions
|
||||
@inject IDistributedCache Db
|
||||
@inject IConfiguration Configuration
|
||||
@inject NavigationManager Navigation
|
||||
|
@ -152,11 +155,14 @@
|
|||
MessageType = MessageComponent.AlertType.Success;
|
||||
}
|
||||
|
||||
private static string GenerateNewId() {
|
||||
private string GenerateNewId() {
|
||||
string base64Guid = Regex.Replace(
|
||||
Convert.ToBase64String(Guid.NewGuid().ToByteArray()),
|
||||
"[/+=]", "");
|
||||
return base64Guid[..6];
|
||||
|
||||
int length = Math.Min(Math.Max(CustomizationOptions.Value.GeneratedIdLength, 2), 16);
|
||||
|
||||
return base64Guid[..length];
|
||||
}
|
||||
|
||||
#region Models
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<AuthorizeView>
|
||||
<Authorized>
|
||||
<span class="mx-3">@(context.User.Identity?.Name ?? "err_username_unknown")</span>
|
||||
<a class="btn btn-link text-secondary-content" href="/Logout">Logout</a>
|
||||
<a data-enhance="false" class="btn btn-link text-secondary-content" href="/Logout">Logout</a>
|
||||
</Authorized>
|
||||
<NotAuthorized>
|
||||
<a class="hover:link text-secondary-content" href="/Login">Login</a>
|
||||
<a data-enhance="false" class="hover:link text-secondary-content" href="/Login">Login</a>
|
||||
</NotAuthorized>
|
||||
</AuthorizeView>
|
||||
|
|
5
Model/Customization.cs
Normal file
5
Model/Customization.cs
Normal file
|
@ -0,0 +1,5 @@
|
|||
namespace JustShortIt.Model;
|
||||
|
||||
public class Customization {
|
||||
public int GeneratedIdLength { get; set; } = 6;
|
||||
}
|
|
@ -15,6 +15,7 @@
|
|||
var redisConnection = builder.Configuration.GetSection("Redis").Get<RedisConnection>();
|
||||
var user = builder.Configuration.GetSection("Account").Get<User>();
|
||||
string? baseUrl = builder.Configuration.GetValue<string>("BaseUrl");
|
||||
builder.Services.Configure<Customization>(builder.Configuration.GetSection(nameof(Customization)));
|
||||
|
||||
#if DEBUG
|
||||
baseUrl = "http://localhost/";
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
"commandName": "Docker",
|
||||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_HTTP_PORTS": "8080"
|
||||
"ASPNETCORE_HTTP_PORTS": "8080",
|
||||
"JSI_CUSTOMIZATION__GENERATEDIDLENGTH": "12"
|
||||
},
|
||||
"publishAllPorts": true
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue