diff options
| -rw-r--r-- | Pages/ViewMedia.razor | 12 | ||||
| -rw-r--r-- | Program.cs | 1 | ||||
| -rw-r--r-- | Services/SourceService.cs | 20 |
3 files changed, 32 insertions, 1 deletions
diff --git a/Pages/ViewMedia.razor b/Pages/ViewMedia.razor index f1270f2..ce9d608 100644 --- a/Pages/ViewMedia.razor +++ b/Pages/ViewMedia.razor @@ -4,6 +4,7 @@ @inject IDbContextFactory<HBContext> dbFactory @inject ITagService tagService @inject IMediaService mediaService +@inject ISourceService sourceService @attribute [Authorize] <PageTitle>@title</PageTitle> @@ -55,6 +56,9 @@ <th>Original Checksum</th> </tr> @foreach(var file in media.UploadedFiles.OrderByDescending(uf => uf.UploadTime)) { + string? sourceUrl = null; + if(file.Filename is not null) + sourceUrl = sourceService.GetUrlFromFilename(file.Filename); <tr> <td title=@file.CreateTime?.ToString()> @(file.CreateTime?.ToString("d") ?? "N/A") @@ -63,7 +67,13 @@ @(file.LastWriteTime?.ToString("d") ?? "N/A") </td> <td title=@file.UploadTime>@(file.UploadTime.ToString("d"))</td> - <td title=@file.Filename>@file.Filename</td> + <td title=@file.Filename> + @if(sourceUrl is not null) { + <a class="nondecorated" target="_blank" href=@sourceUrl>@file.Filename</a> + } else { + @file.Filename + } + </td> <td title=@file.Length>@file.Length.ToBytesSI()</td> <td title=@(file.Checksum + (file.ChecksumVerified ? " (verified)" : "")) @@ -28,6 +28,7 @@ public class Program { builder.Services.AddSingleton<IGlobalUserService, GlobalUserService>(); builder.Services.AddScoped<IUserService, UserService>(); builder.Services.AddHostedService<OcrService>(); + builder.Services.AddSingleton<ISourceService, SourceService>(); var app = builder.Build(); diff --git a/Services/SourceService.cs b/Services/SourceService.cs new file mode 100644 index 0000000..d145346 --- /dev/null +++ b/Services/SourceService.cs @@ -0,0 +1,20 @@ +using System.Text.RegularExpressions; + +namespace HyperBooru.Services; + +public interface ISourceService { + public string? GetUrlFromFilename(string filename); +} + +public class SourceService : ISourceService { + private Regex PixivRegex = + new(@"^([0-9]+)_p[0-9]+(_master1200)?\.[^.]+$", RegexOptions.Compiled); + + public string? GetUrlFromFilename(string filename) { + var pixivMatch = PixivRegex.Match(filename); + if(pixivMatch.Success) + return $"https://pixiv.net/en/artworks/{pixivMatch.Groups[1].Value}"; + + return null; + } +} |
