Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
@inject ICacheManager Cache
@inject IConnectionService ConnectionService
@inherits WebSiteModuleComponentBase
@attribute [JSModuleAutoLoader("Components/FooterCounter.razor.js")]

<div class="d-none d-sm-block ms-2">Run @Runtime</div>
<div id="@Id" class="d-none d-sm-block ms-2" style="width: 110px;">Run @Runtime</div>
@if (_options.Enable)
{
<div class="footer-online ms-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ namespace BootstrapBlazor.Server.Components.Components;
/// <summary>
/// FooterCounter 组件
/// </summary>
public partial class FooterCounter : IDisposable
public partial class FooterCounter
{
private string? Runtime { get; set; }

private CancellationTokenSource _disposeTokenSource = new();
private readonly CancellationTokenSource _disposeTokenSource = new();

private ConnectionHubOptions _options = default!;

Expand All @@ -30,7 +30,9 @@ protected override void OnInitialized()
base.OnInitialized();

_options = BootstrapBlazorOptions.Value.ConnectionHubOptions;
UpdateRuntime();

var ts = DateTimeOffset.Now - Cache.GetStartTime();
Runtime = ts.ToString("dd\\.hh\\:mm\\:ss");
}

/// <summary>
Expand All @@ -41,36 +43,44 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);

try
if (firstRender)
{
await Task.Delay(1000, _disposeTokenSource.Token);
UpdateRuntime();
StateHasChanged();
try
{
while (_disposeTokenSource is { IsCancellationRequested: false })
{
await Task.Delay(30000, _disposeTokenSource.Token);
var ts = DateTimeOffset.Now - Cache.GetStartTime();
await InvokeVoidAsync("updateFooterCounter", Id, ts.TotalSeconds);
}
}
catch { }
}
catch { }
}

private void UpdateRuntime()
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <returns></returns>
protected override Task InvokeInitAsync()
{
var ts = DateTimeOffset.Now - Cache.GetStartTime();
Runtime = ts.ToString("dd\\.hh\\:mm\\:ss");
return InvokeVoidAsync("init", Id, ts.TotalSeconds);
}

private void Dispose(bool disposing)
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="disposing"></param>
/// <returns></returns>
protected override async ValueTask DisposeAsync(bool disposing)
{
await base.DisposeAsync(true);

if (disposing)
{
_disposeTokenSource.Cancel();
_disposeTokenSource.Dispose();
}
}

/// <summary>
/// <inheritdoc/>
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import Data from "../../_content/BootstrapBlazor/modules/data.js"

export function init(id, totalSeconds) {
const el = document.getElementById(id);
if (el === null) {
return;
}

const tick = () => {
const counter = Data.get(id);

counter.totalSeconds = (counter.totalSeconds || 0) + 1;
const now = Math.round(counter.totalSeconds, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Math.round does not accept a second argument.

Remove the second argument from Math.round, as it is ignored. If you need to round to a specific decimal place, consider using a different method.


const days = Math.floor(now / (24 * 3600));
const hours = Math.floor((now % (24 * 3600)) / 3600);
const minutes = Math.floor((now % 3600) / 60);
const seconds = now % 60;

const pad = num => num.toString().padStart(2, '0');
el.innerHTML = `Run ${pad(days)}.${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security (javascript.browser.security.insecure-document-method): User controlled data in methods like innerHTML, outerHTML or document.write is an anti-pattern that can lead to XSS vulnerabilities

Source: opengrep

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security (javascript.browser.security.insecure-innerhtml): User controlled data in a el.innerHTML is an anti-pattern that can lead to XSS vulnerabilities

Source: opengrep

}

const handler = setInterval(tick, 1000);
Data.set(id, {
el,
handler,
totalSeconds
});
}

export function updateFooterCounter(id, totalSeconds) {
const counter = Data.get(id);
if (counter) {
counter.totalSeconds = totalSeconds;
console.log(`FooterCounter updated: ${id}, totalSeconds: ${totalSeconds}`);
}
}

export function dispose(id) {
const counter = Data.get(id);
if (counter) {
clearInterval(counter.handler);
Data.remove(id);
}
}
4 changes: 2 additions & 2 deletions src/BootstrapBlazor.Server/Components/Components/Video.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

<p><b>@Localizer["H1"]</b></p>

@if (VideoUrl.Any())
@if (VideoUrl.Count > 0)
{
foreach (var url in VideoUrl)
{
<div class="mb-3">
<a class="fa-solid fa-video" href="@url" target="_blank"><span class="ms-2">@Localizer["L1"]</span></a>
<a href="@url" target="_blank"><i class="fa-solid fa-video"></i><span class="ms-2">@Localizer["L1"]</span></a>
</div>
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
position: absolute;
left: var(--bb-btn-space);
top: var(--bb-btn-space);
border-radius: inherit;
}

.bb-logo:before {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,16 @@
<div class="col-md-6">
<Card IsShadow="true" HeaderText="分类进度">
<BodyTemplate>
<Scroll Height="320px" style="overflow:scroll;">
<div style="margin-right:10px;">
@{
foreach (var item in Data.TestKKSGroupList)
{
<h4 class="small fw-bold">
@item.KKS @item.NAM<span class="float-end">
@(
item.Percent
)%
</span>
</h4>
<BootstrapBlazor.Components.Progress Value="@item.Percent" IsAnimated="true" Color="@GetColor(item.Percent)" IsShowValue="true" Round="1"></BootstrapBlazor.Components.Progress>
}
}
</div>
<Scroll Height="320px" style="margin: -1rem; padding: 1rem;">
@foreach (var item in Data.TestKKSGroupList)
{
<div class="progress-item">
<div class="small fw-bold mb-2">
@item.KKS @item.NAM<span class="float-end">@item.Percent%</span>
</div>
<BootstrapBlazor.Components.Progress Value="@item.Percent" IsAnimated="true" Color="@GetColor(item.Percent)" IsShowValue="true" Round="1"></BootstrapBlazor.Components.Progress>
</div>
}
</Scroll>
</BodyTemplate>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
.db-progress ::deep .progress {
flex: 1;
}

.progress-item:not(:last-child) {
margin-block-end: 1rem;
}
Loading