@page "/fetchdata/{Service}/{CreatorId}" @using Microsoft.AspNetCore.Components.Rendering; @using Sve.Blazor.InfiniteScroll.Components @using VeloeKemonoPartyApp.Data @using VeloeKemonoPartyApp.Services; @inject WeatherForecastService ForecastService @inject KemonoHttpClient HttpClient @inject IJSRuntime JSRuntime

@ImageContextMenuName

@Message

@foreach (var post in posts) {

@post.Title

@{ int i = 0; foreach (var images in post.Attachments) { /* string toImage = System.IO.Path.Combine(FileSystem.CacheDirectory, System.IO.Path.GetFileName(new Uri(images.Path).LocalPath)); string toFolder = FileSystem.CacheDirectory; for (int tries = 0; tries < 5; tries++) { try { if (!System.IO.File.Exists(toImage)) { Task.Run(() => { using (var s = new HttpClient().GetStreamAsync(images.Link).GetAwaiter().GetResult()) { if (!Directory.Exists(toFolder)) Directory.CreateDirectory(toFolder); using (var fs = new FileStream(toImage, FileMode.CreateNew)) { s.CopyToAsync(fs).GetAwaiter(); } } }).GetAwaiter(); } toImage = Convert.ToBase64String(System.IO.File.ReadAllBytes(toImage)); //DependencyService.Get().GetImageAsync($"https://kemono.party/data{images.Path}", toFolder, toImage).GetAwaiter(); break; } catch (Exception ex) { if (tries == 4) toImage = "logo_vivelapub.png"; //await Task.Delay(500); } } */ if (System.IO.Path.GetExtension(images.Path) is (".png" or ".jpg" or ".jpeg" or ".gif")){ //if (System.IO.Path.GetExtension(toImage) is (".png" or ".jpg" or ".jpeg" or ".gif")){ string link = images.Link; string imageId = $"{images.Path}_{i}"; OpenOverlay(imageId,link,images.Name)) style="margin-bottom:10px; width:@(Application.Current.MainPage.Width - 50)px; height:contain;" /> } //else //{ // string link = "data:image/png;base64," + toImage; //string imageId = $"{images.Path}_{i}"; // OpenOverlay(imageId,link,images.Name)) style="margin-bottom:10px; width:@(Application.Current.MainPage.Width - 50)px; height:contain;" /> //} } } @if(post.Content.Contains("")) { post.Content.Replace("",""); }
@((MarkupString)post.Content)
@foreach (var attachment in post.Attachments) { string link = "https://kemono.party" + attachment.Path;

@attachment.Name

}

@post.Published

}

End

@code { [Parameter] public string CreatorId { get; set; } [Parameter] public string Service { get; set; } string OverlayVisibility { get; set; } string ImageContextMenuName { get; set; } string ImageContextMenuId { get; set; } string ImageContextMenuLink { get; set; } string Message { get; set; } private WeatherForecast[] forecasts; private List postsCache = new List(); private List posts = new List(); private int loadedPos = 0; private Panzoom _panzoom; protected override async Task OnInitializedAsync() { //await GetPosts(); OverlayVisibility = "none"; } private async Task GetPosts() { // Just to make it async int i = 0; do { try { if (postsCache.Count == posts.Count) { var postsNew = await HttpClient.GetPostsList(CreatorId, Service, loadedPos); postsCache.AddRange(postsNew); } posts.AddRange(postsCache.Skip(posts.Count).Take(1)); //loadedPos += postsNew.Count; loadedPos += 1; return; } catch (Exception ex) { await Task.Delay(1000); } i++; } while (i<5); Message = "LoadFailed"; } private async Task OpenLink(string link) { await Browser.Default.OpenAsync(link); } void CloseOverlay() { OverlayVisibility = "none"; } void OpenOverlay(string id, string link, string name) { //JSRuntime.InvokeVoidAsync("ResetZoom"); _panzoom.ResetAsync(); ImageContextMenuName = name; ImageContextMenuLink = link; ImageContextMenuId = id; OverlayVisibility = "block"; ShouldRender(); } }