Skip to content

Commit

Permalink
Do not override existing alt text or caption
Browse files Browse the repository at this point in the history
Fixes #694
  • Loading branch information
swissspidy committed Sep 27, 2024
1 parent e419aa9 commit 365bd0e
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions packages/upload-media/src/store/private-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2054,6 +2054,12 @@ export function generateImageCaptions( id: QueueItemId ) {
return async ( { select, dispatch }: ThunkArgs ) => {
const item = select.getItem( id ) as QueueItem;

// Item already has both caption and alt text, do nothing.
if ( item.additionalData?.caption && item.additionalData.alt_text ) {
dispatch.finishOperation( id, {} );
return;
}

try {
let url = item.attachment?.url;

Expand All @@ -2067,11 +2073,14 @@ export function generateImageCaptions( id: QueueItemId ) {
} );
}

const caption = await aiWorker.generateCaption( url );
const alt = await aiWorker.generateCaption(
url,
'<DETAILED_CAPTION>'
);
// Do not override existing caption or alt text.
const caption =
item.additionalData?.caption ||
( await aiWorker.generateCaption( url ) );

const alt =
item.additionalData?.alt_text ||
( await aiWorker.generateCaption( url, '<DETAILED_CAPTION>' ) );

dispatch.finishOperation( id, {
// For updating in the editor straight away.
Expand Down

0 comments on commit 365bd0e

Please sign in to comment.