62 lines
2.1 KiB
C#
62 lines
2.1 KiB
C#
using Tesses.WebServer;
|
|
using Scriban;
|
|
using System.Web;
|
|
using YoutubeExplode.Search;
|
|
using System.Collections.Concurrent;
|
|
using System.Security.Cryptography;
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
namespace Tesses.YouTubeDownloader2025Companion;
|
|
|
|
public static partial class Pages {
|
|
|
|
|
|
private static ReloadingScript log_page = new ReloadingScript("wwwroot/pages/log.sbnhtml");
|
|
|
|
public static async Task<string> LogAsync(ServerContext ctx)
|
|
{
|
|
var cfg = Program.Config ?? new AuthConfig();
|
|
int page=1;
|
|
if(!ctx.QueryParams.TryGetFirstInt32("page",out page))
|
|
page = 1;
|
|
|
|
List<object> entries=new List<object>();
|
|
|
|
using(var db = new Database())
|
|
{
|
|
foreach(var vid in await db.GetLogEntriesAsync((page-1) * 20))
|
|
{
|
|
var time = vid.DateTime.DateTime;
|
|
|
|
if(vid.HasStrings)
|
|
{
|
|
entries.Add(new{
|
|
Time = $"{time.ToShortDateString()} {time.ToShortTimeString()}",
|
|
vid.Type,
|
|
Videotitle = HttpUtility.HtmlEncode(vid.VideoTitle),
|
|
Videourl = HttpUtility.HtmlAttributeEncode($"{cfg.TYTDUrl.TrimEnd('/')}/watch?v={HttpUtility.UrlEncode(vid.VideoId)}"),
|
|
Channeltitle = HttpUtility.HtmlEncode(vid.ChannelTitle),
|
|
Channelurl = HttpUtility.HtmlAttributeEncode($"{cfg.TYTDUrl.TrimEnd('/')}/channel?id={HttpUtility.UrlEncode(vid.ChannelId)}"),
|
|
|
|
});
|
|
}
|
|
else {
|
|
entries.Add(new {
|
|
Time = $"{time.ToShortDateString()} {time.ToShortTimeString()}",
|
|
vid.Type
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
return Components.Shell("Logs",log_page.Render(new{
|
|
Entries=entries,
|
|
Prev = HttpUtility.HtmlAttributeEncode($"/log?page={(page == 1 ? 1 : page - 1)}"),
|
|
Current = page,
|
|
Next = HttpUtility.HtmlAttributeEncode($"/log?page={page + 1}")
|
|
}),Program.DefaultLinks());
|
|
}
|
|
|
|
} |