From bc2a0d946ce71720748a831e340fb9a9a060a85c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Ca=C5=82ka?= Date: Sat, 20 Apr 2024 01:18:11 +0200 Subject: [PATCH] fix: handle case when image doesn't have sizes --- alt-text-generator-gpt-vision.php | 2 +- readme.txt | 2 +- src/components/BulkGenerateModal.tsx | 6 +++++- src/hooks/useAttachments.ts | 15 +++++++-------- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/alt-text-generator-gpt-vision.php b/alt-text-generator-gpt-vision.php index 9ecc25b..4c2b33c 100644 --- a/alt-text-generator-gpt-vision.php +++ b/alt-text-generator-gpt-vision.php @@ -4,7 +4,7 @@ * Plugin Name: AI Alt Text Generator for GPT Vision * Plugin URI: https://github.com/android-com-pl/wp-ai-alt-generator * Description: Automatically generate alternative text for images using OpenAI's GPT Vision API. - * Version: 2.1.1 + * Version: 2.1.3 * Requires at least: 6.3 * Requires PHP: 8.1 * Author: android.com.pl diff --git a/readme.txt b/readme.txt index ab4ffe4..0770b6b 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: alt text, accessibility, SEO, GPT-4, GPT-V, OpenAI Requires at least: 6.3 Tested up to: 6.5 Requires PHP: 8.1 -Stable tag: 2.1.1 +Stable tag: 2.1.3 License: GPLv3 or later License URI: https://www.gnu.org/licenses/gpl-3.0.html Plugin URI: https://github.com/android-com-pl/wp-ai-alt-generator diff --git a/src/components/BulkGenerateModal.tsx b/src/components/BulkGenerateModal.tsx index c52e925..95ea147 100644 --- a/src/components/BulkGenerateModal.tsx +++ b/src/components/BulkGenerateModal.tsx @@ -52,7 +52,11 @@ export default function BulkGenerateModal({ const thumbnail = //@ts-ignore - missing WP types attachment.media_details.sizes?.thumbnail ?? - attachment.media_details.sizes?.[0]; + attachment.media_details.sizes?.[0] ?? { + width: attachment.media_details.width, + height: attachment.media_details.height, + source_url: attachment.source_url, + }; if (thumbnail) details.thumbnail = { diff --git a/src/hooks/useAttachments.ts b/src/hooks/useAttachments.ts index 12db5dc..5312282 100644 --- a/src/hooks/useAttachments.ts +++ b/src/hooks/useAttachments.ts @@ -1,14 +1,13 @@ import { type Attachment, useEntityRecords } from "@wordpress/core-data"; export default function useAttachments(ids: number[]) { - const { records, hasResolved } = useEntityRecords>( - "postType", - "attachment", - { - include: ids, - per_page: -1, - }, - ); + const { records, hasResolved, isResolving } = useEntityRecords< + Attachment<"view"> + >("postType", "attachment", { + include: ids, + per_page: -1, + context: "view", + }); return { attachments: records ?? [], hasResolved }; }