Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
057ca43
commit 8e0b85c
Showing
12 changed files
with
160 additions
and
4 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
CnGalWebSite/CnGalWebSite.RobotClientX.Models/Configurations/ConfigurationModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace CnGalWebSite.RobotClientX.Models.Configurations | ||
{ | ||
public class ConfigurationModel | ||
{ | ||
public string ChatGPT_SystemMessageTemplate { get; set; } | ||
|
||
public string ChatGPT_UserMessageTemplate { get; set; } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
CnGalWebSite/CnGalWebSite.RobotClientX/.config/dotnet-tools.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"version": 1, | ||
"isRoot": true, | ||
"tools": { | ||
"dotnet-ef": { | ||
"version": "7.0.10", | ||
"commands": [ | ||
"dotnet-ef" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
CnGalWebSite/CnGalWebSite.RobotClientX/Components/Home/EditCard.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
@inject IConfigurationService _configurationService | ||
|
||
<MCard Class="mb-4"> | ||
<MCardTitle> | ||
编辑配置 | ||
</MCardTitle> | ||
<MCardText> | ||
<MRow> | ||
<MCol Cols="12"> | ||
<MTextarea Rows="3" @bind-Value="_configurationModel.ChatGPT_SystemMessageTemplate" Label="GPT 提示词" Outlined HideDetails="true"/> | ||
</MCol> | ||
<MCol Cols="12"> | ||
<MTextarea Rows="3" @bind-Value="_configurationModel.ChatGPT_UserMessageTemplate" Label="GPT 消息模板" Outlined HideDetails="true"/> | ||
</MCol> | ||
</MRow> | ||
|
||
</MCardText> | ||
<MCardActions Class="pb-6"> | ||
<MSpacer></MSpacer> | ||
<MButton Color="primary" | ||
OnClick="SaveEdit"> | ||
<MIcon Left>mdi-check</MIcon> | ||
保存 | ||
</MButton> | ||
</MCardActions> | ||
|
||
</MCard> | ||
@code { | ||
[Parameter] | ||
public EventCallback ConfigurationChanged { get; set; } | ||
|
||
ConfigurationModel _configurationModel = new ConfigurationModel(); | ||
|
||
protected override void OnInitialized() | ||
{ | ||
_configurationModel = _configurationService.GetConfiguration(); | ||
} | ||
|
||
public async Task SaveEdit() | ||
{ | ||
_configurationService.Save(); | ||
await ConfigurationChanged.InvokeAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
CnGalWebSite/CnGalWebSite.RobotClientX/Services/Configurations/ConfigurationService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using CnGalWebSite.RobotClientX.Models.Configurations; | ||
using System.Text.Encodings.Web; | ||
using System.Text.Json; | ||
using System.Text.Unicode; | ||
|
||
namespace CnGalWebSite.RobotClientX.Services.Configurations | ||
{ | ||
public class ConfigurationService:IConfigurationService | ||
{ | ||
private ConfigurationModel _configurationModel; | ||
private readonly IConfiguration _configuration; | ||
private readonly IWebHostEnvironment _webHostEnvironment; | ||
|
||
public ConfigurationService(IConfiguration configuration, IWebHostEnvironment webHostEnvironment) | ||
{ | ||
_configuration = configuration; | ||
_webHostEnvironment = webHostEnvironment; | ||
|
||
Load(); | ||
} | ||
|
||
public void Load() | ||
{ | ||
var path = Path.Combine(_webHostEnvironment.WebRootPath, "Data", "Setting.json"); | ||
string jsonString = File.ReadAllText(path); | ||
_configurationModel = JsonSerializer.Deserialize<ConfigurationModel>(jsonString)!; | ||
|
||
if(string.IsNullOrWhiteSpace( _configurationModel.ChatGPT_SystemMessageTemplate)) | ||
{ | ||
_configurationModel.ChatGPT_SystemMessageTemplate = _configuration["ChatGPT_SystemMessageTemplate"]; | ||
} | ||
if (string.IsNullOrWhiteSpace(_configurationModel.ChatGPT_UserMessageTemplate)) | ||
{ | ||
_configurationModel.ChatGPT_UserMessageTemplate = _configuration["ChatGPT_UserMessageTemplate"]; | ||
} | ||
|
||
Save(); | ||
} | ||
|
||
public void Save() | ||
{ | ||
var path = Path.Combine(_webHostEnvironment.WebRootPath, "Data", "Setting.json"); | ||
var options = new JsonSerializerOptions | ||
{ | ||
WriteIndented = true, | ||
Encoder = JavaScriptEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.All) | ||
}; | ||
string jsonString = JsonSerializer.Serialize(_configurationModel, options); | ||
File.WriteAllText(path, jsonString); | ||
} | ||
|
||
public ConfigurationModel GetConfiguration() | ||
{ | ||
return _configurationModel; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
CnGalWebSite/CnGalWebSite.RobotClientX/Services/Configurations/IConfigurationService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using CnGalWebSite.RobotClientX.Models.Configurations; | ||
|
||
namespace CnGalWebSite.RobotClientX.Services.Configurations | ||
{ | ||
public interface IConfigurationService | ||
{ | ||
ConfigurationModel GetConfiguration(); | ||
|
||
void Save(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"version": "1.0", | ||
"defaultProvider": "cdnjs", | ||
"libraries": [] | ||
} |