123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- @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
- <div id="image-menu" onclick="@(()=>CloseOverlay())"
- style="
- opacity: 1;
- background-color:#ccc;
- position:fixed;
- width:100%;
- height:100%;
- top:0px;
- left:0px;
- justify-content:center;
- pointer-events:none;
- display:@OverlayVisibility;
- z-index:900;">
- <div style="pointer-events:all;">
- <div style="position:fixed; top:0px; left:0px;opacity:1; background-color:red; align-items:center; height:@(Application.Current.MainPage.Height - 80)px; text-align: center;">
- <div id="panzoom_block" style="position: absolute;top: 50%;transform: translateY(-50%);height:@(Application.Current.MainPage.Height - 80)px;width:@(Application.Current.MainPage.Width)px;">
- <Panzoom @ref="_panzoom">
- <img id="panzoom" @ref="@context.ElementReference" alt="image" src="@ImageContextMenuLink" style="max-height:@(Application.Current.MainPage.Height - 80)px;max-width:@(Application.Current.MainPage.Width)px; display:block; margin-top:auto; margin-bottom:auto" />
- </Panzoom>
- </div>
-
-
- </div>
- <div style="position:fixed; bottom:10px; left:10px;">
- <h3>@ImageContextMenuName</h3>
- <button id="reload-image-button" style="z-index:1000;" @onclick=@(() => JSRuntime.InvokeVoidAsync("SwitchPic",ImageContextMenuId,ImageContextMenuLink))>Reload image</button>
- </div>
- </div>
-
-
- </div>
- <p>@Message</p>
- <InfiniteScroll ObserverTargetId="observerTarget" ObservableTargetReached="(e) => GetPosts()" >
- <div>
- @foreach (var post in posts)
- {
- <div>
- <h2>@post.Title</h2>
- @{
- 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<KemonoHttpClient>().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}";
- <img
- id="@imageId"
- src="@link"
- onerror="@(
- ()=>{
- Task.Delay(1000).GetAwaiter();
- JSRuntime.InvokeVoidAsync("SwitchPic",imageId,link);
- }
- )"
- @onclick=@(()=>Task.Run(()=>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}";
- // <img id="@imageId" src="@link" @onclick=@(()=>OpenOverlay(imageId,link,images.Name)) style="margin-bottom:10px; width:@(Application.Current.MainPage.Width - 50)px; height:contain;" />
- //}
- }
- }
-
- @if(post.Content.Contains("<a>"))
- {
- post.Content.Replace("<a>","<a style:\"word-break:break-all;\">");
- }
- <div style="word-break:break-word;">@((MarkupString)post.Content)</div>
- @foreach (var attachment in post.Attachments)
- {
- string link = "https://kemono.party" + attachment.Path;
- <p onclick="@(async () => await OpenLink(link))" style="color:dodgerblue; word-break:break-all;" >@attachment.Name</p>
- }
- <p >@post.Published</p>
- </div>
- }
-
-
- <p class="list-group-item" id="observerTarget">End</p>
- </div>
-
- </InfiniteScroll>
-
- @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<Post> postsCache = new List<Post>();
- private List<Post> posts = new List<Post>();
- 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";
- }
- async void OpenOverlay(string id, string link, string name)
- {
- JSRuntime.InvokeVoidAsync("SetOverlayImage", id);
- ImageContextMenuName = name;
- ImageContextMenuLink = link;
- ImageContextMenuId = id;
- OverlayVisibility = "block";
- await _panzoom.ResetAsync();
- await JSRuntime.InvokeVoidAsync("SetPanzoom");
- JSRuntime.InvokeVoidAsync("PanzoomCenter");
- ShouldRender();
- }
- }
|