!3641 doc(#I6753J): fix request gitee raw file failed issue

* fix: 修复网络请求失败仍然显示工具栏问题
* fix: 修复网路请求失败问题
* refactor: 更改 RepositoryUrl 变量名称
This commit is contained in:
Argo 2022-12-22 11:15:01 +00:00
parent fb9539180e
commit 6e51f6519d
5 changed files with 22 additions and 14 deletions

View File

@ -27,7 +27,7 @@ public class CodeController : ControllerBase
public async Task<string> Get([FromQuery] string fileName, [FromServices] HttpClient client, [FromServices] IOptionsMonitor<WebsiteOptions> options)
{
var ret = "";
client.BaseAddress = new Uri(options.CurrentValue.RepositoryUrl);
client.BaseAddress = new Uri(options.CurrentValue.SampleUrl);
try
{
ret = await client.GetStringAsync(fileName);

View File

@ -9,15 +9,15 @@
else
{
<pre style="max-height: 260px;"><code>@ChildContent</code></pre>
@if (ShowToolbar)
{
<div class="btn-group">
<Button TooltipPlacement="Placement.Top" TooltipText="@PlusTooltipTitle" TooltipTrigger="hover" Icon="fa-solid fa-plus" class="btn-plus"></Button>
<Button TooltipPlacement="Placement.Top" TooltipText="@MinusTooltipTitle" TooltipTrigger="hover" Icon="fa-solid fa-minus" class="btn-minus"></Button>
</div>
}
@if (CanCopy)
{
@if (ShowToolbar)
{
<div class="btn-group">
<Button TooltipPlacement="Placement.Top" TooltipText="@PlusTooltipTitle" TooltipTrigger="hover" Icon="fa-solid fa-plus" class="btn-plus"></Button>
<Button TooltipPlacement="Placement.Top" TooltipText="@MinusTooltipTitle" TooltipTrigger="hover" Icon="fa-solid fa-minus" class="btn-minus"></Button>
</div>
}
<Button TooltipPlacement="Placement.Top" TooltipText="@TooltipTitle" TooltipTrigger="hover" class="btn-copy">Copy</Button>
}
}

View File

@ -121,7 +121,6 @@ public partial class Pre
private async Task GetCodeAsync()
{
// 优先查找 Demo 值
if (!string.IsNullOrEmpty(CodeFile))
{
var code = await Example.GetCodeAsync(CodeFile, BlockTitle, Demo);

View File

@ -49,7 +49,7 @@ public class WebsiteOptions
/// <summary>
///
/// </summary>
public string RepositoryUrl { get; set; } = "https://gitee.com/LongbowEnterprise/BootstrapBlazor/raw/main/src/BootstrapBlazor.Shared/Samples/";
public string SampleUrl { get; set; } = "https://gitee.com/LongbowEnterprise/BootstrapBlazor/raw/main/src/BootstrapBlazor.Shared/Samples/";
/// <summary>
///

View File

@ -14,6 +14,10 @@ class CodeSnippetService
private string ServerUrl { get; set; }
private string SampleUrl { get; set; }
private string DemoUrl { get; set; }
private bool IsDevelopment { get; }
private string ContentRootPath { get; }
@ -40,11 +44,12 @@ class CodeSnippetService
CacheManager = cacheManager;
Client = client;
Client.Timeout = TimeSpan.FromSeconds(5);
Client.BaseAddress = new Uri(options.CurrentValue.RepositoryUrl);
IsDevelopment = options.CurrentValue.IsDevelopment;
ContentRootPath = options.CurrentValue.ContentRootPath;
ServerUrl = options.CurrentValue.ServerUrl;
SampleUrl = options.CurrentValue.SampleUrl;
DemoUrl = $"{SampleUrl}../Demos/";
}
/// <summary>
@ -142,6 +147,9 @@ class CodeSnippetService
{
var payload = "";
demo = demo.Replace('.', Path.DirectorySeparatorChar);
demo = $"{demo}.razor";
if (IsDevelopment)
{
payload = await ReadDemoTextAsync(demo);
@ -155,7 +163,8 @@ class CodeSnippetService
}
else
{
payload = await Client.GetStringAsync(demo);
Client.BaseAddress = new Uri(DemoUrl);
payload = await Client.GetStringAsync(demo.Replace('\\', '/'));
}
}
@ -182,6 +191,7 @@ class CodeSnippetService
}
else
{
Client.BaseAddress = new Uri(SampleUrl);
payload = await Client.GetStringAsync(codeFile);
}
}
@ -222,8 +232,7 @@ class CodeSnippetService
var payload = "";
var paths = new string[] { "..", "BootstrapBlazor.Shared", "Demos" };
var folder = Path.Combine(ContentRootPath, string.Join(Path.DirectorySeparatorChar, paths));
var file = Path.Combine(folder, codeFile.Replace('.', Path.DirectorySeparatorChar));
file = $"{file}.razor";
var file = Path.Combine(folder, codeFile);
if (File.Exists(file))
{
payload = await File.ReadAllTextAsync(file);