openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Data integrity: Internet Archive ID is 't' generating bad thumbnails in carousels

Open jdlrobson opened this issue 6 years ago • 1 comments

This relates to the slack conversation between @mekarpeles and Brittany. For those who missed it, apparently this fix is not applying to: https://openlibrary.org/subjects/in_library#ebooks=true&sort=edition_count when you click right arrow.

The carousel item is rendered on the server side so this is likely an issue in the template.

The template uses the following code If an Internet Archive ID is available that's used here.

$elif book.get('ia'):
    $ cover_url = '%s/b/ia/%s-M.jpg?default=%s'%(cover_host, book.get('ia')[0], fallback_cover)

For some reason some books have an inaccurate ia field. When that happens a bad URI is created like //covers.openlibrary.org/b/ia/t-M.jpg?default=https://openlibrary.org/images/icons/avatar_book.png

The template is dumb and will assume if it finds an image a cover exists. ie. It;s the default parameter in the covers api that is causing an issue.

The covers api takes a default parameter.

Two solutions to this

  1. Either we cannot depend on the IA field and we should not ever use it for the thumbnail
  2. API should be updated to 404 when an image is not available so alt text can be used.
<div class="book carousel__item">
  <div class="book-cover">
    <a href="/works/OL55532W">
      <img class="bookcover" loading="lazy"
        width="130" height="200"
        title="The three sisters by Anton Pavlovich Chekhov"
        data-lazy="//covers.openlibrary.org/b/ia/t-M.jpg?default=https://openlibrary.org/images/icons/avatar_book.png"/>
    </a>
  </div>
  <div class="book-cta"><a class="cta-btn cta-btn--available borrow-link" href="/borrow/ia/threesistersdram00chek?ref=ol" data-ol-link-track="subjects" title="Borrow The three sisters"
    data-key="subjects" data-ocaid="threesistersdram00chek">Borrow</a></div>
</div>

Evidence / Screenshot (if possible)

Screen Shot 2020-04-21 at 9 56 54 PM

Related

Very similar to #2836 possibly can be fixed at the same time.

Stakeholders

jdlrobson avatar Apr 22 '20 04:04 jdlrobson

Hi, I'd like to work on this one.

I checked and this still happens on master. In openlibrary/plugins/worksearch/subjects.py, work_wrapper saves ia as a single string, not a list. Then _resolve_carousel_card_cover_url in openlibrary/plugins/openlibrary/partials.py does book.get('ia')[0], which gives only the first letter. So when a subject carousel loads more books and a work has a scan but no cover id, the cover URL ends up like /b/ia/t-M.jpg.

My plan is to make that function handle both a string and a list, and add a test in test_partials.py. books/mobile_carousel.html has the same [0] code, so I'll check that too.

Can I be assigned to this? @mekarpeles

Animesh-Jantwal avatar Oct 29 '26 09:10 Animesh-Jantwal