Only save used images to image folder when inserting images (not all of them)

I created a fresh article creator project and started,
so my need is to upload images in jpeg format only.

So I have use logic to do all steps by api call.

  1. Linked the post uploader id to article creator.
  2. Linked domain info to post uploader and updated folder path of article creator.
  3. Run article creator project.
  4. Checked If imageinsert.imagetype is local, clear the post uploader folder path to stop post uploader to post data to wordpress.
  5. Created function which get credentials and upload images to wordpress and get urls from response.
  6. There are only 10 images in the articles I created for testing, but images are 205.
  7. Store the image url and filename in an object.
  8. Get that object to loop each text file to replace src=“/images/${imageInfo.filename} with src=”${imageInfo.wordpressImageUrl}".
  9. After replacing updated folder path back and run the post uploader project.

This is the issue it is uploading too many files to wordpress that are not required.

Can you please fix this, if we rerun the project then also old images will be removed from images folder too.

I found too many junks are present, and when rerun the project older data is still present and newer data is added not replaced on place of older data.

This is critical for storage point of view and also not a good practice.
can you update the code and also let me know to update the seo content machine.

Article creator will keep track of each image it inserts.

Once task is complete ONLY used images are copied to output image folder.

You can see exactly how many in task log…

Article creator will not clear image folder if you re-run it. Its up to you to delete output folder or not.

If you want all images that SCM downloaded, you can access it by clicking on task cache button.

image