mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-12-06 05:59:45 +08:00
!3641 doc(#I6753J): fix request gitee raw file failed issue
* fix: 修复网络请求失败仍然显示工具栏问题 * fix: 修复网路请求失败问题 * refactor: 更改 RepositoryUrl 变量名称
This commit is contained in:
parent
fb9539180e
commit
6e51f6519d
@ -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);
|
||||
|
@ -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>
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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>
|
||||
///
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user