From 971f79a1a1b237bc9802aa48cf63ea4d1d045f46 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Wed, 17 Apr 2024 22:10:54 +0200 Subject: [PATCH] Upgrade --- StlSpy/Service/LocalStorage.cs | 19 ++++++++++++++++++- StlSpy/StlSpy.csproj | 10 +++++----- StlSpy/Utils/Request.cs | 2 +- StlSpy/Views/LocalCollectionView.axaml.cs | 3 ++- StlSpy/Views/PreviewPostView.axaml.cs | 15 ++++++++++----- 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/StlSpy/Service/LocalStorage.cs b/StlSpy/Service/LocalStorage.cs index 99eb9c4..4095ac7 100644 --- a/StlSpy/Service/LocalStorage.cs +++ b/StlSpy/Service/LocalStorage.cs @@ -339,7 +339,24 @@ public async Task AddPost(CollectionId id, Post post, IProgress? progress if (!AreFilesCached(post.UniversalId)) { - await SavePostLocally(post, progress); + try + { + await SavePostLocally(post, progress); + } + catch (Exception e) + { + var path = GetPath(post.UniversalId); + try + { + Directory.Delete(path, true); + } + catch + { + } + + throw; + } + } if (!collection.UIDs.Contains(post.UniversalId)) diff --git a/StlSpy/StlSpy.csproj b/StlSpy/StlSpy.csproj index 69d4815..0fbf999 100644 --- a/StlSpy/StlSpy.csproj +++ b/StlSpy/StlSpy.csproj @@ -22,12 +22,12 @@ - - + + - - - + + + diff --git a/StlSpy/Utils/Request.cs b/StlSpy/Utils/Request.cs index 7fd6eaf..7b9386e 100644 --- a/StlSpy/Utils/Request.cs +++ b/StlSpy/Utils/Request.cs @@ -27,7 +27,7 @@ public static async Task GetAsync(Uri uri, Dictionary he { using (HttpClient client = new()) { - client.Timeout = TimeSpan.FromMinutes(5); + client.Timeout = TimeSpan.FromMinutes(1); foreach (var kv in headers) client.DefaultRequestHeaders.Add(kv.Key, kv.Value); diff --git a/StlSpy/Views/LocalCollectionView.axaml.cs b/StlSpy/Views/LocalCollectionView.axaml.cs index 7929dc1..e885ad8 100644 --- a/StlSpy/Views/LocalCollectionView.axaml.cs +++ b/StlSpy/Views/LocalCollectionView.axaml.cs @@ -75,7 +75,7 @@ private async void AddTopButtons() private async void Get() { - _view.SetPosts(GetPosts()); + await _view.SetPosts(GetPosts()); } private async Task> GetPosts() @@ -87,6 +87,7 @@ private async Task> GetPosts() await load.WaitUntilReady(); load.Complete(); } + return (await storage.GetPosts(_id))!.Posts.OrderByDescending(x => x.Added).Select(x => { var post = new PreviewPostView(x, ApiDescription.GetLocalApiDescription()); diff --git a/StlSpy/Views/PreviewPostView.axaml.cs b/StlSpy/Views/PreviewPostView.axaml.cs index fff59fd..272631f 100644 --- a/StlSpy/Views/PreviewPostView.axaml.cs +++ b/StlSpy/Views/PreviewPostView.axaml.cs @@ -37,12 +37,8 @@ public partial class PreviewPostView : UserControlExt public event Action? OnNeedListReload; - public async void DownloadImage() + public async void GetCoverImage() { - if (_downloadedImage) - return; - - _downloadedImage = true; try { byte[]? data = await Post.Thumbnail.Get(); @@ -58,6 +54,15 @@ public async void DownloadImage() } } + public void DownloadImage() + { + if (_downloadedImage) + return; + + _downloadedImage = true; + Dispatcher.UIThread.Post(GetCoverImage, DispatcherPriority.Background); + } + public PreviewPostView(PreviewPost previewPost, ApiDescription api) { Post = previewPost;