fix: custom api key
This commit is contained in:
parent
4101b1bb93
commit
1d190eb8b6
@ -1,7 +1,9 @@
|
||||
{
|
||||
"Meili": {
|
||||
"Port": 7700,
|
||||
"UiEnabled" : true
|
||||
"UiEnabled" : true,
|
||||
"CustomApiKey": false,
|
||||
"ApiKey": "YourOptionalApiKey"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
|
@ -6,6 +6,8 @@ public class MeiliSearchConfiguration
|
||||
{
|
||||
private readonly string _meiliPort = "Meili:Port";
|
||||
private readonly string _meiliUiEnabled = "Meili:UiEnabled";
|
||||
private readonly string _meiliEnableCustomApiKey = "Meili:CustomApiKey";
|
||||
private readonly string _meiliApiKey = "Meili:ApiKey";
|
||||
private readonly IConfiguration _configuration;
|
||||
public MeiliSearchConfiguration(IConfiguration configuration)
|
||||
{
|
||||
@ -13,4 +15,6 @@ public class MeiliSearchConfiguration
|
||||
}
|
||||
public int MeiliPort => _configuration.GetValue<int>(_meiliPort);
|
||||
public bool UiEnabled => _configuration.GetValue<bool>(_meiliUiEnabled);
|
||||
public string ApiKey => _configuration.GetValue<string>(_meiliApiKey) ?? "";
|
||||
public bool EnableCustomApiKey => _configuration.GetValue<bool>(_meiliEnableCustomApiKey);
|
||||
}
|
@ -33,7 +33,12 @@ public class MeiliSearchService:IMeiliSearchService
|
||||
_meiliSearchConfiguration = meiliSearchConfiguration;
|
||||
var binaryName = GetBinaryName();
|
||||
MakeExecutable(Path.Combine(AppContext.BaseDirectory, binaryName));
|
||||
var apiKey = ApiKeyGenerator.GenerateApiKey();
|
||||
string apiKey = "";
|
||||
if (_meiliSearchConfiguration.EnableCustomApiKey)
|
||||
apiKey = _meiliSearchConfiguration.ApiKey;
|
||||
else
|
||||
apiKey = ApiKeyGenerator.GenerateApiKey();
|
||||
|
||||
_sdkHttpClient = httpClient;
|
||||
_sdkHttpClient.BaseAddress = new Uri("http://localhost:"+meiliSearchConfiguration.MeiliPort);
|
||||
Sdk = new MeilisearchClient(httpClient, apiKey);
|
||||
@ -190,7 +195,11 @@ public class MeiliSearchService:IMeiliSearchService
|
||||
public void RefreshApiKey()
|
||||
{
|
||||
_logger.LogInformation("Refreshing API key.");
|
||||
var apiKey = ApiKeyGenerator.GenerateApiKey();
|
||||
string apiKey = "";
|
||||
if (_meiliSearchConfiguration.EnableCustomApiKey)
|
||||
apiKey = _meiliSearchConfiguration.ApiKey;
|
||||
else
|
||||
apiKey = ApiKeyGenerator.GenerateApiKey();
|
||||
Sdk = new MeilisearchClient(_sdkHttpClient, apiKey);
|
||||
_logger.LogInformation("New API key generated.");
|
||||
Restart();
|
||||
|
Loading…
x
Reference in New Issue
Block a user