From 632f1e3db46cebe14b011b4d397cd4f4f800564b Mon Sep 17 00:00:00 2001 From: Codel1417 <13484789+Codel1417@users.noreply.github.com> Date: Fri, 17 May 2024 21:37:14 -0400 Subject: [PATCH] Support mediaUrl if its provided --- lib/Frontend/Widgets/tail_blog.dart | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/Frontend/Widgets/tail_blog.dart b/lib/Frontend/Widgets/tail_blog.dart index 05e8f033..4d2c0d87 100644 --- a/lib/Frontend/Widgets/tail_blog.dart +++ b/lib/Frontend/Widgets/tail_blog.dart @@ -115,7 +115,7 @@ class _TailBlogState extends State { if (_wordpressPosts.isNotEmpty) { for (Post post in _wordpressPosts) { - results.add(FeedItem(title: post.title!.parsedText, publishDate: post.date!, url: post.link, feedType: FeedType.blog, imageId: post.featuredMedia)); + results.add(FeedItem(title: post.title!.parsedText, publishDate: post.date!, url: post.link, feedType: FeedType.blog, imageId: post.featuredMedia, imageUrl: post.featuredImageUrl)); } } if (results.isNotEmpty && context.mounted) { @@ -142,12 +142,17 @@ class _TailBlogState extends State { await lock.synchronized( () async { // Get image url from wordpress api - final RetrieveMediaRequest retrieveMediaRequest = RetrieveMediaRequest(id: item.imageId!); - WordpressResponse retrieveMediaResponse = await client.media.retrieve(retrieveMediaRequest); - if (retrieveMediaResponse.dataOrNull() != null) { - Media mediaInfo = retrieveMediaResponse.dataOrNull()!; - mediaUrl = mediaInfo.mediaDetails!.sizes!['full']!.sourceUrl!; + if (item.imageUrl != null && item.imageUrl!.isNotEmpty) { + mediaUrl = item.imageUrl; + } else { + final RetrieveMediaRequest retrieveMediaRequest = RetrieveMediaRequest(id: item.imageId!); + WordpressResponse retrieveMediaResponse = await client.media.retrieve(retrieveMediaRequest); + if (retrieveMediaResponse.dataOrNull() != null) { + Media mediaInfo = retrieveMediaResponse.dataOrNull()!; + mediaUrl = mediaInfo.mediaDetails!.sizes!['full']!.sourceUrl!; + } } + if (mediaUrl != null) { // download the image await initDio().download(mediaUrl!, filePath); @@ -173,13 +178,15 @@ class _TailBlogState extends State { class FeedItem implements Comparable { String title; - DateTime publishDate; String url; FeedType feedType; + + //Image ID is used as the wordpress image ID and the unique id to identify the image in cache int? imageId; + String? imageUrl; - FeedItem({required this.title, required this.publishDate, required this.url, required this.feedType, this.imageId}); + FeedItem({required this.title, required this.publishDate, required this.url, required this.feedType, this.imageId, this.imageUrl}); @override int compareTo(FeedItem other) {