Create a new cover loader for EDS to proxy the image provided from the EDS API - #5542
Create a new cover loader for EDS to proxy the image provided from the EDS API#5542meganschanz wants to merge 7 commits into
Conversation
demiankatz
left a comment
There was a problem hiding this comment.
Thanks, @meganschanz -- see below for a few thoughts on this.
I'd suggest that we wait to hear more from @cwolfebsco about the policy side of things before investing more time, though -- if it's a no-go due to EBSCO rules, then there's no point in wasting time on polishing... but I thought a review might be helpful for future reference should we get the green light to proceed.
| $recordId = $ids['recordid'] ?? ''; | ||
| $url = $this->getCachedData($recordId); | ||
|
|
||
| if (str_starts_with($url, 'http://') || str_starts_with($url, 'https://')) { |
There was a problem hiding this comment.
Should you ensure that $url is a string before performing these string operations? What happens if the cache is empty?
There was a problem hiding this comment.
Good point. I changed how that check is done.
| $url = $this->getCachedData($recordId); | ||
|
|
||
| if (str_starts_with($url, 'http://') || str_starts_with($url, 'https://')) { | ||
| $this->debug('Returning Cover image URL: ' . $url); |
There was a problem hiding this comment.
Maybe helpful to specify the source, in case there are multiple cover handlers in play.
| $this->debug('Returning Cover image URL: ' . $url); | |
| $this->debug('Returning EDS cover image URL: ' . $url); |
There was a problem hiding this comment.
I applied the suggestion. The only reason I didn't in the first place was I worried the message was too repetitive since the class name is (always?) in the message too:
vufind.DEBUG: VuFind\Content\Covers\EDS: Returning EDS cover image URL: https://some-url
| class EDS extends DefaultRecord | ||
| { | ||
| use Feature\IlsAwareTrait; | ||
| use \VuFind\Http\CachingDownloaderAwareTrait; |
There was a problem hiding this comment.
You're not using the caching downloader, so why are you using this trait?
There was a problem hiding this comment.
I am not; good catch. That was leftover from when I was experimenting with caching the images. I removed it.
| \VuFind\Http\CachingDownloaderAwareInterface | ||
| { | ||
| use \VuFind\Log\LoggerAwareTrait; | ||
| use \VuFind\Http\CachingDownloaderAwareTrait; |
There was a problem hiding this comment.
This trait seems unnecessary here as well (but sorry if I'm overlooking something!).
There was a problem hiding this comment.
Yup, same as above. I removed it.
| // for certain ebook packages. | ||
| if ($closestMatch) { | ||
| return $closestMatch; | ||
| if ($thumbnail) { |
There was a problem hiding this comment.
Would there be value in adding an EDS.ini setting to control whether thumbnails are returned directly or through the cache? Some might prefer the old approach, and it doesn't look like adding flexibility would be too difficult.
There was a problem hiding this comment.
Good idea. I made a new setting under [Cover] called loadDirectly and set it to true by default to be consistent with existing functionality. The comment indicates that when it is false the coverimages setting in the config.ini also needs to be updated to include EDS. I'm open to other names for the setting or suggestions to improve the comment around it.
| if ($closestMatch) { | ||
| return $closestMatch; | ||
| if ($thumbnail) { | ||
| $this->putCachedData($this->getUniqueID(), $thumbnail); |
There was a problem hiding this comment.
As @cwolfebsco asked on Slack, can we set the lifetime here based on the headers of the API response? (I imagine that may be non-trivial and might require injecting the data to pass it down this far into the code -- but at least worth considering).
There was a problem hiding this comment.
I don't think we need to do this now considering we're not going to cache the images, and just the URL, right? The cache already has a lifetime based on the config.ini -> [Cache] -> ttl time.
| * creating a service. | ||
| * @throws ContainerException&\Throwable if any other error occurs | ||
| */ | ||
| public function __invoke( |
There was a problem hiding this comment.
I wonder if this factory should be simplified or made to extend one of the other existing driver factories -- but the best approach may depend on the answer to the EPF issue.
There was a problem hiding this comment.
It didn't seem like any of the existing driver factories injected the \VuFind\Cache\Manager already. But working with the factories is not my strong-suite, so there certainly may be a way to simplify it that I'm just not seeing. And yes we do need to keep in mind that both EDS and EPF will be using it.
|
@demiankatz & @meganschanz: Thanks for your patience on this. As you know, I wanted to make sure I had a clear answer from Product Management before responding. Cover images provided for catalog enrichment or eBooks as part of EDS API are licensed for use within EDS API results only. We're not able to grant permission to cache these images, I am afraid. Happy to discuss further if it would help to understand the constraints in more detail. |
Thanks for the clarification, @cwolfebsco! So it sounds like we definitely would have to turn off the property in the cover loader that caches images. It looks like the fundamental functionality of the cover loader doesn't depend on caching the actual image, though, just on caching the image url. Since the loading is accomplished by record ID, and the EDS record IDs will never be used to load images outside the context of EDS results, it sounds to me like as long as we don't locally cache the image files themselves, the other aspects of the solution may be within bounds -- unless running the images through a proxy server is an inherent violation, in which case this solution is simply unworkable. |
This is following up on the Slack conversation that started on August 18th with the idea to switch how EDS cover images are loaded. To instead use a cover loader instead of putting the image URL returned from the EDS API directly in the template for the client side to request.
The benefits of making a new cover loader for EDS:
This makes the images available at
Cover/Show?recordid={{eds-record-id}}&size={{size}}&source=EDS, for example:Cover/Show?recordid=cat09276a%2Cebc.ebs29904633e&size=medium&source=EDS.To test:
EDS.inito include validEBSCO_Accountinformationconfig.inito enableEDSwithincoverimagesEDS/Home) or view some record pages (/EdsRecord/nlebk,401631/)Note:
EdsRecord/cat09276a,ebc.ebs29904633e)