Skip to content

Commit

Permalink
Support mediaUrl if its provided
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed May 18, 2024
1 parent c649b7f commit 632f1e3
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/Frontend/Widgets/tail_blog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class _TailBlogState extends State<TailBlog> {

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) {
Expand All @@ -142,12 +142,17 @@ class _TailBlogState extends State<TailBlog> {
await lock.synchronized(
() async {
// Get image url from wordpress api
final RetrieveMediaRequest retrieveMediaRequest = RetrieveMediaRequest(id: item.imageId!);
WordpressResponse<Media> 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<Media> 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);
Expand All @@ -173,13 +178,15 @@ class _TailBlogState extends State<TailBlog> {

class FeedItem implements Comparable<FeedItem> {
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) {
Expand Down

0 comments on commit 632f1e3

Please sign in to comment.